Skip to content

Commit

Permalink
Merge pull request #46 음식 내역 삭제 api
Browse files Browse the repository at this point in the history
음식 내역 삭제 api
  • Loading branch information
SangminHann authored Jun 26, 2024
2 parents c9a0df9 + 8f00041 commit ae9f13c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public ResponseDto<?> update(@UserId Long userId,@RequestBody @Valid HistoryRequ
return ResponseDto.ok(historyService.update(userId, historyRequestDto));
}

@DeleteMapping("/{historyId}")
public ResponseDto<?> delete(@UserId Long userId, @PathVariable("historyId") Long historyId) {
return ResponseDto.ok(historyService.deleteHistory(userId, historyId));
}

}
9 changes: 8 additions & 1 deletion src/main/java/com/example/habit/service/HistoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public Boolean update(Long userId, HistoryRequestDto historyRequestDto) {
history.update(historyRequestDto);
historyRepository.save(history);


return Boolean.TRUE;
}

Expand All @@ -131,5 +130,13 @@ public HistoryDto get(Long userId, Long historyId) {
return HistoryDto.fromEntity(history);
}

@Transactional
public Boolean deleteHistory(Long userId, Long historyId) {
User user = userRepository.findById(userId).orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_USER));
History history = historyRepository.findById(historyId).orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_HISTORY));
historyRepository.delete(history);

return Boolean.TRUE;
}

}

0 comments on commit ae9f13c

Please sign in to comment.