Skip to content

Commit

Permalink
HotFix: 일일 통계에서도 recordId 추가 및 삭제 시 recordId로 삭제 하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJejune committed Jul 19, 2023
1 parent ab3dc8d commit 48cf134
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ 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(),
FranchiseInfo.of(drink.getFranchise()),
drink.getImageUrl(),
drink.getSize(),
drink.getCalorie(),
drink.getSugar()
drink.getSugar(),
recordId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public DrinkDailySugarStatisticsResponse retrieveUserDailySugarStatistics(final

private List<DrinkDailyDetailInfo> getDailyDrinks(final List<RecordEntity> dailyRecords) {
return dailyRecords.stream()
.map(dr -> DrinkDailyDetailInfo.of(dr.getDrink()))
.map(dr -> DrinkDailyDetailInfo.of(dr.getDrink(), dr.getId()))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public ResponseEntity<DataResponse<DrinkRecordSaveResponse>> saveDrinkRecord(
@Operation(summary = "마신 음료 삭제", description = "유저가 마신 음료를 삭제할 수 있는 기능입니다.")
@ApiResponses(@ApiResponse(responseCode = "200", description = "음료 기록 삭제 성공"))
@SecurityRequirement(name = "accessToken")
@DeleteMapping("/drink/{drinkId}")
@DeleteMapping("/{recordId}")
public ResponseEntity<MessageResponse> 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, "마신 음료 기록 삭제 성공"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public interface FindRecordsRepository {

List<RankingDrink> findPopularDrinkRecordsByFranchiseId(Long franchiseId, LocalDateTime startDate, LocalDateTime endDate);

RecordEntity findRecordByMemberIdAndDrinkId(Long memberId, Long drinkId);
RecordEntity findRecordByIdAndMemberId(Long memberId, Long recordId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ public List<RankingDrink> 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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ List<RankingDrink> findTop3PopularDrinksByFranchiseIdAndBetweenDates(
@Param("endDate") LocalDateTime endDate,
Pageable pageable);

Optional<RecordEntity> findByMemberIdAndDrinkId(Long memberId, Long drinkId);
Optional<RecordEntity> findByIdAndMemberId(Long id, Long memberId);
}

0 comments on commit 48cf134

Please sign in to comment.