Skip to content

Commit

Permalink
Merge pull request #56 from Domitory-CheckMate/feature/55-domain
Browse files Browse the repository at this point in the history
[fix] api 연동 오류 해결
  • Loading branch information
OJOJIN authored Jan 22, 2024
2 parents a62f2ae + 20fb53b commit 95948cd
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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 @@ -6,6 +6,7 @@

@Builder
public record PostDetailResponseDto(
Long memberId,
String name,
String major,
String profile,
Expand All @@ -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())
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.ProfileImageType;

public record PostDetailDto(
Long memberId,
String major,
MbtiType mbti,
GenderType gender,
Expand All @@ -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;
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 All @@ -28,6 +29,7 @@ public class PostCustomRepositoryImpl implements PostCustomRepository {
public Optional<PostDetailDto> findPostDetail(Long postId) {
return Optional.ofNullable(queryFactory
.select(new QPostDetailDto(
user.id,
user.major,
user.mbtiType,
user.gender,
Expand Down Expand Up @@ -66,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 @@ -78,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 @@ -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;
}
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 @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> List<T> convertPaging(List<T> 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 <T> void validFilterResult(List<T> dataList) {
if (dataList.size() == 0)
throw new EntityNotFoundException(POST_LIST_NOT_FOUND);
}

private static <T> void validOffsetSize(List<T> dataList, long offset){
if (dataList.size() <= offset)
throw new InvalidValueException(INVALID_PAGING_SIZE);
}
}

0 comments on commit 95948cd

Please sign in to comment.