Skip to content

Commit

Permalink
[fix] #55 게시글에 기숙사 유형 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuKwanKon committed Jan 21, 2024
1 parent 1cd4408 commit 6a1907b
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public class PostController {

@GetMapping
public ResponseEntity<SuccessResponse<?>> 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);
}

Expand All @@ -54,7 +55,7 @@ public ResponseEntity<SuccessResponse<?>> getMyPosts(@UserId final Long userId,
return SuccessResponse.ok(responseDto);
}

@PatchMapping("{id}")
@PatchMapping("/{id}")
public ResponseEntity<SuccessResponse<?>> updateMyPost(@UserId final Long userId,
@PathVariable("id") final Long postId,
@RequestBody @Valid final PostUpdateRequestDto requestDto) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DormitoryType> {
public DormitoryTypeConverter() {
super(DormitoryType.class);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +68,7 @@ public Page<PostSearchDto> searchPosts(PostSearchCondition condition) {
.where(
eqImportantKey(condition.importantKeyType()),
eqGenderType(condition.genderType()),
eqDormitoryType(condition.dormitoryType()),
validateUserState()
)
.orderBy(post.id.desc())
Expand All @@ -79,6 +81,7 @@ public Page<PostSearchDto> searchPosts(PostSearchCondition condition) {
.where(
eqImportantKey(condition.importantKeyType()),
eqGenderType(condition.genderType()),
eqDormitoryType(condition.dormitoryType()),
validateUserState()
);
return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount);
Expand Down Expand Up @@ -137,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostSearchDto> postSearchList = getSearchResults(condition);
List<PostSearchElementResponseDto> searchResults = createPostSearchResponseDto(postSearchList, checkList);
PostSortingUtils.sortByTypeForSearchResults(searchResults, condition.postSortType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public enum ErrorCode {
CHATROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "해당하는 채팅방을 찾을 수 없습니다."),
REFRESH_TOKEN_NOT_FOUND(HttpStatus.NOT_FOUND, "해당하는 리프레시 토큰을 찾을 수 없습니다. 다시 로그인해 주세요."),
UNAFFILIATED_EMAIL(HttpStatus.CONFLICT, "가입되지 않은 이메일입니다."),
POST_LIST_NOT_FOUND(HttpStatus.NOT_FOUND, "필터에 해당한 게시글들을 찾을 수 없습니다."),

/**
* 405 Method Not Allowed
Expand Down

0 comments on commit 6a1907b

Please sign in to comment.