Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#119-authorsList-JPA-error-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkJh38 authored Aug 9, 2024
2 parents 6289b9a + 100181f commit 8aa4056
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public enum ErrorStatus implements BaseErrorCode {
MEMBER_LOGIN_FAIL(HttpStatus.BAD_REQUEST, "MEMBER_1006", "아이디나 비밀번호가 올바르지 않습니다."),
MEMBER_WRONG_EMAIL(HttpStatus.BAD_REQUEST, "MEMBER_1007", "이메일 형식이 올바르지 않습니다."),
MEMBER_WRONG_PASSWORD(HttpStatus.BAD_REQUEST, "MEMBER_1008", "비밀번호 형식이 올바르지 않습니다."),
MEMBER_EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT, "MEMBER_1009", "이미 가입된 이메일입니다."),
MEMBER_NICKNAME_ALREADY_EXISTS(HttpStatus.CONFLICT, "MEMBER_1010", "이미 존재하는 닉네임입니다."),

MEMBER_SELF_FOLLOW(HttpStatus.BAD_REQUEST, "MEMBER_1100", "셀프 팔로우 기능은 제공하지 않습니다"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests(
authorize -> authorize
// Member 관련 접근
.requestMatchers("/members/sign-up").permitAll()
.requestMatchers("/members/sign-up", "/members/sign-up/check-email", "/members/sign-up/check-nickname").permitAll()
.requestMatchers("/members/login", "members/posts").permitAll()
// Post 관련 접근
.requestMatchers("/posts","/posts/{postId}", "/posts/visibility/{postId}", "/posts/coauthors/{postId}", "/posts/categories/{postId}").permitAll() //.hasRole("USER")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public static MemberResponseDTO.BookmarkDTO toBookmarkDTO(Bookmark bookmark) {
.memberId(bookmark.getMember().getMemberId())
.bookmarkId(bookmark.getId())
.postId(bookmark.getPost().getPostId())
// Post의 첫 번째 사진을 가져온다
// 나중에 postFile이 존재하지 않을 경우 나오는 기본 사진 처리를 해줘야 한다
.photoUrl(bookmark.getPost().getPostFileList().get(0).getFileUrl())
.thumbnailImageUrl((bookmark.getPost().getThumbnailImage() != null)
? bookmark.getPost().getThumbnailImage().getFileUrl()
: "")
.postTitle(bookmark.getPost().getPostTitle())
.nickname(bookmark.getPost().getMember().getNickname())
.postBody(bookmark.getPost().getPostBody())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,28 @@

public class PostConverter {

// public static Post toPost(PostRequestDTO.CreatePostRequestDTO request) {
// return Post.builder()
// .postTitle(request.getPostTitle())
// .postBody(request.getPostBody())
// .postStatus(request.getPostStatus())
// .postAccess(request.getPostAccess())
// .build();
// }
public static Post toPost(PostRequestDTO.CreatePostRequestDTO request, TeamRepository teamRepository, ProjectRepository projectRepository) {
Team team = null;
Project project = null;
// teamId가 제공된 경우에만 Team 객체를 조회
if (request.getTeamId() != null) {
team = teamRepository.findById(request.getTeamId())
.orElseThrow(() -> new IllegalArgumentException("Team not found with id: " + request.getTeamId()));
}
// projectId가 제공된 경우에만 Project 객체를 조회
if (request.getProjectId() != null) {
project = projectRepository.findById(request.getProjectId())
.orElseThrow(() -> new IllegalArgumentException("Project not found with id: " + request.getProjectId()));
public static Post toPost(PostRequestDTO.CreatePostRequestDTO request, TeamRepository teamRepository, ProjectRepository projectRepository) {
Team team = null;
Project project = null;
// teamId가 제공된 경우에만 Team 객체를 조회
if (request.getTeamId() != null) {
team = teamRepository.findById(request.getTeamId())
.orElseThrow(() -> new IllegalArgumentException("Team not found with id: " + request.getTeamId()));
}
// projectId가 제공된 경우에만 Project 객체를 조회
if (request.getProjectId() != null) {
project = projectRepository.findById(request.getProjectId())
.orElseThrow(() -> new IllegalArgumentException("Project not found with id: " + request.getProjectId()));
}
return Post.builder()
.postTitle(request.getPostTitle())
.postBody(request.getPostBody())
.team(team)
.project(project)
.postStatus(request.getPostStatus())
.postAccess(request.getPostAccess())
.build();
}
return Post.builder()
.postTitle(request.getPostTitle())
.postBody(request.getPostBody())
.team(team)
.project(project)
.postStatus(request.getPostStatus())
.postAccess(request.getPostAccess())
.build();
}


public static PostResponseDTO.CreatePostResultDTO toCreateResultDTO(Post post) {
Expand All @@ -64,6 +56,9 @@ public static PostResponseDTO.CreatePostResultDTO toCreateResultDTO(Post post) {
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}
Expand All @@ -86,6 +81,9 @@ public static PostResponseDTO.UpdatePostResultDTO toUpdatePostResultDTO(Post pos
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}
Expand All @@ -109,6 +107,9 @@ public static PostResponseDTO.PostPreviewDTO toPostPreviewDTO(Post post) {
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -150,6 +151,9 @@ public static PostResponseDTO.MemberPostPreviewDTO toMemberPostPreviewDTO(Post p
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -191,6 +195,9 @@ public static PostResponseDTO.TeamPostPreviewDTO toTeamPostPreviewDTO(Post post)
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -233,6 +240,9 @@ public static PostResponseDTO.MemberPostInProjectPreviewDTO toMemberPostInProjec
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -274,6 +284,9 @@ public static PostResponseDTO.TeamPostInProjectPreviewDTO toTeamPostInProjectPre
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -315,6 +328,9 @@ public static PostResponseDTO.MemberPostInTeamPreviewDTO toMemberPostInTeamPrevi
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -358,6 +374,9 @@ public static PostResponseDTO.PostAdjacentDTO.PostAdjacentPreviewDTO toPostAdjac
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
Expand Down Expand Up @@ -392,6 +411,9 @@ public static PostResponseDTO.UpdatePostResultDTO toSetPostCategoriesResultDTO(P
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class Post extends BaseEntity {
@Column(name = "post_body", nullable = false, columnDefinition = "varchar(500)")
private String postBody;

@OneToOne
@JoinColumn(name = "thumbnail_image_id")
private PostFile thumbnailImage;

@Builder.Default
@Enumerated(EnumType.STRING)
@Column(name = "post_access", nullable = false, columnDefinition = "varchar(500)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
// 이미 가입된 메일인지 확인
Boolean existsByEmail(String email);

Boolean existsByNickname(String nickname);

Optional<Member> findByEmail(String email);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public interface MemberCommandService {

public ApiResponse<String> signUp(MemberRequestDTO.MemberSignUpRequestDTO signUpRequest);

ApiResponse<String> checkEmailDuplication(String email);

ApiResponse<String> checkNicknameDuplication(String nickname);

public ApiResponse<MemberResponseDTO.MemberTokenResponseDTO> login(MemberRequestDTO.MemberLoginRequestDTO loginRequest);

// 회원별 관심 카테고리탭 리스트 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class MemberCommandServiceImpl implements MemberCommandService {
public ApiResponse<String> signUp(MemberRequestDTO.MemberSignUpRequestDTO signUpRequest) {
signUpRequest.isCorrect();

if (memberRepository.existsByEmail(signUpRequest.getEmail())) {
if (memberRepository.existsByEmail(signUpRequest.getEmail())
|| memberRepository.existsByNickname(signUpRequest.getNickname())) {
throw new MemberHandler(ErrorStatus.MEMBER_ALREADY_EXISTS);
}

Expand All @@ -65,13 +66,36 @@ public ApiResponse<String> signUp(MemberRequestDTO.MemberSignUpRequestDTO signUp
.gender(Member.Gender.Female)
.github(signUpRequest.getGithub())
.linkedin(signUpRequest.getLinkedin())
.discord(signUpRequest.getDiscord())
.image(null)
.build();
memberRepository.save(member);

return ApiResponse.of(SuccessStatus.MEMBER_OK, "정상적으로 가입되었습니다.");
}

@Override
public ApiResponse<String> checkEmailDuplication(String email) {
if (memberRepository.existsByEmail(email)) {
throw new MemberHandler(ErrorStatus.MEMBER_EMAIL_ALREADY_EXISTS);
}

if (!email.matches("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$")) {
throw new MemberHandler(ErrorStatus.MEMBER_WRONG_EMAIL);
}

return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, "사용가능한 이메일입니다!");
}

@Override
public ApiResponse<String> checkNicknameDuplication(String nickname) {
if (memberRepository.existsByNickname(nickname)) {
throw new MemberHandler(ErrorStatus.MEMBER_NICKNAME_ALREADY_EXISTS);
}
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, "사용가능한 닉네임입니다!");
}


@Override
public ApiResponse<MemberResponseDTO.MemberTokenResponseDTO> login(MemberRequestDTO.MemberLoginRequestDTO loginRequest) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public Post createPost(PostRequestDTO.CreatePostRequestDTO request) {
}
}

// 대표 사진 설정
String thumbnailImageName = request.getThumbnailImageName();
for (PostFile postFile : tempPost.getPostFileList()) {
if (postFile.getFileName().equals(thumbnailImageName)) {
tempPost.setThumbnailImage(postFile);
}
}
if (tempPost.getPostFileList().size() != 0 && tempPost.getThumbnailImage() == null) {
tempPost.setThumbnailImage(tempPost.getPostFileList().get(0));
}

Post savedPost = postRepository.save(tempPost);
return savedPost;
}
Expand Down Expand Up @@ -101,6 +112,17 @@ public Post updatePost(Long postId, PostRequestDTO.UpdatePostDTO request) {
}
}

// 대표 사진 설정
String thumbnailImageName = request.getThumbnailImageName();
for (PostFile postFile : updatePost.getPostFileList()) {
if (postFile.getFileName() == thumbnailImageName) {
updatePost.setThumbnailImage(postFile);
}
}
if (updatePost.getPostFileList().size() != 0 && updatePost.getThumbnailImage() == null) {
updatePost.setThumbnailImage(updatePost.getPostFileList().get(0));
}

return postRepository.save(updatePost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public ApiResponse<String> signUp(@Valid @RequestBody MemberRequestDTO.MemberSig
return memberCommandService.signUp(request);
}

@GetMapping("/sign-up/check-email")
@Operation(summary = "이메일 중복 확인")
public ApiResponse<String> checkEmailDuplication(@RequestParam String email) {
return memberCommandService.checkEmailDuplication(email);
}

@GetMapping("/sign-up/check-nickname")
@Operation(summary = "닉네임 중복 확인")
public ApiResponse<String> checkNicknameDuplication(@RequestParam String nickname) {
return memberCommandService.checkNicknameDuplication(nickname);
}

@PostMapping("/login")
@Operation(
summary = "로그인"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class MemberSignUpRequestDTO {
private Member.Gender gender;
private String github;
private String linkedin;
private String discord;

@JsonIgnore
public Boolean isCorrect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static class BookmarkDTO {
Long memberId;
Long bookmarkId;
Long postId;
String photoUrl;
String thumbnailImageUrl;
String postTitle;
String nickname;
String postBody;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class CreatePostRequestDTO {
private Boolean postStatus;
//private Set<String> postCategory;
private PostAccess postAccess;
private String thumbnailImageName;
private List<MultipartFile> postFiles;
}

Expand All @@ -36,6 +37,7 @@ public static class UpdatePostDTO {
private Boolean postStatus;
//private Set<String> postCategory;
private PostAccess postAccess;
private String thumbnailImageName;
private List<MultipartFile> addedPostFiles;
}

Expand Down
Loading

0 comments on commit 8aa4056

Please sign in to comment.