Skip to content

Commit

Permalink
Merge pull request #37 from KOA-TF/feat/member
Browse files Browse the repository at this point in the history
Member, MemberDetail 칼럼 수정, 이메일 인증 API 수정
  • Loading branch information
isprogrammingfun authored Nov 11, 2023
2 parents 16e0c03 + 2b8a30e commit 9e27727
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.koa.commonmodule.common.ApplicationResponse;
import com.koa.coremodule.member.application.dto.request.MemberDetailCreateRequest;
import com.koa.coremodule.member.application.dto.request.MemberPasswordChangeRequest;
import com.koa.coremodule.member.application.dto.response.CheckEmailResponse;
import com.koa.coremodule.member.application.dto.response.CheckPasswordResponse;
import com.koa.coremodule.member.application.dto.response.MemberDetailInfoResponse;
import com.koa.coremodule.member.application.dto.response.MemberInfoResponse;
Expand Down Expand Up @@ -40,9 +41,10 @@ public class MemberController {
private final EmailVerificationUseCase emailVerificationUseCase;
private final MemberPasswordChangeUseCase memberPasswordChangeUseCase;

@GetMapping
public MemberInfoResponse getMemberInfo(){
return memberGetUseCase.getMemberInfo();
@GetMapping("/info")
public ApplicationResponse<MemberInfoResponse> getMemberInfo(){
MemberInfoResponse response = memberGetUseCase.getMemberInfo();
return ApplicationResponse.ok(response);
}

@PostMapping
Expand All @@ -56,13 +58,18 @@ public ApplicationResponse<CheckRegisterResponse> checkMemberRegistered(@Request
CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(email, password);
return ApplicationResponse.ok(response);
}

@GetMapping("/info")
@GetMapping("/info/detail")
public ApplicationResponse<MemberDetailInfoResponse> getMemberDetailInfo() {
MemberDetailInfoResponse response = memberGetUseCase.getMemberDetailInfo();
return ApplicationResponse.ok(response);
}

@PostMapping("/email")
public ApplicationResponse<CheckEmailResponse> checkEmail(@RequestParam String email) {
CheckEmailResponse response = memberCheckUseCase.checkEmail(email);
return ApplicationResponse.ok(response);
}

@PostMapping("/verify")
public ApplicationResponse<Void> postVerifyEmail(@RequestParam String email) {
emailVerificationUseCase.sendVerificationEmail(email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private static Map<String, Set<HttpMethod>> createIgnoredPathMap() {
map.put("/v1/member/register", Set.of(HttpMethod.POST));
map.put("/h2-console/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/v1/auth/login/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/v1/member/email", Set.of(HttpMethod.POST));
map.put("/v1/member/verify", Set.of(HttpMethod.POST));
map.put("/v1/member/verify/code", Set.of(HttpMethod.POST));
map.put("/api-docs/**", Set.of(HttpMethod.GET, HttpMethod.POST));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
@Service
@RequiredArgsConstructor
public class EmailSendService {
private static final int LENGTH = 6;
private static final String MESSAGE= "인증번호는 %s 입니다.";
private static final String TITLE = "KOA 이메일 인증";
private static final int CODE_LENGTH = 6;
private static final String MESSAGE_TEMPLATE = "인증번호는 %s 입니다.";
private static final String EMAIL_TITLE = "KOA 이메일 인증";

private final JavaMailSender emailSender;
private final RedisUtils redisUtils;

Expand All @@ -26,27 +27,22 @@ public class EmailSendService {

public void sendEmail(String email) {
String code = createCode();
SimpleMailMessage emailForm = createEmailForm(email, TITLE, String.format(MESSAGE, code));
String messageText = String.format(MESSAGE_TEMPLATE, code);
SimpleMailMessage emailForm = createEmailForm(email, EMAIL_TITLE, messageText);
emailSender.send(emailForm);
redisUtils.setDataExpire(email, code, authCodeExpirationMillis);
}

private String createCode() {
try {
Random random = SecureRandom.getInstanceStrong();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < LENGTH; i++) {
builder.append(random.nextInt(10));
}
return builder.toString();
} catch (NoSuchAlgorithmException e) {
throw new CreateCodeException(Error.CREATE_CODE_FAIL);
Random random = new Random();
StringBuilder codeBuilder = new StringBuilder(CODE_LENGTH);
for (int i = 0; i < CODE_LENGTH; i++) {
codeBuilder.append(random.nextInt(10));
}
return codeBuilder.toString();
}

private SimpleMailMessage createEmailForm(String toEmail,
String title,
String text) {
private SimpleMailMessage createEmailForm(String toEmail, String title, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(toEmail);
message.setSubject(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class MemberDetailCreateRequest {
private String major;
private String part;
private List<InterestCreateRequest> interests;
private String phoneNumber;
private String description;
private List<LinkCreateRequest> links;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.koa.coremodule.member.application.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class CheckEmailResponse {
private final Boolean isEmailExist;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class MemberDetailInfoResponse {
private String major;
private String part;
private List<InterestInfoResponse> interests;
private String phoneNumber;
private String description;
private String profileImage;
private List<LinkInfoResponse> links;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public class MemberInfoResponse {
private String name;
private String period;
private String email;
private String phoneNumber;
private boolean isMemberDetailExist;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class MemberMapper {
public static MemberInfoResponse mapToMemberInfoResponse(Member member, boolean isMemberDetailExist){
return MemberInfoResponse.builder()
.name(member.getName())
.period(member.getPeriod())
.email(member.getEmail())
.phoneNumber(member.getPhoneNumber())
.isMemberDetailExist(isMemberDetailExist)
.build();
}
Expand All @@ -33,7 +35,6 @@ public static MemberDetail mapToMemberInfo(Member member, MemberDetailCreateRequ
return MemberDetail.builder()
.major(memberInfoCreateRequest.getMajor())
.part(Part.valueOf(memberInfoCreateRequest.getPart()))
.phoneNumber(memberInfoCreateRequest.getPhoneNumber())
.description(memberInfoCreateRequest.getDescription())
.profileImage(imageUrl)
.member(member)
Expand Down Expand Up @@ -61,7 +62,6 @@ public static MemberDetailInfoResponse mapToMemberDetailInfoResponse(MemberDetai
.major(memberDetail.getMajor())
.part(memberDetail.getPart().toString())
.interests(interests)
.phoneNumber(memberDetail.getPhoneNumber())
.description(memberDetail.getDescription())
.profileImage(memberDetail.getProfileImage())
.links(links)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class EmailVerificationUseCase {
private final MemberQueryService memberQueryService;

public void sendVerificationEmail(String email) {
memberQueryService.checkEmailExist(email);
emailSendService.sendEmail(email);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.koa.coremodule.member.application.service;

import com.koa.commonmodule.annotation.ApplicationService;
import com.koa.commonmodule.exception.Error;
import com.koa.coremodule.member.application.dto.response.CheckEmailResponse;
import com.koa.coremodule.member.application.dto.response.CheckPasswordResponse;
import com.koa.coremodule.member.application.dto.response.CheckRegisterResponse;
import com.koa.coremodule.member.application.exception.WrongPasswordException;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.service.MemberQueryService;
import com.koa.coremodule.member.domain.utils.MemberUtils;
Expand All @@ -28,4 +27,9 @@ public CheckPasswordResponse checkPassword(String password) {
Member member = memberUtils.getAccessMember();
return new CheckPasswordResponse(member.getPassword().equals(password));
}

public CheckEmailResponse checkEmail(String email) {
final boolean isEmailExist = memberQueryService.checkEmailExist(email);
return new CheckEmailResponse(isEmailExist);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class Member extends BaseEntity {
private Long id;

private String name;
private String period;
private String email;
private String phoneNumber;
private String password;
private String fcmToken;

Expand All @@ -34,9 +36,11 @@ public class Member extends BaseEntity {
private Boolean isDeleted = Boolean.FALSE;

@Builder
public Member(String name, String email, String password, Authority authority) {
public Member(String name, String period, String email, String phoneNumber, String password, Authority authority) {
this.name = name;
this.period = period;
this.email = email;
this.phoneNumber = phoneNumber;
this.password = password;
this.authority = authority;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class MemberDetail extends BaseEntity {

private String major;
private Part part;
private String phoneNumber;
private String description;
private String profileImage;
private Boolean isDeleted = Boolean.FALSE;
Expand All @@ -42,10 +41,9 @@ public class MemberDetail extends BaseEntity {
private Member member;

@Builder
public MemberDetail(String major, Part part, String phoneNumber, String description, String profileImage, Member member) {
public MemberDetail(String major, Part part, String description, String profileImage, Member member) {
this.major = major;
this.part = part;
this.phoneNumber = phoneNumber;
this.description = description;
this.profileImage = profileImage;
this.member = member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public Member findByEmail(String email) {
.orElseThrow(() -> new UserNotFoundException(Error.MEMBER_NOT_FOUND));
}

public void checkEmailExist(String email) {
if(memberRepository.existsByEmail(email) == false) {
throw new UserNotFoundException(Error.MEMBER_NOT_FOUND);
}
public boolean checkEmailExist(String email) {
return memberRepository.existsByEmail(email);
}
}

0 comments on commit 9e27727

Please sign in to comment.