Skip to content

Commit

Permalink
Merge pull request #49 from KTB16Team/feature/44-mypage
Browse files Browse the repository at this point in the history
refactor: username, membername -> nickname으로 통일
  • Loading branch information
mng990 authored Nov 4, 2024
2 parents 7b8de09 + 443920d commit b0839c2
Show file tree
Hide file tree
Showing 28 changed files with 143 additions and 49 deletions.
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.sun.mail:javax.mail:1.6.2'
implementation 'io.netty:netty-all:4.1.75.Final'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CorsProperties.class,
AiServerProperties.class,
S3Properties.class
//SMTPProperties.class
})
public class PropertiesConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MemberMapper {
public Member signUpMemberEntity(SignUpRequest signUpRequest) {
return Member
.builder()
.memberName(signUpRequest.memberName())
.nickname(signUpRequest.nickname())
.password(passwordEncoder.encode(signUpRequest.password()))
.email(signUpRequest.email())
.memberRole(MemberRole.USER)
Expand All @@ -31,7 +31,7 @@ public Member signUpMemberEntity(SignUpRequest signUpRequest) {

public FindMyInfoResponse toFindMyInfoResponse(Member member) {
return new FindMyInfoResponse(
member.getMemberName(),
member.getNickname(),
member.getEmail(),
member.getProfileImage().getUrl()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static FindPostAndCommentsByIdResponse toFindPostAndCommentsByIdResponse(
return new FindPostAndCommentsByIdResponse(
post.getMember() == member,
post.getTitle(),
post.getMember().getMemberName(),
post.getMember().getNickname(),
post.getSummaryAi(),
post.getPostLikesCount(),
post.getPostViewsCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public class S3Properties {
private String secretKey;
private String region;
private String bucketName;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aimo.backend.common.properties;

// import org.springframework.boot.context.properties.ConfigurationProperties;
//
// import lombok.Getter;
// import lombok.Setter;
//
// @Getter
// @Setter
// @ConfigurationProperties(prefix = "mail.smtp")
// public class SMTPProperties {
// private String host;
// private int port;
// private String protocol;
// private String auth;
// private String starttlsEnable;
// private String debug;
// private String from;
// private String fromName;
// private String subject;
// private String content;
// }
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class CustomUserDetailsService implements UserDetailsService {
private final MemberService memberService;

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Member member = memberService.findByEmail(username)
public UserDetails loadUserByUsername(String nickname) throws UsernameNotFoundException {
Member member = memberService.findByEmail(nickname)
.orElseThrow(() -> new UsernameNotFoundException("해당하는 회원을 찾을 수 없습니다."));

String pw = member.getPassword();
String role = member.getRole().getValue();

return User.builder()
.username(username)
.username(nickname)
.password(pw)
.roles(role)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public record CommentResponse(
Long commentId,
String username,
String nickname,
String content,
Long likes,
List<ChildCommentResponse>childComments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ChildComment extends BaseEntity {
private Long id;

@Column(nullable = false)
private String memberName;
private String nickname;

@Column(nullable = false, length = 500)
private String content;
Expand All @@ -60,14 +60,14 @@ public class ChildComment extends BaseEntity {

@Builder
private ChildComment(
String memberName,
String nickname,
String content,
ParentComment parentComment,
Boolean isDeleted,
Member member,
Post post
) {
this.memberName = memberName;
this.nickname = nickname;
this.content = content;
this.parentComment = parentComment;
this.isDeleted = isDeleted;
Expand All @@ -81,13 +81,13 @@ public Integer getLikesCount() {

public void deleteChildCommentSoftly() {
this.member = null;
this.memberName = CommentConstants.DELETED_MEMBER.getValue();
this.nickname = CommentConstants.DELETED_MEMBER.getValue();
this.isDeleted = true;
}

public void deleteChildCommentSoftlyWithContent() {
this.member = null;
this.memberName = CommentConstants.DELETED_MEMBER.getValue();
this.nickname = CommentConstants.DELETED_MEMBER.getValue();
this.isDeleted = true;
content = CommentConstants.DELETED_COMMENT.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ParentComment extends BaseEntity {
private Long id;

@Column(nullable = false)
private String memberName;
private String nickname;

@Column(nullable = false, length = 500)
private String content;
Expand Down Expand Up @@ -58,13 +58,13 @@ public Integer getLikesCount() {

@Builder
private ParentComment(
String memberName,
String nickname,
String content,
Boolean isDeleted,
Member member,
Post post
) {
this.memberName = memberName;
this.nickname = nickname;
this.content = content;
this.isDeleted = isDeleted;
this.member = member;
Expand All @@ -73,13 +73,13 @@ private ParentComment(

public void deleteChildCommentSoftly() {
this.member = null;
this.memberName = CommentConstants.DELETED_COMMENT.getValue();
this.nickname = CommentConstants.DELETED_COMMENT.getValue();
this.isDeleted = true;
}

public void deleteChildCommentSoftlyWithContent() {
this.member = null;
this.memberName = CommentConstants.DELETED_MEMBER.getValue();
this.nickname = CommentConstants.DELETED_MEMBER.getValue();
this.isDeleted = true;
content = CommentConstants.DELETED_COMMENT.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ChildCommentMapper {
public ChildComment from(SaveChildCommentRequest request,
Member member, ParentComment parentComment, Post post) {
return ChildComment.builder()
.memberName(member.getMemberName())
.nickname(member.getNickname())
.content(request.content())
.parentComment(parentComment)
.isDeleted(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ParentCommentMapper {

public ParentComment from(SaveParentCommentRequest request, Member member, Post post) {
return ParentComment.builder()
.memberName(member.getMemberName())
.nickname(member.getNickname())
.content(request.content())
.isDeleted(false)
.member(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public interface ParentCommentLikeRepository extends JpaRepository<ParentCommentLike, Long> {

void deleteByParentComment_Id(Long id, Long parentCommentId);

void deleteByMember_IdAndParentComment_Id(Long likeId, Long parentCommentId);
Boolean existsByParentComment_IdAndMember_Id(Long parentCommentId, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void likeParentComment(Member member, Long parentCommentId, LikeType like
.member(member)
.build());
} else {
parentCommentLikeRepository.deleteByParentComment_Id(member.getId(), parentCommentId);
parentCommentLikeRepository.deleteByMember_IdAndParentComment_Id(member.getId(), parentCommentId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import aimo.backend.domains.member.dto.DeleteRequest;
import aimo.backend.domains.member.dto.FindMyInfoResponse;
import aimo.backend.domains.member.dto.LogOutRequest;
import aimo.backend.domains.member.dto.SendTemproraryPasswordRequest;
import aimo.backend.domains.member.dto.SignUpRequest;
import aimo.backend.common.dto.DataResponse;
import aimo.backend.domains.auth.security.jwtFilter.JwtTokenProvider;
Expand Down Expand Up @@ -101,13 +102,24 @@ public ResponseEntity<DataResponse<FindMyInfoResponse>> findMyInfo() {
.body(DataResponse.from(memberService.findMyInfo()));
}

// 비밀번호 수정(현재 비밀번호 확인)
@PutMapping("/password")
public ResponseEntity<DataResponse<Void>> updatePassword(@Valid @RequestBody UpdatePasswordRequest updatePasswordRequest) {
memberService.updatePassword(updatePasswordRequest);

return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created());
}

// 비밀번호 재발급(임시 비밀번호를 이메일로 전송)
@PostMapping("/password/temp")
public ResponseEntity<DataResponse<Void>> sendTemporaryPassword(
@Valid @RequestBody SendTemproraryPasswordRequest sendTemproraryPasswordRequest) {
memberService.sendTemporaryPassword(sendTemproraryPasswordRequest);

return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created());
}


@GetMapping("/nickname/{nickname}/exists")
public ResponseEntity<DataResponse<Void>> checkNicknameExists(@PathVariable("nickname") String nickname) {
memberService.checkNicknameExists(nickname);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aimo.backend.domains.member.dto;

public record CreateProfileImageUrlRequest(
String memberName,
String nickname,
String extension
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package aimo.backend.domains.member.dto;

import jakarta.validation.constraints.Email;

public record SendTemproraryPasswordRequest(
@Email(message = "이메일 형식이 아닙니다.")
String email) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import jakarta.validation.constraints.Past;

public record SignUpRequest(
@NotBlank(message = "userName이 빈 문자열입니다.")
String memberName,
@NotBlank(message = "nickname이 빈 문자열입니다.")
String nickname,
@Email(message = "email 형식이 아닙니다.")
String email,
@NotBlank(message = "password가 빈 문자열입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Member extends BaseEntity {
private Long id;

@Column(nullable = false, unique = true)
private String memberName;
private String nickname;

@Column(nullable = false, unique = true)
private String email;
Expand Down Expand Up @@ -86,21 +86,21 @@ public void updatePassword(String password) {
this.password = password;
}

public void updateMemberName(String memberName) {
this.memberName = memberName;
public void updateNickname(String nickname) {
this.nickname = nickname;
}

@Builder
private Member(
String memberName,
String nickname,
String email,
String password,
MemberRole memberRole,
Gender gender,
Provider provider,
LocalDate birthDate) {

this.memberName = memberName;
this.nickname = nickname;
this.email = email;
this.password = password;
this.role = memberRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

void deleteMemberByEmail(String email);

boolean existsByMemberName(String memberName);
boolean existsByNickname(String nickname);

boolean existsByEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import aimo.backend.domains.member.dto.DeleteRequest;
import aimo.backend.domains.member.dto.FindMyInfoResponse;
import aimo.backend.domains.member.dto.LogOutRequest;
import aimo.backend.domains.member.dto.SendTemproraryPasswordRequest;
import aimo.backend.domains.member.dto.SignUpRequest;
import aimo.backend.domains.member.dto.UpdateNicknameRequest;
import aimo.backend.domains.member.dto.UpdatePasswordRequest;
Expand All @@ -27,6 +28,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;
import java.util.UUID;

@Slf4j
@Service
Expand Down Expand Up @@ -54,7 +56,7 @@ public void signUp(SignUpRequest signUpRequest) {
validateDuplicateEmail(signUpRequest.email());

// 중복 닉네임 검사
validateDuplicateUsername(signUpRequest.memberName());
validateDuplicateNickname(signUpRequest.nickname());

Member member = memberMapper.signUpMemberEntity(signUpRequest);
memberRepository.save(member);
Expand Down Expand Up @@ -127,8 +129,8 @@ public void updatePassword(UpdatePasswordRequest updatePasswordRequest) {
@Transactional(rollbackFor = ApiException.class)
public void updateNickname(UpdateNicknameRequest updateNicknameRequest) {
Member member = memberLoader.getMember();
validateDuplicateUsername(updateNicknameRequest.newNickname());
member.updateMemberName(updateNicknameRequest.newNickname());
validateDuplicateNickname(updateNicknameRequest.newNickname());
member.updateNickname(updateNicknameRequest.newNickname());
}

public FindMyInfoResponse findMyInfo() {
Expand All @@ -140,7 +142,7 @@ public Member findById(Long memberId) {
}

public void checkNicknameExists(String nickname) {
if (memberRepository.existsByMemberName(nickname)) {
if (memberRepository.existsByNickname(nickname)) {
throw ApiException.from(ErrorCode.MEMBER_NAME_DUPLICATE);
}
}
Expand All @@ -157,9 +159,18 @@ private void validateDuplicateEmail(String email) {
}

// 닉네임 중복 검사
private void validateDuplicateUsername(String username) {
if (memberRepository.existsByMemberName(username)) {
private void validateDuplicateNickname(String nickname) {
if (memberRepository.existsByNickname(nickname)) {
throw ApiException.from(ErrorCode.MEMBER_NAME_DUPLICATE);
}
}

@Transactional(rollbackFor = ApiException.class)
public void sendTemporaryPassword(SendTemproraryPasswordRequest sendTemproraryPasswordRequest) {
String temporaryPassword = UUID.randomUUID().toString().substring(0, 8);

Member member = memberRepository.findByEmail(sendTemproraryPasswordRequest.email())
.orElseThrow(() -> ApiException.from(ErrorCode.MEMBER_NOT_FOUND));
member.updatePassword(passwordEncoder.encode(temporaryPassword));
}
}
Loading

0 comments on commit b0839c2

Please sign in to comment.