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

[refactor] : 옷장 옷 입기 로직 리팩토링 및 전제 조회 필터링 오타 수정 #119

Merged
merged 1 commit into from
Aug 20, 2023
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 @@ -99,9 +99,12 @@ public ResponseEntity<Void> updateClotheGoal(
// 옷장 옷 입기
@PatchMapping("/{id}/wear")
public ResponseEntity<Void> wearClothe(
@PathVariable Long id
@PathVariable Long id,
Authentication authentication,
HttpServletRequest request
) {
this.clotheService.wearClothe(id);
checkAuthentication(authentication, request);
this.clotheService.wearClothe(id, authentication);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface ClosetRepository extends JpaRepository<Clothe, Long> {

List<Clothe> findAllByCategoryAndSeasonAndMemberOrderByCountAsc(Integer category, Integer season, Member member);

@Query("select Count(c) from Clothe c where c.category = :category and c.lastDate = :today")
int getCountOneCategoryPerOnDay(int category, LocalDate today);
@Query("select Count(c) from Clothe c where c.category = :category and c.lastDate = :today and c.member = :member")
int getCountOneCategoryPerOnDay(int category, LocalDate today, Member member);

List<Clothe> findAllByCategoryAndSeasonAndMember(Integer category, Integer season, Member member);

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/umc/refit/web/service/ClotheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public List<GetClotheListResponseDto> showClotheMain(Integer category, Integer s
} else if (isNegative1) {
return c2.getLastDate() != null ? c2.getLastDate().compareTo(c1.getLastDate()) : 1;
} else if (isNegative2) {

return c1.getLastDate() != null ? c2.getLastDate().compareTo(c1.getLastDate()) : -1;
} else if (isPositive1) {

return c2.getCompletedDate() != null ? c2.getCompletedDate().compareTo(c1.getCompletedDate()) : 1;
} else {
return c2.getCompletedDate() != null ? c2.getCompletedDate().compareTo(c1.getCompletedDate()) : -1;
Expand All @@ -107,7 +107,7 @@ public List<GetClotheListResponseDto> showClotheMain(Integer category, Integer s
.collect(Collectors.toList());


} else if (sort.equals("most_worn")) {
} else if (sort.equals("most-worn")) {
return this.closetRepository.findAllByCategoryAndSeasonAndMemberOrderByCountDesc(category, season, member)
.stream()
.map(clothe -> clothe.from(this.calculateRemainedDay(clothe)))
Expand Down Expand Up @@ -145,9 +145,10 @@ public void updateClotheGoal(Long id, UpdateClotheGoalRequestDto request) {
}

@Transactional
public void wearClothe(Long id) {
public void wearClothe(Long id, Authentication authentication) {
Clothe clothe = getClothe(id);
if (this.closetRepository.getCountOneCategoryPerOnDay(clothe.getCategory(), LocalDate.now()) >= 2) {
Member member = getMember(authentication);
if (this.closetRepository.getCountOneCategoryPerOnDay(clothe.getCategory(), LocalDate.now(), member) >= 2) {
throw new ClotheException(
ONE_CATEGORY_OVER_TWO_COUNT, ONE_CATEGORY_OVER_TWO_COUNT.getCode(), ONE_CATEGORY_OVER_TWO_COUNT.getErrorMessage());
}
Expand Down
Loading