-
Notifications
You must be signed in to change notification settings - Fork 6
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
[BE] 방 비교 결과 조회 API에 기능을 추가 구현한다. #215
Changes from all commits
f538567
b36ff94
e2466d9
e581a50
1c7e10b
51a8121
0d15ffe
9e3d1ea
3c4d63a
f247693
0be2c6b
b18b3ae
0ef6035
7378345
483c7cb
905a6cf
7178c39
8abc291
2ba0997
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,8 @@ public ResponseEntity<UserChecklistsPreviewResponse> readUserChecklistsPreview() | |
@GetMapping("/checklists/comparison") | ||
public ResponseEntity<ChecklistsWithScoreReadResponse> readChecklistsComparison( | ||
@RequestParam("id") List<Long> checklistIds) { | ||
return ResponseEntity.ok(checklistService.readChecklistsComparison(checklistIds)); | ||
User user = new User(1L, "방끗", "[email protected]"); | ||
return ResponseEntity.ok(checklistService.readChecklistsComparison(user, checklistIds)); | ||
} | ||
|
||
@PutMapping("/checklists/{id}") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> scores) { | ||
return (int) scores.stream() | ||
.filter(score -> score > targetScore) | ||
.count() + 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,7 @@ public enum Grade { | |
GOOD(3), | ||
SOSO(2), | ||
BAD(1), | ||
NONE(0) | ||
; | ||
NONE(0); | ||
|
||
private final int score; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CategoryScoreReadResponse> 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<SelectedOptionResponse> options; | ||
private final List<CategoryScoreReadResponse> categories; | ||
private Integer rank; | ||
|
||
public ChecklistWithScoreReadResponse(Long checklistId, Integer score, | ||
SelectedRoomResponse room, List<SelectedOptionResponse> options, | ||
List<CategoryScoreReadResponse> 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<SelectedOptionResponse> options, | ||
List<CategoryScoreReadResponse> 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<SelectedOptionResponse> getOptions() { | ||
return options; | ||
} | ||
|
||
public List<CategoryScoreReadResponse> getCategories() { | ||
return categories; | ||
} | ||
|
||
public Integer getRank() { | ||
return rank; | ||
} | ||
tsulocalize marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,14 @@ default Checklist getById(long id) { | |
//TODO: 논리적 삭제 리팩토링 | ||
List<Checklist> findByUser(User user); | ||
|
||
//TODO: 논리적 삭제 리팩토링 | ||
List<Checklist> findByUserAndIdIn(User user, List<Long> checklistIds); | ||
|
||
//TODO: 논리적 삭제 리팩토링 | ||
long countAllByIdIn(List<Long> ids); | ||
@Query("SELECT c FROM Checklist c " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 쿼리를 따로 작성한 코드에 대해서는 테스트를 작성해 보아도 좋을 것 같습니다~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 작성 완료! |
||
+ "JOIN FETCH c.user u " | ||
+ "JOIN FETCH c.room r " | ||
+ "WHERE u = :user " | ||
+ "AND c.id IN :checklistIds " | ||
+ "AND c.deleted = false") | ||
List<Checklist> findByUserAndIdIn(@Param("user") User user, | ||
@Param("checklistIds") List<Long> 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); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
record에서 class로 바꾼 이유가 있으신가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
객체 생성시 rank를 할당할 수가 없는데 Record를 사용할 경우 setter 사용이 불가했습니다.
rank 계산 후 값을 할당해주기 위해 class로 변경하였습니다!