diff --git a/oversweet-api/src/main/java/com/depromeet/oversweet/drink/dto/response/DrinkDailyDetailInfo.java b/oversweet-api/src/main/java/com/depromeet/oversweet/drink/dto/response/DrinkDailyDetailInfo.java index f7ea9f9..531587e 100644 --- a/oversweet-api/src/main/java/com/depromeet/oversweet/drink/dto/response/DrinkDailyDetailInfo.java +++ b/oversweet-api/src/main/java/com/depromeet/oversweet/drink/dto/response/DrinkDailyDetailInfo.java @@ -21,9 +21,12 @@ public record DrinkDailyDetailInfo( @Schema(description = "음료 칼로리", example = "100") int calorie, - @Schema(description = "음료 당도", example = "10") int sugar + @Schema(description = "음료 당도", example = "10") int sugar, + + @Schema(description = "해당 기록 Id", example = "1") Long recordId + ) { - public static DrinkDailyDetailInfo of(final DrinkEntity drink){ + public static DrinkDailyDetailInfo of(final DrinkEntity drink, final Long recordId){ return new DrinkDailyDetailInfo( drink.getId(), drink.getName(), @@ -31,7 +34,8 @@ public static DrinkDailyDetailInfo of(final DrinkEntity drink){ drink.getImageUrl(), drink.getSize(), drink.getCalorie(), - drink.getSugar() + drink.getSugar(), + recordId ); } } diff --git a/oversweet-api/src/main/java/com/depromeet/oversweet/drink/service/DrinkDailyStatisticsService.java b/oversweet-api/src/main/java/com/depromeet/oversweet/drink/service/DrinkDailyStatisticsService.java index 9081c1b..3d5b5d1 100644 --- a/oversweet-api/src/main/java/com/depromeet/oversweet/drink/service/DrinkDailyStatisticsService.java +++ b/oversweet-api/src/main/java/com/depromeet/oversweet/drink/service/DrinkDailyStatisticsService.java @@ -61,7 +61,7 @@ public DrinkDailySugarStatisticsResponse retrieveUserDailySugarStatistics(final private List getDailyDrinks(final List dailyRecords) { return dailyRecords.stream() - .map(dr -> DrinkDailyDetailInfo.of(dr.getDrink())) + .map(dr -> DrinkDailyDetailInfo.of(dr.getDrink(), dr.getId())) .toList(); } } diff --git a/oversweet-api/src/main/java/com/depromeet/oversweet/record/controller/RecordController.java b/oversweet-api/src/main/java/com/depromeet/oversweet/record/controller/RecordController.java index aad2481..d9509d1 100644 --- a/oversweet-api/src/main/java/com/depromeet/oversweet/record/controller/RecordController.java +++ b/oversweet-api/src/main/java/com/depromeet/oversweet/record/controller/RecordController.java @@ -52,12 +52,12 @@ public ResponseEntity> saveDrinkRecord( @Operation(summary = "마신 음료 삭제", description = "유저가 마신 음료를 삭제할 수 있는 기능입니다.") @ApiResponses(@ApiResponse(responseCode = "200", description = "음료 기록 삭제 성공")) @SecurityRequirement(name = "accessToken") - @DeleteMapping("/drink/{drinkId}") + @DeleteMapping("/{recordId}") public ResponseEntity deleteDrinkRecord( @AuthenticationPrincipal final CustomUserDetails userDetails, - @PathVariable @Parameter(description = "해당 음료의 Id") final Long drinkId + @PathVariable @Parameter(description = "해당 레코드의 Id") final Long recordId ) { - drinkRecordSaveService.deleteDrinkRecord(userDetails.getId(), drinkId); + drinkRecordSaveService.deleteDrinkRecord(userDetails.getId(), recordId); return ResponseEntity.ok().body(MessageResponse.of(HttpStatus.OK, "마신 음료 기록 삭제 성공")); } } diff --git a/oversweet-api/src/main/java/com/depromeet/oversweet/record/service/DrinkRecordSaveService.java b/oversweet-api/src/main/java/com/depromeet/oversweet/record/service/DrinkRecordSaveService.java index fcff4c3..a53aaa4 100644 --- a/oversweet-api/src/main/java/com/depromeet/oversweet/record/service/DrinkRecordSaveService.java +++ b/oversweet-api/src/main/java/com/depromeet/oversweet/record/service/DrinkRecordSaveService.java @@ -11,6 +11,8 @@ import com.depromeet.oversweet.drink.dto.response.DrinkDailySugarTotalStatisticsInfo; import com.depromeet.oversweet.drink.vo.DrinkStatisticsTotalInfo; import com.depromeet.oversweet.drink.vo.LocalDateTimeInfo; +import com.depromeet.oversweet.exception.ErrorCode; +import com.depromeet.oversweet.exception.record.NotFoundRecordException; import com.depromeet.oversweet.record.dto.request.DrinkRecordSaveRequest; import com.depromeet.oversweet.record.dto.response.DrinkRecordSaveResponse; import lombok.RequiredArgsConstructor; @@ -60,13 +62,9 @@ public DrinkRecordSaveResponse saveDrinkRecord(Long memberId, DrinkRecordSaveReq /** * 마신 당 기록 삭제 */ - public void deleteDrinkRecord(final Long memberId, final Long drinkId) { + public void deleteDrinkRecord(final Long memberId, final Long recordId) { - final MemberEntity findMember = findMemberRepository.findMemberById(memberId); - - final DrinkEntity findDrink = findDrinkRepository.findDrinkById(drinkId); - - final RecordEntity findRecord = findRecordsRepository.findRecordByMemberIdAndDrinkId(findMember.getId(), findDrink.getId()); + final RecordEntity findRecord = findRecordsRepository.findRecordByIdAndMemberId(memberId, recordId); deleteRecordRepository.deleteById(findRecord.getId()); } diff --git a/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepository.java b/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepository.java index ae77c8b..f638f07 100644 --- a/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepository.java +++ b/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepository.java @@ -17,5 +17,5 @@ public interface FindRecordsRepository { List findPopularDrinkRecordsByFranchiseId(Long franchiseId, LocalDateTime startDate, LocalDateTime endDate); - RecordEntity findRecordByMemberIdAndDrinkId(Long memberId, Long drinkId); + RecordEntity findRecordByIdAndMemberId(Long memberId, Long recordId); } diff --git a/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepositoryImpl.java b/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepositoryImpl.java index adaef42..1a61ede 100644 --- a/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepositoryImpl.java +++ b/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/FindRecordsRepositoryImpl.java @@ -88,9 +88,8 @@ public List findPopularDrinkRecordsByFranchiseId(Long franchiseId, } @Override - @Transactional - public RecordEntity findRecordByMemberIdAndDrinkId(final Long memberId, final Long drinkId) { - return recordJpaRepository.findByMemberIdAndDrinkId(memberId, drinkId) + public RecordEntity findRecordByIdAndMemberId(final Long memberId, final Long recordId) { + return recordJpaRepository.findByIdAndMemberId(recordId, memberId) .orElseThrow(() -> new NotFoundRecordException(ErrorCode.NOT_FOUND_RECORD)); } } diff --git a/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/RecordJpaRepository.java b/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/RecordJpaRepository.java index 6256cb0..00c3358 100644 --- a/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/RecordJpaRepository.java +++ b/oversweet-domain/src/main/java/com/depromeet/oversweet/domain/record/repository/RecordJpaRepository.java @@ -26,5 +26,5 @@ List findTop3PopularDrinksByFranchiseIdAndBetweenDates( @Param("endDate") LocalDateTime endDate, Pageable pageable); - Optional findByMemberIdAndDrinkId(Long memberId, Long drinkId); + Optional findByIdAndMemberId(Long id, Long memberId); }