Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] checklist api 오류 해결 #64

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public ResponseEntity<SuccessResponse<?>> createCheckList(@UserId final Long use
@PatchMapping("/my")
public ResponseEntity<SuccessResponse<?>> updateCheckList(@UserId final Long userId,
@RequestBody final CheckListRequestDto checkListRequestDto) {
System.out.println("my logs " + checkListRequestDto.cleanType());
checkListService.updateCheckList(userId, checkListRequestDto);
return SuccessResponse.ok(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
package org.gachon.checkmate.domain.checkList.dto.request;

import org.gachon.checkmate.domain.checkList.dto.support.CheckListEnumDto;
import org.gachon.checkmate.domain.checkList.entity.*;

public record CheckListRequestDto(
CleanType cleanType,
DrinkType drinkType,
HomeType homeType,
LifePatternType lifePatternType,
CallType callType,
EarPhoneType earPhoneType,
SleepGrindingType sleepGrindingType,
SleepSnoreType sleepSnoreType,
SleepTalkingType sleepTalkingType,
SleepTurningType sleepTurningType,
SmokeType smokeType
import static org.gachon.checkmate.global.utils.EnumValueUtils.toEntityCode;

public record CheckListRequestDto(
String cleanType,
String drinkType,
String homeType,
String lifePatternType,
String callType,
String earPhoneType,
String sleepGrindingType,
String sleepSnoreType,
String sleepTalkingType,
String sleepTurningType,
String smokeType
) {
public static CheckListEnumDto toEnumDto(CheckListRequestDto requestDto) {
return CheckListEnumDto.builder()
.cleanType(toEntityCode(CleanType.class, requestDto.cleanType()))
.drinkType(toEntityCode(DrinkType.class, requestDto.drinkType()))
.homeType(toEntityCode(HomeType.class, requestDto.homeType()))
.lifePatternType(toEntityCode(LifePatternType.class, requestDto.lifePatternType()))
.callType(toEntityCode(CallType.class, requestDto.callType()))
.earPhoneType(toEntityCode(EarPhoneType.class, requestDto.earPhoneType()))
.sleepGrindingType(toEntityCode(SleepGrindingType.class, requestDto.sleepGrindingType()))
.sleepSnoreType(toEntityCode(SleepSnoreType.class, requestDto.sleepSnoreType()))
.sleepTalkingType(toEntityCode(SleepTalkingType.class, requestDto.sleepTalkingType()))
.sleepTurningType(toEntityCode(SleepTurningType.class, requestDto.sleepTurningType()))
.smokeType(toEntityCode(SmokeType.class, requestDto.smokeType()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gachon.checkmate.domain.checkList.dto.support;

import lombok.Builder;
import org.gachon.checkmate.domain.checkList.entity.*;

@Builder
public record CheckListEnumDto(
CleanType cleanType,
DrinkType drinkType,
HomeType homeType,
LifePatternType lifePatternType,
CallType callType,
EarPhoneType earPhoneType,
SleepGrindingType sleepGrindingType,
SleepSnoreType sleepSnoreType,
SleepTalkingType sleepTalkingType,
SleepTurningType sleepTurningType,
SmokeType smokeType
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.*;
import org.gachon.checkmate.domain.checkList.converter.*;
import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto;
import org.gachon.checkmate.domain.checkList.dto.support.CheckListEnumDto;
import org.gachon.checkmate.domain.member.entity.User;
import org.gachon.checkmate.global.common.BaseTimeEntity;

Expand Down Expand Up @@ -43,7 +44,7 @@ public class CheckList extends BaseTimeEntity {
@JoinColumn(name = "user_id")
private User user;

public static CheckList createCheckList(User user, CheckListRequestDto checkListRequestDto) {
public static CheckList createCheckList(User user, CheckListEnumDto checkListRequestDto) {
CheckList checkList = CheckList.builder()
.cleanType(checkListRequestDto.cleanType())
.drinkType(checkListRequestDto.drinkType())
Expand All @@ -62,7 +63,7 @@ public static CheckList createCheckList(User user, CheckListRequestDto checkList
return checkList;
}

public void updateCheckList(CheckListRequestDto checkListRequestDto) {
public void updateCheckList(CheckListEnumDto checkListRequestDto) {
this.cleanType = checkListRequestDto.cleanType();
this.drinkType = checkListRequestDto.drinkType();
this.homeType = checkListRequestDto.homeType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.*;
import org.gachon.checkmate.domain.checkList.converter.*;
import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto;
import org.gachon.checkmate.domain.checkList.dto.support.CheckListEnumDto;
import org.gachon.checkmate.domain.post.entity.Post;
import org.gachon.checkmate.global.common.BaseTimeEntity;

Expand Down Expand Up @@ -43,7 +44,7 @@ public class PostCheckList extends BaseTimeEntity {
@JoinColumn(name = "post_id")
private Post post;

public static PostCheckList createPostCheckList(CheckListRequestDto checkListRequestDto, Post post) {
public static PostCheckList createPostCheckList(CheckListEnumDto checkListRequestDto, Post post) {
PostCheckList checkList = PostCheckList.builder()
.cleanType(checkListRequestDto.cleanType())
.drinkType(checkListRequestDto.drinkType())
Expand All @@ -62,7 +63,7 @@ public static PostCheckList createPostCheckList(CheckListRequestDto checkListReq
return checkList;
}

public void updatePostCheckList(CheckListRequestDto checkListRequestDto) {
public void updatePostCheckList(CheckListEnumDto checkListRequestDto) {
this.cleanType = checkListRequestDto.cleanType();
this.drinkType = checkListRequestDto.drinkType();
this.homeType = checkListRequestDto.homeType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto;
import org.gachon.checkmate.domain.checkList.dto.response.CheckListResponseDto;
import org.gachon.checkmate.domain.checkList.dto.support.CheckListEnumDto;
import org.gachon.checkmate.domain.checkList.entity.CheckList;
import org.gachon.checkmate.domain.checkList.repository.CheckListRepository;
import org.gachon.checkmate.domain.member.entity.User;
Expand All @@ -25,15 +26,17 @@ public class CheckListService {
public void createCheckList(Long userId, CheckListRequestDto checkListRequestDto) {
User user = findByIdOrThrow(userId);
checkIfCheckListExists(user);
CheckList checkList = CheckList.createCheckList(user, checkListRequestDto);
CheckListEnumDto checkListDto = CheckListRequestDto.toEnumDto(checkListRequestDto);
CheckList checkList = CheckList.createCheckList(user, checkListDto);
checkListRepository.save(checkList);
}

public void updateCheckList(Long userId, CheckListRequestDto checkListRequestDto) {
User user = findByIdOrThrow(userId);
checkIfCheckListNotExists(user);
CheckList checkList = user.getCheckList();
checkList.updateCheckList(checkListRequestDto);
CheckListEnumDto checkListDto = CheckListRequestDto.toEnumDto(checkListRequestDto);
checkList.updateCheckList(checkListDto);
checkListRepository.save(checkList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostUpdateRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto;
import org.gachon.checkmate.domain.post.dto.response.PostDetailResponseDto;
import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto;
Expand Down Expand Up @@ -58,7 +57,7 @@ public ResponseEntity<SuccessResponse<?>> getMyPosts(@UserId final Long userId,
@PatchMapping("/{id}")
public ResponseEntity<SuccessResponse<?>> updateMyPost(@UserId final Long userId,
@PathVariable("id") final Long postId,
@RequestBody @Valid final PostUpdateRequestDto requestDto) {
@RequestBody @Valid final PostRequestDto requestDto) {
PostUpdateResponseDto responseDto = postService.updateMyPost(userId, postId, requestDto);
return SuccessResponse.ok(responseDto);
}
Expand All @@ -73,7 +72,7 @@ public ResponseEntity<SuccessResponse<?>> updatePostState(@UserId final Long use

@PostMapping
public ResponseEntity<SuccessResponse<?>> createPost(@UserId final Long userId,
@RequestBody @Valid final PostCreateRequestDto requestDto) {
@RequestBody @Valid final PostRequestDto requestDto) {
postService.createPost(userId, requestDto);
return SuccessResponse.created(null);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.gachon.checkmate.domain.post.dto.request;

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.dto.support.PostEnumDto;
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;

import java.time.LocalDate;

import static org.gachon.checkmate.global.utils.EnumValueUtils.toEntityCode;

public record PostRequestDto(
@NotBlank(message = "제목을 입력해주세요") String title,
@NotBlank(message = "내용을 입력해주세요") String content,
@NotNull(message = "중요 키워드를 입력해주세요") String importantKey,
@NotNull(message = "유사도를 입력해주세요") String similarityKey,
@NotNull(message = "호실을 입력해주세요") String roomType,
@NotNull(message = "기숙사 유형을 입력해주세요") String dormitoryType,
@NotNull(message = "모집 마감기간을 입력해주세요") LocalDate endDate,
@NotNull(message = "체크리스트를 입력해주세요") CheckListRequestDto checkList
) {
public static PostEnumDto toEnumDto(PostRequestDto requestDto) {
return PostEnumDto.builder()
.title(requestDto.title())
.content(requestDto.content())
.importantKey(toEntityCode(ImportantKeyType.class, requestDto.importantKey()))
.similarityKey(toEntityCode(SimilarityKeyType.class, requestDto.similarityKey()))
.roomType(toEntityCode(RoomType.class, requestDto.roomType()))
.dormitoryType(toEntityCode(DormitoryType.class, requestDto.dormitoryType()))
.endDate(requestDto.endDate())
.checkList(CheckListRequestDto.toEnumDto(requestDto.checkList()))
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.gachon.checkmate.domain.post.dto.support;

import lombok.Builder;
import org.gachon.checkmate.domain.checkList.dto.support.CheckListEnumDto;
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;

import java.time.LocalDate;

@Builder
public record PostEnumDto(
String title,
String content,
ImportantKeyType importantKey,
SimilarityKeyType similarityKey,
RoomType roomType,
DormitoryType dormitoryType,
LocalDate endDate,
CheckListEnumDto checkList
) {
}
22 changes: 11 additions & 11 deletions src/main/java/org/gachon/checkmate/domain/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.gachon.checkmate.domain.checkList.entity.PostCheckList;
import org.gachon.checkmate.domain.member.entity.User;
import org.gachon.checkmate.domain.post.converter.*;
import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostUpdateRequestDto;
import org.gachon.checkmate.domain.post.dto.support.PostEnumDto;
import org.gachon.checkmate.domain.scrap.entity.Scrap;
import org.gachon.checkmate.global.common.BaseTimeEntity;

Expand Down Expand Up @@ -47,16 +47,16 @@ public class Post extends BaseTimeEntity {
@Builder.Default
private List<Scrap> scrapList = new ArrayList<>();

public static Post createPost(PostCreateRequestDto postCreateRequestDto, User user) {
public static Post createPost(PostEnumDto postRequestDto, User user) {
Post post = Post.builder()
.title(postCreateRequestDto.title())
.content(postCreateRequestDto.content())
.endDate(postCreateRequestDto.endDate())
.title(postRequestDto.title())
.content(postRequestDto.content())
.endDate(postRequestDto.endDate())
.postState(PostState.RECRUITING)
.roomType(postCreateRequestDto.roomType())
.dormitoryType(postCreateRequestDto.dormitoryType())
.importantKeyType(postCreateRequestDto.importantKey())
.similarityKeyType(postCreateRequestDto.similarityKey())
.roomType(postRequestDto.roomType())
.dormitoryType(postRequestDto.dormitoryType())
.importantKeyType(postRequestDto.importantKey())
.similarityKeyType(postRequestDto.similarityKey())
.user(user)
.build();
user.addPost(post);
Expand All @@ -71,7 +71,7 @@ public void addScrap(Scrap scrap) {
this.scrapList.add(scrap);
}

public void updatePost(PostUpdateRequestDto postUpdateRequestDto) {
public void updatePost(PostEnumDto postUpdateRequestDto) {
this.title = postUpdateRequestDto.title();
this.content = postUpdateRequestDto.content();
this.importantKeyType = postUpdateRequestDto.importantKey();
Expand Down
Loading