diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/category/controller/CategoryController.java b/backend/bang-ggood/src/main/java/com/bang_ggood/category/controller/CategoryController.java index cbf7b1c3..810c07fc 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/category/controller/CategoryController.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/category/controller/CategoryController.java @@ -2,8 +2,6 @@ import com.bang_ggood.category.dto.request.CategoryPriorityCreateRequest; import com.bang_ggood.category.dto.response.CategoriesReadResponse; -import com.bang_ggood.category.dto.response.CategoriesReadResponse; -import com.bang_ggood.category.dto.request.CategoryPriorityCreateRequest; import com.bang_ggood.category.service.CategoryService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/category/dto/CategoryQuestionsResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/category/dto/CategoryQuestionsResponse.java deleted file mode 100644 index a9aa261e..00000000 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/category/dto/CategoryQuestionsResponse.java +++ /dev/null @@ -1,8 +0,0 @@ - -package com.bang_ggood.category.dto; - -import com.bang_ggood.checklist.dto.response.QuestionResponse; -import java.util.List; - -public record CategoryQuestionsResponse(Integer categoryId, String categoryName, List questions) { -} diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/category/dto/response/WrittenCategoryQuestionsResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/category/dto/response/WrittenCategoryQuestionsResponse.java deleted file mode 100644 index 30a1d94f..00000000 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/category/dto/response/WrittenCategoryQuestionsResponse.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.bang_ggood.category.dto.response; - -import com.bang_ggood.category.domain.Category; -import com.bang_ggood.checklist.dto.response.WrittenQuestionResponse; -import java.util.List; - -public record WrittenCategoryQuestionsResponse(Integer categoryId, String categoryName, - List questions) { - - public static WrittenCategoryQuestionsResponse of(Category category, List questions) { - return new WrittenCategoryQuestionsResponse( - category.getId(), - category.getName(), - questions - ); - } -} diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/category/service/CategoryService.java b/backend/bang-ggood/src/main/java/com/bang_ggood/category/service/CategoryService.java index 3674af29..e57bbe62 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/category/service/CategoryService.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/category/service/CategoryService.java @@ -5,9 +5,6 @@ import com.bang_ggood.category.dto.request.CategoryPriorityCreateRequest; import com.bang_ggood.category.dto.response.CategoriesReadResponse; import com.bang_ggood.category.dto.response.CategoryReadResponse; -import com.bang_ggood.category.dto.response.CategoriesReadResponse; -import com.bang_ggood.category.dto.request.CategoryPriorityCreateRequest; -import com.bang_ggood.category.dto.response.CategoryReadResponse; import com.bang_ggood.category.repository.CategoryPriorityRepository; import com.bang_ggood.exception.BangggoodException; import com.bang_ggood.user.domain.User; @@ -65,7 +62,9 @@ private void validateCategoryId(CategoryPriorityCreateRequest request) { request.categoryIds().stream() .filter(id -> !Category.contains(id)) .findAny() - .ifPresent(id -> { throw new BangggoodException(CATEGORY_NOT_FOUND); }); + .ifPresent(id -> { + throw new BangggoodException(CATEGORY_NOT_FOUND); + }); } public CategoriesReadResponse readCategories() { diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/controller/ChecklistController.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/controller/ChecklistController.java index db658670..77378119 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/controller/ChecklistController.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/controller/ChecklistController.java @@ -57,7 +57,8 @@ public ResponseEntity readUserChecklistsPreview() @GetMapping("/checklists/comparison") public ResponseEntity readChecklistsComparison( @RequestParam("id") List checklistIds) { - return ResponseEntity.ok(checklistService.readChecklistsComparison(checklistIds)); + User user = new User(1L, "방끗", "bang-ggood@gmail.com"); + return ResponseEntity.ok(checklistService.readChecklistsComparison(user, checklistIds)); } @PutMapping("/checklists/{id}") diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Checklist.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Checklist.java index 33c4adf8..cc5cea5a 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Checklist.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Checklist.java @@ -1,7 +1,10 @@ package com.bang_ggood.checklist.domain; import com.bang_ggood.BaseEntity; +import com.bang_ggood.room.domain.FloorLevel; import com.bang_ggood.room.domain.Room; +import com.bang_ggood.room.domain.Structure; +import com.bang_ggood.room.domain.Type; import com.bang_ggood.user.domain.User; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -95,6 +98,22 @@ public Integer getRoomWalkingTime() { return room.getWalkingTime(); } + public Type getRoomType() { + return room.getType(); + } + + public Integer getRoomSize() { + return room.getSize(); + } + + public FloorLevel getRoomFloorLevel() { + return room.getFloorLevel(); + } + + public Structure getRoomStructure() { + return room.getStructure(); + } + public Integer getDeposit() { return deposit; } diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/ChecklistRank.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/ChecklistRank.java new file mode 100644 index 00000000..ec156c1d --- /dev/null +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/ChecklistRank.java @@ -0,0 +1,15 @@ +package com.bang_ggood.checklist.domain; + +import java.util.List; + +public class ChecklistRank { + + private ChecklistRank() { + } + + public static int calculateRanks(int targetScore, List scores) { + return (int) scores.stream() + .filter(score -> score > targetScore) + .count() + 1; + } +} diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Grade.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Grade.java index bc2687d5..4aeb3cfd 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Grade.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/domain/Grade.java @@ -10,8 +10,7 @@ public enum Grade { GOOD(3), SOSO(2), BAD(1), - NONE(0) - ; + NONE(0); private final int score; diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/ChecklistWithScoreReadResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/ChecklistWithScoreReadResponse.java index c8d3e42d..6deab241 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/ChecklistWithScoreReadResponse.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/ChecklistWithScoreReadResponse.java @@ -1,30 +1,65 @@ package com.bang_ggood.checklist.dto.response; import com.bang_ggood.checklist.domain.Checklist; +import com.bang_ggood.room.dto.response.SelectedRoomResponse; import java.util.List; -public record ChecklistWithScoreReadResponse( - Long checklistId, String roomName, String address, - Integer floor, Integer deposit, Integer rent, - Integer contractTerm, String station, Integer walkingTime, - Integer optionCount, Integer score, - List categories -) { - public static ChecklistWithScoreReadResponse of(Checklist checklist, int checklistOptionCount, int checklistScore, +public class ChecklistWithScoreReadResponse { + + private final Long checklistId; + private final Integer score; + private final SelectedRoomResponse room; + private final List options; + private final List categories; + private Integer rank; + + public ChecklistWithScoreReadResponse(Long checklistId, Integer score, + SelectedRoomResponse room, List options, + List categories) { + this.checklistId = checklistId; + this.score = score; + this.room = room; + this.options = options; + this.categories = categories; + } + + public static ChecklistWithScoreReadResponse of(Checklist checklist, int checklistScore, + SelectedRoomResponse room, List options, List categoryScores) { return new ChecklistWithScoreReadResponse( checklist.getId(), - checklist.getRoomName(), - checklist.getRoomAddress(), - checklist.getRoomFloor(), - checklist.getDeposit(), - checklist.getRent(), - checklist.getContractTerm(), - checklist.getRoomStation(), - checklist.getRoomWalkingTime(), - checklistOptionCount, checklistScore, + room, + options, categoryScores ); } + + public void assignRank(int rank) { + this.rank = rank; + } + + public Long getChecklistId() { + return checklistId; + } + + public Integer getScore() { + return score; + } + + public SelectedRoomResponse getRoom() { + return room; + } + + public List getOptions() { + return options; + } + + public List getCategories() { + return categories; + } + + public Integer getRank() { + return rank; + } } diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/UserChecklistPreviewResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/UserChecklistPreviewResponse.java index 15bbc6a9..27d90b50 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/UserChecklistPreviewResponse.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/UserChecklistPreviewResponse.java @@ -1,7 +1,6 @@ package com.bang_ggood.checklist.dto.response; import com.bang_ggood.checklist.domain.Checklist; - import java.time.LocalDateTime; import java.util.List; diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/WrittenChecklistResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/WrittenChecklistResponse.java deleted file mode 100644 index bdcfc70e..00000000 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/WrittenChecklistResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.bang_ggood.checklist.dto.response; - -import com.bang_ggood.category.dto.response.WrittenCategoryQuestionsResponse; -import com.bang_ggood.room.dto.response.WrittenRoomResponse; -import java.util.List; - -public record WrittenChecklistResponse(WrittenRoomResponse room, List options, - List categories) { -} diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/WrittenQuestionResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/WrittenQuestionResponse.java deleted file mode 100644 index 34fc7ced..00000000 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/dto/response/WrittenQuestionResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.bang_ggood.checklist.dto.response; - -import com.bang_ggood.checklist.domain.ChecklistQuestion; - -public record WrittenQuestionResponse(Integer questionId, String title, String subtitle, String answer) { - - public static WrittenQuestionResponse of(ChecklistQuestion checklistQuestion) { - return new WrittenQuestionResponse( - checklistQuestion.getQuestion().getId(), - checklistQuestion.getQuestion().getTitle(), - checklistQuestion.getQuestion().getSubtitle(), - checklistQuestion.getGrade().name() - ); - } -} diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/repository/ChecklistRepository.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/repository/ChecklistRepository.java index fb3f6150..c2be695d 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/repository/ChecklistRepository.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/repository/ChecklistRepository.java @@ -28,11 +28,14 @@ default Checklist getById(long id) { //TODO: 논리적 삭제 리팩토링 List findByUser(User user); - //TODO: 논리적 삭제 리팩토링 - List findByUserAndIdIn(User user, List checklistIds); - - //TODO: 논리적 삭제 리팩토링 - long countAllByIdIn(List ids); + @Query("SELECT c FROM Checklist c " + + "JOIN FETCH c.user u " + + "JOIN FETCH c.room r " + + "WHERE u = :user " + + "AND c.id IN :checklistIds " + + "AND c.deleted = false") + List findByUserAndIdIn(@Param("user") User user, + @Param("checklistIds") List checklistIds); @Query("SELECT COUNT(c) > 0 FROM Checklist c " + "WHERE c.id = :id " @@ -44,5 +47,4 @@ default Checklist getById(long id) { + "SET c.deleted = true " + "WHERE c.id = :id") void deleteById(@Param("id") long id); - } diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/service/ChecklistService.java b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/service/ChecklistService.java index fc46b0df..d7eddd67 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/service/ChecklistService.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/checklist/service/ChecklistService.java @@ -7,13 +7,14 @@ import com.bang_ggood.checklist.domain.Checklist; import com.bang_ggood.checklist.domain.ChecklistOption; import com.bang_ggood.checklist.domain.ChecklistQuestion; +import com.bang_ggood.checklist.domain.ChecklistRank; import com.bang_ggood.checklist.domain.ChecklistScore; import com.bang_ggood.checklist.domain.CustomChecklistQuestion; import com.bang_ggood.checklist.domain.Grade; import com.bang_ggood.checklist.domain.Option; import com.bang_ggood.checklist.domain.Question; -import com.bang_ggood.checklist.dto.request.ChecklistRequest; import com.bang_ggood.checklist.dto.request.ChecklistInfo; +import com.bang_ggood.checklist.dto.request.ChecklistRequest; import com.bang_ggood.checklist.dto.request.CustomChecklistUpdateRequest; import com.bang_ggood.checklist.dto.request.QuestionRequest; import com.bang_ggood.checklist.dto.response.BadgeResponse; @@ -40,7 +41,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -174,13 +174,13 @@ public SelectedChecklistResponse readChecklistById(long id) { List options = readOptionsByChecklistId(id); - List selectedCategoryQuestionsRespons = + List selectedCategoryQuestionsResponse = readCategoryQuestionsByChecklistId(id); int checklistScore = ChecklistScore.calculateTotalScore(checklist.getQuestions()); return new SelectedChecklistResponse(selectedRoomResponse, options, checklistScore, - selectedCategoryQuestionsRespons); + selectedCategoryQuestionsResponse); } private List readOptionsByChecklistId(long checklistId) { @@ -200,14 +200,14 @@ private List readCategoryQuestionsByChecklist private SelectedCategoryQuestionsResponse readQuestionsByCategory(Category category, List checklistQuestions) { - List selectedQuestionRespons = + List selectedQuestionResponse = Question.filter(category, checklistQuestions).stream() .map(SelectedQuestionResponse::of) .toList(); int categoryScore = ChecklistScore.calculateCategoryScore(category, checklistQuestions); - return SelectedCategoryQuestionsResponse.of(category, categoryScore, selectedQuestionRespons); + return SelectedCategoryQuestionsResponse.of(category, categoryScore, selectedQuestionResponse); } @Transactional @@ -233,23 +233,24 @@ private List createBadges(List questions) { } @Transactional - public ChecklistsWithScoreReadResponse readChecklistsComparison(List checklistIds) { - User user = new User(1L, "방끗", "bang-ggood@gmail.com"); + public ChecklistsWithScoreReadResponse readChecklistsComparison(User user, List checklistIds) { + List checklists = checklistRepository.findByUserAndIdIn(user, checklistIds); - validateChecklistComparison(checklistIds); + validateChecklistComparison(checklists, checklistIds); - List responses = checklistRepository.findByUserAndIdIn(user, checklistIds) + List checklistsWithScore = checklists .stream() .map(this::getChecklistWithScore) - .sorted(Comparator.comparing(ChecklistWithScoreReadResponse::score).reversed()) .toList(); - return new ChecklistsWithScoreReadResponse(responses); + assignRanks(checklistsWithScore, getScores(checklistsWithScore)); + + return new ChecklistsWithScoreReadResponse(checklistsWithScore); } - private void validateChecklistComparison(List checklistIds) { + private void validateChecklistComparison(List userChecklists, List checklistIds) { validateChecklistComparisonCount(checklistIds); - validateChecklist(checklistIds); + validateUserChecklist(userChecklists, checklistIds); } private void validateChecklistComparisonCount(List checklistIds) { @@ -258,26 +259,25 @@ private void validateChecklistComparisonCount(List checklistIds) { } } - private void validateChecklist(List checklistIds) { - if (checklistRepository.countAllByIdIn(checklistIds) != checklistIds.size()) { + private void validateUserChecklist(List userChecklists, List checklistIds) { + if (userChecklists.size() != checklistIds.size()) { throw new BangggoodException(ExceptionCode.CHECKLIST_NOT_FOUND); } } - private ChecklistWithScoreReadResponse getChecklistWithScore(Checklist checklist) { List categoryScores = getCategoryScores(checklist.getQuestions()); int checklistScore = getChecklistScore(checklist.getQuestions()); - int checklistOptionCount = checklistOptionRepository.countByChecklist(checklist); + SelectedRoomResponse selectedRoom = SelectedRoomResponse.of(checklist); + List options = readOptionsByChecklistId(checklist.getId()); - return ChecklistWithScoreReadResponse.of(checklist, checklistOptionCount, checklistScore, categoryScores); + return ChecklistWithScoreReadResponse.of(checklist, checklistScore, selectedRoom, options, categoryScores); } private List getCategoryScores(List questions) { return Arrays.stream(Category.values()) .map(category -> CategoryScoreReadResponse.of(category, ChecklistScore.calculateCategoryScore(category, questions))) - .filter(response -> response.score() != 0) .toList(); } @@ -285,6 +285,19 @@ private int getChecklistScore(List questions) { return ChecklistScore.calculateTotalScore(questions); } + private List getScores(List checklistsWithScore) { + return checklistsWithScore.stream() + .map(ChecklistWithScoreReadResponse::getScore) + .toList(); + } + + private void assignRanks(List checklistsWithScore, List scores) { + checklistsWithScore + .forEach(checklistWithScore -> checklistWithScore.assignRank( + ChecklistRank.calculateRanks(checklistWithScore.getScore(), scores) + )); + } + @Transactional public void updateChecklistById(User user, long id, ChecklistRequest checklistRequest) { Checklist checklist = checklistRepository.getById(id); diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/exception/ExceptionCode.java b/backend/bang-ggood/src/main/java/com/bang_ggood/exception/ExceptionCode.java index e161ecfb..dd52a714 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/exception/ExceptionCode.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/exception/ExceptionCode.java @@ -46,6 +46,9 @@ public enum ExceptionCode { // Room ROOM_FLOOR_AND_LEVEL_INVALID(HttpStatus.BAD_REQUEST, "방이 지상층일 경우에만 층수를 입력할 수 있습니다."), + //Score + SCORE_NOT_DESCENDING_SORTED(HttpStatus.BAD_REQUEST, "정렬되지 않은 점수입니다."), + // Auth OAUTH_TOKEN_INTERNAL_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "토큰을 요청하는 과정에서 예상치 못한 예외가 발생했습니다."); diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/handler/GlobalExceptionHandler.java b/backend/bang-ggood/src/main/java/com/bang_ggood/handler/GlobalExceptionHandler.java index df30e69d..beefa577 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/handler/GlobalExceptionHandler.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/handler/GlobalExceptionHandler.java @@ -1,8 +1,8 @@ package com.bang_ggood.handler; import com.bang_ggood.exception.BangggoodException; -import com.bang_ggood.exception.dto.ExceptionResponse; import com.bang_ggood.exception.OauthException; +import com.bang_ggood.exception.dto.ExceptionResponse; import com.bang_ggood.exception.dto.OauthExceptionResponse; import jakarta.servlet.http.HttpServletRequest; import org.springframework.http.HttpStatus; diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/SelectedRoomResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/SelectedRoomResponse.java index 65d30ec6..2a06f5c7 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/SelectedRoomResponse.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/SelectedRoomResponse.java @@ -3,10 +3,14 @@ import com.bang_ggood.checklist.domain.Checklist; public record SelectedRoomResponse(String roomName, Integer deposit, Integer rent, Integer contractTerm, Integer floor, - String address, String station, Integer walkingTime, String realEstate) { + String address, String station, Integer walkingTime, String realEstate, + String type, Integer size, String floorLevel, String structure) { + public static SelectedRoomResponse of(Checklist checklist) { return new SelectedRoomResponse(checklist.getRoomName(), checklist.getDeposit(), checklist.getRent(), checklist.getContractTerm(), checklist.getRoomFloor(), checklist.getRoomAddress(), - checklist.getRoomStation(), checklist.getRoomWalkingTime(), checklist.getRealEstate()); + checklist.getRoomStation(), checklist.getRoomWalkingTime(), checklist.getRealEstate(), + checklist.getRoomType().getName(), checklist.getRoomSize(), checklist.getRoomFloorLevel().name(), + checklist.getRoomStructure().name()); } } diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/WrittenRoomResponse.java b/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/WrittenRoomResponse.java deleted file mode 100644 index f3e859a5..00000000 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/room/dto/response/WrittenRoomResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.bang_ggood.room.dto.response; - -import com.bang_ggood.checklist.domain.Checklist; - -public record WrittenRoomResponse(String name, Integer deposit, Integer rent, Integer contractTerm, Integer floor, - String address, String station, Integer walkingTime, String realEstate) { - public static WrittenRoomResponse of(Checklist checklist) { - return new WrittenRoomResponse(checklist.getRoomName(), checklist.getDeposit(), checklist.getRent(), - checklist.getContractTerm(), checklist.getRoomFloor(), checklist.getRoomAddress(), - checklist.getRoomStation(), checklist.getRoomWalkingTime(), checklist.getRealEstate()); - } -} diff --git a/backend/bang-ggood/src/main/java/com/bang_ggood/user/service/OauthClient.java b/backend/bang-ggood/src/main/java/com/bang_ggood/user/service/OauthClient.java index 4a97d848..53d0110f 100644 --- a/backend/bang-ggood/src/main/java/com/bang_ggood/user/service/OauthClient.java +++ b/backend/bang-ggood/src/main/java/com/bang_ggood/user/service/OauthClient.java @@ -27,8 +27,8 @@ public OauthClient( @Value("${kakao.user_get_uri}") String userInfoRequestUri, @Value("${kakao.grant_type}") String grantType, @Value("${kakao.client_id}") String clientId, - @Value("${kakao.redirect_uri}")String redirectUrl, - @Value("${kakao.client_secret}")String clientSecret) { + @Value("${kakao.redirect_uri}") String redirectUrl, + @Value("${kakao.client_secret}") String clientSecret) { this.restClient = restClient; this.tokenRequestUri = tokenRequestUri; this.userInfoRequestUri = userInfoRequestUri; diff --git a/backend/bang-ggood/src/main/resources/schema.sql b/backend/bang-ggood/src/main/resources/schema.sql index 9efc8f52..ff1b6eda 100644 --- a/backend/bang-ggood/src/main/resources/schema.sql +++ b/backend/bang-ggood/src/main/resources/schema.sql @@ -32,7 +32,7 @@ CREATE TABLE users email VARCHAR(255) NOT NULL, created_at TIMESTAMP(6), modified_at TIMESTAMP(6), - deleted BOOLEAN + deleted BOOLEAN ); CREATE TABLE checklist @@ -46,7 +46,7 @@ CREATE TABLE checklist room_id BIGINT NOT NULL UNIQUE, user_id BIGINT NOT NULL, real_estate VARCHAR(255), - deleted BOOLEAN, + deleted BOOLEAN, FOREIGN KEY (room_id) REFERENCES room (id), FOREIGN KEY (user_id) REFERENCES users (id) ); @@ -77,23 +77,48 @@ CREATE TABLE checklist_option CREATE TABLE category_priority ( - id bigint generated by default as identity, - category_id INTEGER not null, - user_id bigint not null, - created_at TIMESTAMP not null, - modified_at TIMESTAMP not null, - deleted BOOLEAN, - primary key (id), - foreign key (user_id) references users -); + id + bigint + generated + by + default as + identity, + category_id + INTEGER + not + null, + user_id + bigint + not + null, + created_at + TIMESTAMP + not + null, + modified_at + TIMESTAMP + not + null, + deleted + BOOLEAN, + primary + key +( + id +), + foreign key +( + user_id +) references users + ); CREATE TABLE custom_checklist_question ( - id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - user_id BIGINT, - question VARCHAR(255), - created_at TIMESTAMP(6), - modified_at TIMESTAMP(6), - deleted BOOLEAN, + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + user_id BIGINT, + question VARCHAR(255), + created_at TIMESTAMP(6), + modified_at TIMESTAMP(6), + deleted BOOLEAN, FOREIGN KEY (user_id) references users ); diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/ChecklistFixture.java b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/ChecklistFixture.java index 43ba1502..f28472e7 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/ChecklistFixture.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/ChecklistFixture.java @@ -7,14 +7,13 @@ import com.bang_ggood.checklist.dto.request.ChecklistRequest; import com.bang_ggood.checklist.dto.request.QuestionRequest; import com.bang_ggood.room.RoomFixture; -import com.bang_ggood.user.domain.User; - +import com.bang_ggood.user.UserFixture; import java.util.List; public class ChecklistFixture { public static final Checklist checklist = new Checklist( - new User(1L, "방방이", "bang-ggood@gmail.com"), + UserFixture.USER1, RoomFixture.ROOM_1, 1000, 50, 12, "방끗공인중개사" ); diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/controller/ChecklistE2ETest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/controller/ChecklistE2ETest.java index 78e86679..39f76fb6 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/controller/ChecklistE2ETest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/controller/ChecklistE2ETest.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; - import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/domain/ChecklistRankTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/domain/ChecklistRankTest.java new file mode 100644 index 00000000..a9964f0d --- /dev/null +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/domain/ChecklistRankTest.java @@ -0,0 +1,84 @@ +package com.bang_ggood.checklist.domain; + +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +class ChecklistRankTest { + + @DisplayName("Score 에 대한 Rank 계산 성공 : 3명인 경우") + @Test + void calculateRanksByDescendingScores_threeScores() { + //give + List scores = List.of(5, 3, 1); + + //when & then + assertAll( + () -> assertThat(ChecklistRank.calculateRanks(5, scores)).isEqualTo(1), + () -> assertThat(ChecklistRank.calculateRanks(3, scores)).isEqualTo(2), + () -> assertThat(ChecklistRank.calculateRanks(1, scores)).isEqualTo(3) + ); + } + + @DisplayName("Score 에 대한 Rank 계산 성공 : 2명인 경우") + @Test + void calculateRanksByDescendingScores_twoScores() { + //given + List scores = List.of(5, 3); + + //when & then + assertAll( + () -> assertThat(ChecklistRank.calculateRanks(5, scores)).isEqualTo(1), + () -> assertThat(ChecklistRank.calculateRanks(3, scores)).isEqualTo(2) + ); + } + + @DisplayName("Score 에 대한 Rank 계산 성공 : 1명인 경우") + @Test + void calculateRanksByDescendingScores_oneScores() { + //given + List scores = List.of(5); + + //when & then + assertThat(ChecklistRank.calculateRanks(5, scores)).isEqualTo(1); + } + + @DisplayName("Score 에 대한 Rank 계산 성공 : 모두 점수가 같은 경우") + @Test + void calculateRanksByDescendingScores_allSameScore() { + //given + List scores = List.of(5, 5, 5); + + //when & then + assertThat(ChecklistRank.calculateRanks(5, scores)).isEqualTo(1); + } + + @DisplayName("Score 에 대한 Rank 계산 성공 : 1등이 2명인 경우") + @Test + void calculateRanksByDescendingScores_bothRankOne() { + //given + List scores = List.of(5, 5, 1); + + //when & then + assertAll( + () -> assertThat(ChecklistRank.calculateRanks(5, scores)).isEqualTo(1), + () -> assertThat(ChecklistRank.calculateRanks(1, scores)).isEqualTo(3) + ); + } + + @DisplayName("Score 에 대한 Rank 계산 성공 : 2등이 2명인 경우") + @Test + void calculateRanksByDescendingScores_BothRankTwo() { + //given + List scores = List.of(5, 1, 1); + + //when & then + assertAll( + () -> assertThat(ChecklistRank.calculateRanks(5, scores)).isEqualTo(1), + () -> assertThat(ChecklistRank.calculateRanks(1, scores)).isEqualTo(2) + ); + } +} diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/option/OptionTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/option/OptionTest.java index 74ecde46..a524256c 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/option/OptionTest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/option/OptionTest.java @@ -1,11 +1,11 @@ package com.bang_ggood.checklist.option; -import static org.assertj.core.api.Assertions.assertThat; - import com.bang_ggood.checklist.domain.Option; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + class OptionTest { @DisplayName("옵션 포함 성공: 포함하는 경우") diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/repository/ChecklistRepositoryTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/repository/ChecklistRepositoryTest.java index a39e07ff..aa5691f8 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/repository/ChecklistRepositoryTest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/repository/ChecklistRepositoryTest.java @@ -7,11 +7,12 @@ import com.bang_ggood.exception.ExceptionCode; import com.bang_ggood.room.RoomFixture; import com.bang_ggood.room.repository.RoomRepository; -import org.assertj.core.api.Assertions; +import com.bang_ggood.user.UserFixture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -52,6 +53,16 @@ void findById_notFound_exception() { .hasMessage(ExceptionCode.CHECKLIST_NOT_FOUND.getMessage()); } + @DisplayName("체크리스트 아이디 리스트 중 유저가 생성한 체크리스트 목록 갖고 오기 성공") + @Test + void findByUserAndIdIn() { + //given + Checklist savedChecklist = checklistRepository.save(ChecklistFixture.checklist); + + assertThat(checklistRepository.findByUserAndIdIn(UserFixture.USER1, List.of(savedChecklist.getId()))) + .isEqualTo(List.of(savedChecklist)); + } + @DisplayName("아이디를 통해 체크리스트 존재 확인 성공 : 존재하는 경우") @Test void existsById_true() { diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/service/ChecklistServiceTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/service/ChecklistServiceTest.java index b35cd45a..5b669767 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/service/ChecklistServiceTest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/checklist/service/ChecklistServiceTest.java @@ -4,9 +4,11 @@ import com.bang_ggood.category.domain.Category; import com.bang_ggood.checklist.ChecklistFixture; import com.bang_ggood.checklist.domain.Checklist; -import com.bang_ggood.checklist.dto.request.CustomChecklistUpdateRequest; +import com.bang_ggood.checklist.domain.ChecklistQuestion; +import com.bang_ggood.checklist.domain.Grade; +import com.bang_ggood.checklist.domain.Question; import com.bang_ggood.checklist.dto.request.ChecklistRequest; - +import com.bang_ggood.checklist.dto.request.CustomChecklistUpdateRequest; import com.bang_ggood.checklist.dto.response.ChecklistQuestionsResponse; import com.bang_ggood.checklist.dto.response.ChecklistsWithScoreReadResponse; import com.bang_ggood.checklist.dto.response.SelectedChecklistResponse; @@ -22,12 +24,10 @@ import com.bang_ggood.room.repository.RoomRepository; import com.bang_ggood.user.UserFixture; import com.bang_ggood.user.domain.User; -import java.sql.Struct; -import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; +import java.util.List; import static com.bang_ggood.checklist.CustomChecklistFixture.CUSTOM_CHECKLIST_UPDATE_REQUEST; import static com.bang_ggood.checklist.CustomChecklistFixture.CUSTOM_CHECKLIST_UPDATE_REQUEST_DUPLICATED; @@ -82,7 +82,8 @@ void createChecklist() { void createChecklist_invalidQuestionId_exception() { //given & when & then assertThatThrownBy( - () -> checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST_INVALID_QUESTION_ID)) + () -> checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST_INVALID_QUESTION_ID)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.QUESTION_INVALID.getMessage()); } @@ -217,13 +218,13 @@ void readChecklistById_invalidChecklistId_exception() { @Test void readChecklistsComparison() { // given - User user = new User(1L, "방방이", "bang-ggood@gmail.com"); + User user1 = UserFixture.USER1; Room room1 = RoomFixture.ROOM_1; Room room2 = RoomFixture.ROOM_2; Room room3 = RoomFixture.ROOM_3; - Checklist checklist1 = createChecklist(user, room1); - Checklist checklist2 = createChecklist(user, room2); - Checklist checklist3 = createChecklist(user, room3); + Checklist checklist1 = createChecklist(user1, room1); + Checklist checklist2 = createChecklist(user1, room2); + Checklist checklist3 = createChecklist(user1, room3); roomRepository.saveAll(List.of(room1, room2, room3)); List checklists = checklistRepository.saveAll(List.of(checklist1, checklist2, checklist3)); @@ -231,20 +232,53 @@ void readChecklistsComparison() { checklists.get(2).getId()); // when - ChecklistsWithScoreReadResponse response = checklistService.readChecklistsComparison(checklistIds); + ChecklistsWithScoreReadResponse response = checklistService.readChecklistsComparison(user1, checklistIds); // then assertThat(response.checklists()).hasSize(3); } + @DisplayName("체크리스트 비교 성공 : 순위가 정상적으로 계산된 경우") + @Test + void readChecklistsComparison_compareRank() { + // given + User user1 = UserFixture.USER1; + Room room1 = RoomFixture.ROOM_1; + Room room2 = RoomFixture.ROOM_2; + Room room3 = RoomFixture.ROOM_3; + Checklist checklist1 = createChecklist(user1, room1); + Checklist checklist2 = createChecklist(user1, room2); + Checklist checklist3 = createChecklist(user1, room3); + ChecklistQuestion checklistQuestion1 = new ChecklistQuestion(checklist1, Question.CLEAN_1, Grade.GOOD, null); + ChecklistQuestion checklistQuestion2 = new ChecklistQuestion(checklist2, Question.CLEAN_2, Grade.SOSO, null); + ChecklistQuestion checklistQuestion3 = new ChecklistQuestion(checklist3, Question.CLEAN_3, Grade.BAD, null); + + roomRepository.saveAll(List.of(room1, room2, room3)); + List checklists = checklistRepository.saveAll(List.of(checklist1, checklist2, checklist3)); + checklistQuestionRepository.saveAll(List.of(checklistQuestion1, checklistQuestion2, checklistQuestion3)); + List checklistIds = List.of(checklists.get(0).getId(), checklists.get(1).getId(), + checklists.get(2).getId()); + + // when + ChecklistsWithScoreReadResponse response = checklistService.readChecklistsComparison(user1, checklistIds); + + // then + assertAll( + () -> assertThat(response.checklists().get(0).getRank()).isEqualTo(1), + () -> assertThat(response.checklists().get(1).getRank()).isEqualTo(2), + () -> assertThat(response.checklists().get(2).getRank()).isEqualTo(3) + ); + } + @DisplayName("체크리스트 비교 실패 : 아이디 개수가 유효하지 않을 때") @Test void readChecklistsComparison_invalidIdCount() { // given + User user1 = UserFixture.USER1; List invalidChecklistIds = List.of(1L, 2L, 3L, 4L); // when & then - assertThatCode(() -> checklistService.readChecklistsComparison(invalidChecklistIds)) + assertThatCode(() -> checklistService.readChecklistsComparison(user1, invalidChecklistIds)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.CHECKLIST_COMPARISON_INVALID_COUNT.getMessage()); } @@ -253,13 +287,13 @@ void readChecklistsComparison_invalidIdCount() { @Test void readChecklistsComparison_invalidId() { // given - User user = new User(1L, "방방이", "bang-ggood@gmail.com"); + User user1 = UserFixture.USER1; Room room1 = RoomFixture.ROOM_1; Room room2 = RoomFixture.ROOM_2; Room room3 = RoomFixture.ROOM_3; - Checklist checklist1 = createChecklist(user, room1); - Checklist checklist2 = createChecklist(user, room2); - Checklist checklist3 = createChecklist(user, room3); + Checklist checklist1 = createChecklist(user1, room1); + Checklist checklist2 = createChecklist(user1, room2); + Checklist checklist3 = createChecklist(user1, room3); roomRepository.saveAll(List.of(room1, room2, room3)); List checklists = checklistRepository.saveAll(List.of(checklist1, checklist2, checklist3)); @@ -267,7 +301,7 @@ void readChecklistsComparison_invalidId() { checklists.get(2).getId() + 1); // when & then - assertThatCode(() -> checklistService.readChecklistsComparison(invalidChecklistIds)) + assertThatCode(() -> checklistService.readChecklistsComparison(user1, invalidChecklistIds)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.CHECKLIST_NOT_FOUND.getMessage()); } @@ -276,7 +310,8 @@ void readChecklistsComparison_invalidId() { @Test void updateChecklistById() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_UPDATE_REQUEST); @@ -285,7 +320,8 @@ void updateChecklistById() { Checklist checklist = checklistRepository.getById(checklistId); assertAll( () -> assertThat(checklist.getRoom().getStructure()).isEqualTo(Structure.OPEN_ONE_ROOM), - () -> assertThat(checklistOptionRepository.findByChecklistId(checklistId).get(3).getOptionId()).isEqualTo(4), + () -> assertThat( + checklistOptionRepository.findByChecklistId(checklistId).get(3).getOptionId()).isEqualTo(4), () -> assertThat(checklist.getQuestions().get(3).getMemo()).isEqualTo("메모") ); } @@ -294,11 +330,13 @@ void updateChecklistById() { @Test void updateChecklistById_invalidQuestionId_exception() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when & then assertThatThrownBy( - () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_UPDATE_REQUEST_INVALID_QUESTION_ID)) + () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, + ChecklistFixture.CHECKLIST_UPDATE_REQUEST_INVALID_QUESTION_ID)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.QUESTION_INVALID.getMessage()); } @@ -307,11 +345,13 @@ void updateChecklistById_invalidQuestionId_exception() { @Test void updateChecklistById_duplicatedQuestionId_exception() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when & then assertThatThrownBy( - () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_CREATE_REQUEST_DUPLICATED_QUESTION_ID)) + () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, + ChecklistFixture.CHECKLIST_CREATE_REQUEST_DUPLICATED_QUESTION_ID)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.QUESTION_DUPLICATED.getMessage()); } @@ -320,11 +360,13 @@ void updateChecklistById_duplicatedQuestionId_exception() { @Test void updateChecklistById_invalidOptionId_exception() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when & then assertThatThrownBy( - () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_UPDATE_REQUEST_INVALID_OPTION_ID)) + () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, + ChecklistFixture.CHECKLIST_UPDATE_REQUEST_INVALID_OPTION_ID)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.OPTION_INVALID.getMessage()); } @@ -333,11 +375,13 @@ void updateChecklistById_invalidOptionId_exception() { @Test void updateChecklistById_duplicatedOptionId_exception() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when & then assertThatThrownBy( - () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_UPDATE_REQUEST_DUPLICATED_OPTION_ID)) + () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, + ChecklistFixture.CHECKLIST_UPDATE_REQUEST_DUPLICATED_OPTION_ID)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.OPTION_DUPLICATED.getMessage()); } @@ -346,11 +390,13 @@ void updateChecklistById_duplicatedOptionId_exception() { @Test void updateChecklistById_differentQuestionLength_exception() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when & then assertThatThrownBy( - () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_UPDATE_REQUEST_DIFFERENT_QUESTION_LENGTH)) + () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, + ChecklistFixture.CHECKLIST_UPDATE_REQUEST_DIFFERENT_QUESTION_LENGTH)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.QUESTION_DIFFERENT.getMessage()); } @@ -359,11 +405,13 @@ void updateChecklistById_differentQuestionLength_exception() { @Test void createChecklist_differentQuestion_exception() { //given - long checklistId = checklistService.createChecklist(UserFixture.USER1, ChecklistFixture.CHECKLIST_CREATE_REQUEST); + long checklistId = checklistService.createChecklist(UserFixture.USER1, + ChecklistFixture.CHECKLIST_CREATE_REQUEST); //when & then assertThatThrownBy( - () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, ChecklistFixture.CHECKLIST_UPDATE_REQUEST_DIFFERENT_QUESTION)) + () -> checklistService.updateChecklistById(UserFixture.USER1, checklistId, + ChecklistFixture.CHECKLIST_UPDATE_REQUEST_DIFFERENT_QUESTION)) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.QUESTION_DIFFERENT.getMessage()); } @@ -440,8 +488,8 @@ void deleteChecklistById() { @Test void deleteChecklistById_notFound_exception() { // given & when & then - assertThatThrownBy(() -> checklistService.deleteChecklistById(-1)) - .isInstanceOf(BangggoodException.class) - .hasMessage(ExceptionCode.CHECKLIST_NOT_FOUND.getMessage()); + assertThatThrownBy(() -> checklistService.deleteChecklistById(-1)) + .isInstanceOf(BangggoodException.class) + .hasMessage(ExceptionCode.CHECKLIST_NOT_FOUND.getMessage()); } } diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/user/UserFixture.java b/backend/bang-ggood/src/test/java/com/bang_ggood/user/UserFixture.java index d839907a..e764995a 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/user/UserFixture.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/user/UserFixture.java @@ -8,13 +8,13 @@ public class UserFixture { public static final User USER1 = new User(1L, "방방이", "bang-bang@gmail.com"); - public static final User USER2 = new User("빵빵이", "bbang-bbang@gmail.com"); + public static final User USER2 = new User(2L, "빵빵이", "bbang-bbang@gmail.com"); public static final OauthInfoResponse OAUTH_INFO_RESPONSE_USER1 = new OauthInfoResponse("", "", new KakaoAccountResponse(USER1.getEmail(), USER1.getName(), - new ProfileResponse("", "",""))); + new ProfileResponse("", "", ""))); public static final OauthInfoResponse OAUTH_INFO_RESPONSE_USER2 = new OauthInfoResponse("", "", new KakaoAccountResponse(USER2.getEmail(), USER2.getName(), - new ProfileResponse("", "",""))); + new ProfileResponse("", "", ""))); } diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/user/service/UserServiceTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/user/service/UserServiceTest.java index 8fac2eb5..a34ecd82 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/user/service/UserServiceTest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/user/service/UserServiceTest.java @@ -13,8 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import static com.bang_ggood.user.UserFixture.USER1; import static com.bang_ggood.user.UserFixture.OAUTH_INFO_RESPONSE_USER1; +import static com.bang_ggood.user.UserFixture.USER1; import static org.mockito.ArgumentMatchers.any; @ExtendWith(MockitoExtension.class) diff --git a/backend/bang-ggood/src/test/resources/schema-test.sql b/backend/bang-ggood/src/test/resources/schema-test.sql index 4348b96c..707e8fa8 100644 --- a/backend/bang-ggood/src/test/resources/schema-test.sql +++ b/backend/bang-ggood/src/test/resources/schema-test.sql @@ -33,7 +33,7 @@ CREATE TABLE users email VARCHAR(255) NOT NULL, created_at TIMESTAMP(6), modified_at TIMESTAMP(6), - deleted BOOLEAN + deleted BOOLEAN ); CREATE TABLE checklist @@ -47,7 +47,7 @@ CREATE TABLE checklist room_id BIGINT NOT NULL UNIQUE, user_id BIGINT NOT NULL, real_estate VARCHAR(255), - deleted BOOLEAN, + deleted BOOLEAN, FOREIGN KEY (room_id) REFERENCES room (id), FOREIGN KEY (user_id) REFERENCES users (id) ); @@ -84,7 +84,7 @@ CREATE TABLE category_priority user_id bigint not null, created_at TIMESTAMP not null, modified_at TIMESTAMP not null, - deleted BOOLEAN, + deleted BOOLEAN, primary key (id), foreign key (user_id) references users ); @@ -96,17 +96,17 @@ CREATE TABLE test_entity name varchar(255) not null, created_at TIMESTAMP not null, modified_at TIMESTAMP not null, - deleted BOOLEAN, + deleted BOOLEAN, primary key (id) ); CREATE TABLE custom_checklist_question ( - id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - user_id BIGINT, - question VARCHAR(255), - created_at TIMESTAMP(6), - modified_at TIMESTAMP(6), - deleted BOOLEAN, + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + user_id BIGINT, + question VARCHAR(255), + created_at TIMESTAMP(6), + modified_at TIMESTAMP(6), + deleted BOOLEAN, FOREIGN KEY (user_id) references users );