diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java index b594764..f62157e 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java @@ -1,18 +1,22 @@ package org.gachon.checkmate.domain.member.dto.response; import lombok.Builder; +import org.gachon.checkmate.domain.member.entity.GenderType; @Builder public record MemberSignInResponseDto( Long memberId, + String gender, String accessToken, String refreshToken ) { public static MemberSignInResponseDto of(Long memberId, + GenderType genderType, String accessToken, String refreshToken) { return MemberSignInResponseDto.builder() .memberId(memberId) + .gender(genderType.getDesc()) .accessToken(accessToken) .refreshToken(refreshToken) .build(); diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index f8e70e3..7193a98 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -66,7 +66,7 @@ public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequest String accessToken = issueNewAccessToken(user.getId()); String refreshToken = issueNewRefreshToken(user.getId()); saveTokenInfo(user.getId(), refreshToken); - return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken); + return MemberSignInResponseDto.of(user.getId(), user.getGender(), accessToken, refreshToken); } public void withdraw(Long userId) { diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index 148816f..2e0a794 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -24,11 +24,12 @@ public class PostController { @GetMapping public ResponseEntity> getAllPosts(@UserId final Long userId, - @RequestParam(required = false) final String key, @RequestParam final String type, + @RequestParam(required = false) final String key, @RequestParam(required = false) final String gender, + @RequestParam(required = false) final String dormitory, final Pageable pageable) { - final PostSearchResponseDto responseDto = postService.getAllPosts(userId, key, type, gender, pageable); + final PostSearchResponseDto responseDto = postService.getAllPosts(userId, key, type, gender, dormitory, pageable); return SuccessResponse.ok(responseDto); } @@ -54,7 +55,7 @@ public ResponseEntity> getMyPosts(@UserId final Long userId, return SuccessResponse.ok(responseDto); } - @PatchMapping("{id}") + @PatchMapping("/{id}") public ResponseEntity> updateMyPost(@UserId final Long userId, @PathVariable("id") final Long postId, @RequestBody @Valid final PostUpdateRequestDto requestDto) { diff --git a/src/main/java/org/gachon/checkmate/domain/post/converter/DormitoryTypeConverter.java b/src/main/java/org/gachon/checkmate/domain/post/converter/DormitoryTypeConverter.java new file mode 100644 index 0000000..83586c7 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/converter/DormitoryTypeConverter.java @@ -0,0 +1,13 @@ +package org.gachon.checkmate.domain.post.converter; + +import jakarta.persistence.Converter; +import org.gachon.checkmate.domain.post.entity.DormitoryType; +import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter; + +@Converter +public class DormitoryTypeConverter extends AbstractEnumCodeAttributeConverter { + public DormitoryTypeConverter() { + super(DormitoryType.class); + } +} + diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostCreateRequestDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostCreateRequestDto.java index 8f0d5e3..26d63de 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostCreateRequestDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostCreateRequestDto.java @@ -5,6 +5,7 @@ import lombok.NonNull; import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto; +import org.gachon.checkmate.domain.post.entity.DormitoryType; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.RoomType; import org.gachon.checkmate.domain.post.entity.SimilarityKeyType; @@ -16,7 +17,8 @@ public record PostCreateRequestDto( @NotBlank(message = "내용을 입력해주세요") String content, @NotNull(message = "중요 키워드를 입력해주세요") ImportantKeyType importantKey, @NotNull(message = "유사도를 입력해주세요") SimilarityKeyType similarityKey, - @NotNull(message = "기숙사 유형을 입력해주세요") RoomType roomType, + @NotNull(message = "호실을 입력해주세요") RoomType roomType, + @NotNull(message = "기숙사 유형을 입력해주세요") DormitoryType dormitoryType, @NotNull(message = "모집 마감기간을 입력해주세요") LocalDate endDate, @NotNull(message = "체크리스트를 입력해주세요") CheckListRequestDto checkList ) { diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java index dbfb18d..700dbc4 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/request/PostUpdateRequestDto.java @@ -3,6 +3,7 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto; +import org.gachon.checkmate.domain.post.entity.DormitoryType; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.RoomType; import org.gachon.checkmate.domain.post.entity.SimilarityKeyType; @@ -14,7 +15,8 @@ public record PostUpdateRequestDto( @NotBlank(message = "내용을 입력해주세요") String content, @NotNull(message = "중요 키워드를 입력해주세요") ImportantKeyType importantKey, @NotNull(message = "유사도를 입력해주세요") SimilarityKeyType similarityKey, - @NotNull(message = "기숙사 유형을 입력해주세요") RoomType roomType, + @NotNull(message = "호실을 입력해주세요") RoomType roomType, + @NotNull(message = "기숙사 유형을 입력해주세요") DormitoryType dormitoryType, @NotNull(message = "모집 마감기간을 입력해주세요") LocalDate endDate, @NotNull(message = "체크리스트를 입력해주세요") CheckListRequestDto checkList ) { diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java index d6148f7..4df81d9 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java @@ -6,6 +6,7 @@ @Builder public record PostDetailResponseDto( + Long memberId, String name, String major, String profile, @@ -16,6 +17,7 @@ public record PostDetailResponseDto( ) { public static PostDetailResponseDto of(PostDetailDto postDetailDto, CheckListResponseDto checkList, boolean isScrap) { return PostDetailResponseDto.builder() + .memberId(postDetailDto.memberId()) .name(postDetailDto.name()) .major(postDetailDto.major()) .profile(postDetailDto.profile()) diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java index 8425796..c4f5086 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java @@ -7,6 +7,7 @@ import org.gachon.checkmate.domain.member.entity.ProfileImageType; public record PostDetailDto( + Long memberId, String major, MbtiType mbti, GenderType gender, @@ -15,7 +16,8 @@ public record PostDetailDto( PostCheckList postCheckList ) { @QueryProjection - public PostDetailDto(String major, MbtiType mbti, GenderType gender, String name, String profile, PostCheckList postCheckList) { + public PostDetailDto(Long memberId, String major, MbtiType mbti, GenderType gender, String name, String profile, PostCheckList postCheckList) { + this.memberId = memberId; this.major = major; this.mbti = mbti; this.gender = gender; diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchCondition.java b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchCondition.java index a0de622..d7fc828 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchCondition.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchCondition.java @@ -4,6 +4,7 @@ import lombok.AccessLevel; import lombok.Builder; import org.gachon.checkmate.domain.member.entity.GenderType; +import org.gachon.checkmate.domain.post.entity.DormitoryType; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.utils.PostSortType; import org.springframework.data.domain.Pageable; @@ -14,14 +15,16 @@ public record PostSearchCondition( ImportantKeyType importantKeyType, GenderType genderType, + DormitoryType dormitoryType, @NotNull PostSortType postSortType, Pageable pageable ) { - public static PostSearchCondition of(@NotNull String sortType, String importantKeyType, String genderType, Pageable pageable) { + public static PostSearchCondition of(@NotNull String sortType, String importantKeyType, String genderType, String dormitoryType, Pageable pageable) { return PostSearchCondition.builder() .importantKeyType(importantKeyType != null ? toEntityCode(ImportantKeyType.class, importantKeyType) : null) .genderType(genderType != null ? toEntityCode(GenderType.class, genderType) : null) + .dormitoryType(dormitoryType != null ? toEntityCode(DormitoryType.class, dormitoryType) : null) .postSortType(toEntityCode(PostSortType.class, sortType)) .pageable(pageable) .build(); diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/DormitoryType.java b/src/main/java/org/gachon/checkmate/domain/post/entity/DormitoryType.java new file mode 100644 index 0000000..4d193a5 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/DormitoryType.java @@ -0,0 +1,17 @@ +package org.gachon.checkmate.domain.post.entity; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.gachon.checkmate.global.utils.EnumField; + +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public enum DormitoryType implements EnumField { + FIRST("1", "1기숙사"), + SECOND("2", "2기숙사"), + THIRD("3", "3기숙사"); + + private final String code; + private final String desc; +} diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index 68c6e29..b7a85a2 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -4,10 +4,7 @@ import lombok.*; import org.gachon.checkmate.domain.checkList.entity.PostCheckList; import org.gachon.checkmate.domain.member.entity.User; -import org.gachon.checkmate.domain.post.converter.ImportantKeyTypeConverter; -import org.gachon.checkmate.domain.post.converter.PostStateConverter; -import org.gachon.checkmate.domain.post.converter.RoomTypeConverter; -import org.gachon.checkmate.domain.post.converter.SimilarityKeyTypeConverter; +import org.gachon.checkmate.domain.post.converter.*; import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto; import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto; import org.gachon.checkmate.domain.post.dto.request.PostUpdateRequestDto; @@ -35,6 +32,8 @@ public class Post extends BaseTimeEntity { private PostState postState; @Convert(converter = RoomTypeConverter.class) private RoomType roomType; + @Convert(converter = DormitoryTypeConverter.class) + private DormitoryType dormitoryType; @Convert(converter = ImportantKeyTypeConverter.class) private ImportantKeyType importantKeyType; @Convert(converter = SimilarityKeyTypeConverter.class) @@ -55,6 +54,7 @@ public static Post createPost(PostCreateRequestDto postCreateRequestDto, User us .endDate(postCreateRequestDto.endDate()) .postState(PostState.RECRUITING) .roomType(postCreateRequestDto.roomType()) + .dormitoryType(postCreateRequestDto.dormitoryType()) .importantKeyType(postCreateRequestDto.importantKey()) .similarityKeyType(postCreateRequestDto.similarityKey()) .user(user) @@ -77,6 +77,7 @@ public void updatePost(PostUpdateRequestDto postUpdateRequestDto) { this.importantKeyType = postUpdateRequestDto.importantKey(); this.similarityKeyType = postUpdateRequestDto.similarityKey(); this.roomType = postUpdateRequestDto.roomType(); + this.dormitoryType = postUpdateRequestDto.dormitoryType(); this.endDate = postUpdateRequestDto.endDate(); this.postCheckList.updatePostCheckList(postUpdateRequestDto.checkList()); } diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index dc99cd9..d182b2b 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -7,6 +7,7 @@ import org.gachon.checkmate.domain.member.entity.GenderType; import org.gachon.checkmate.domain.member.entity.UserState; import org.gachon.checkmate.domain.post.dto.support.*; +import org.gachon.checkmate.domain.post.entity.DormitoryType; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.Post; import org.springframework.data.domain.Page; @@ -28,6 +29,7 @@ public class PostCustomRepositoryImpl implements PostCustomRepository { public Optional findPostDetail(Long postId) { return Optional.ofNullable(queryFactory .select(new QPostDetailDto( + user.id, user.major, user.mbtiType, user.gender, @@ -66,6 +68,7 @@ public Page searchPosts(PostSearchCondition condition) { .where( eqImportantKey(condition.importantKeyType()), eqGenderType(condition.genderType()), + eqDormitoryType(condition.dormitoryType()), validateUserState() ) .orderBy(post.id.desc()) @@ -78,6 +81,7 @@ public Page searchPosts(PostSearchCondition condition) { .where( eqImportantKey(condition.importantKeyType()), eqGenderType(condition.genderType()), + eqDormitoryType(condition.dormitoryType()), validateUserState() ); return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount); @@ -136,6 +140,10 @@ private BooleanExpression eqGenderType(GenderType genderType) { return genderType != null ? user.gender.eq(genderType) : null; } + private BooleanExpression eqDormitoryType(DormitoryType dormitoryType) { + return dormitoryType != null ? post.dormitoryType.eq(dormitoryType) : null; + } + private BooleanExpression eqImportantKey(ImportantKeyType importantKeyType) { return importantKeyType != null ? post.importantKeyType.eq(importantKeyType) : null; } diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index b6b132c..b010de9 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -65,9 +65,9 @@ public PostSearchResponseDto getMyPosts(Long userId, Pageable pageable) { return PostSearchResponseDto.of(searchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); } - public PostSearchResponseDto getAllPosts(Long userId, String key, String type, String gender, Pageable pageable) { + public PostSearchResponseDto getAllPosts(Long userId, String key, String type, String gender, String dormitory, Pageable pageable) { CheckList checkList = getCheckList(userId); - PostSearchCondition condition = PostSearchCondition.of(type, key, gender, pageable); + PostSearchCondition condition = PostSearchCondition.of(type, key, gender, dormitory, pageable); Page postSearchList = getSearchResults(condition); List searchResults = createPostSearchResponseDto(postSearchList, checkList); PostSortingUtils.sortByTypeForSearchResults(searchResults, condition.postSortType()); diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index c3ae8f3..e41b40b 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -62,6 +62,7 @@ public enum ErrorCode { DUPLICATE_CHECK_LIST(HttpStatus.CONFLICT, "체크리스트가 이미 존재합니다."), DUPLICATE_POST_REPORT(HttpStatus.CONFLICT, "이전에 신고했던 게시물입니다."), DUPLICATE_CHATROOM_REPORT(HttpStatus.CONFLICT, "이전에 신고했던 채팅방입니다."), + POST_LIST_NOT_FOUND(HttpStatus.CONFLICT, "필터에 해당한 게시글들을 찾을 수 없습니다."), /** * 500 Internal Server Error diff --git a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java index 34458b5..29403fa 100644 --- a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java +++ b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java @@ -2,19 +2,31 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.gachon.checkmate.global.error.exception.EntityNotFoundException; import org.gachon.checkmate.global.error.exception.InvalidValueException; import java.util.List; import static org.gachon.checkmate.global.error.ErrorCode.INVALID_PAGING_SIZE; +import static org.gachon.checkmate.global.error.ErrorCode.POST_LIST_NOT_FOUND; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class PagingUtils { public static List convertPaging(List dataList, long offset, int size) { - if (dataList.size() <= offset) - throw new InvalidValueException(INVALID_PAGING_SIZE); + validFilterResult(dataList); + validOffsetSize(dataList, offset); int startIndex = (int) offset; int endIndex = Math.min(dataList.size(), startIndex + size); return dataList.subList(startIndex, endIndex); } + + private static void validFilterResult(List dataList) { + if (dataList.size() == 0) + throw new EntityNotFoundException(POST_LIST_NOT_FOUND); + } + + private static void validOffsetSize(List dataList, long offset){ + if (dataList.size() <= offset) + throw new InvalidValueException(INVALID_PAGING_SIZE); + } }