Skip to content

Commit

Permalink
fix: 운동 종료 시 필수 요청 파라미터 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
bngsh committed Oct 4, 2023
1 parent 028cecd commit 35da2eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/whyranoid/walkie/dto/HistoryDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ public class HistoryDto {
@Schema(description = "요청 필수 파라미터 - 워키 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "3")
private Long walkieId;

@Schema(description = "요청 필수 파라미터 - 구글 uid", requiredMode = Schema.RequiredMode.REQUIRED, example = "super-secret-key")
@Schema(description = "요청 필수 파라미터 - 구글 uid", example = "super-secret-key")
private String authId;

@Schema(description = "요청 필수 파라미터 - 히스토리 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "57245")
@Schema(description = "요청 필수 파라미터 - 히스토리 아이디", example = "57245")
private Long historyId;

@Schema(description = "요청 필수 파라미터 - 운동을 끝낸 시각", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023-09-09 09:09:09")
@Schema(description = "요청 필수 파라미터 - 운동을 끝낸 시각", example = "2023-09-09 09:09:09")
private String endTime;

@Schema(description = "요청 필수 파라미터 - 운동한 시간(초)", requiredMode = Schema.RequiredMode.REQUIRED, example = "39431")
@Schema(description = "요청 필수 파라미터 - 운동한 시간(초)", example = "39431")
private Integer totalTime;

@Schema(description = "요청 파라미터 - 운동한 거리(미터)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1842.5")
@Schema(description = "요청 파라미터 - 운동한 거리(미터)", example = "1842.5")
private Double distance;

@Schema(description = "요청 파라미터 - 소비 칼로리", requiredMode = Schema.RequiredMode.REQUIRED, example = "300")
@Schema(description = "요청 파라미터 - 소비 칼로리", example = "300")
private Integer calorie;

@Schema(description = "요청 파라미터 - 걸음 수", requiredMode = Schema.RequiredMode.REQUIRED, example = "3094")
@Schema(description = "요청 파라미터 - 걸음 수", example = "3094")
private Integer step;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,13 @@ public WalkingLikeDto findWalkingLikePeople(Long walkieId) {

@Override
public Long updateCurrentWalkingHistory(HistoryDto historyDto) {
Long updatedHistory = queryFactory.update(history)
.set(history.distance, historyDto.getDistance())
.set(history.endTime, historyDto.getEndTime())
.set(history.totalTime, historyDto.getTotalTime())
.set(history.calorie, historyDto.getCalorie())
.set(history.step, historyDto.getStep())
.where(history.historyId.eq(historyDto.getHistoryId()))
.execute();

Long updatedWalkie = queryFactory.update(walkie)
.set(walkie.status, 'N')
.where(walkie.userId.eq(historyDto.getWalkieId()))
.execute();

if (updatedHistory == 1 && updatedWalkie == 1) return historyDto.getHistoryId();
if (updatedWalkie == 1) return historyDto.getHistoryId();
return -1L;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class WalkingService {

public Long startWalking(WalkingDto walkingDto) {
Walkie user = walkieRepository.findById(walkingDto.getWalkieId()).orElseThrow(EntityNotFoundException::new);
user.changeStatus('o');
user.changeStatus('W');
walkieRepository.save(user);

Walkie walkie = walkieRepository.findById(walkingDto.getWalkieId()).orElseThrow(EntityNotFoundException::new);
Expand Down Expand Up @@ -79,9 +79,7 @@ public WalkingLikeDto getTotalWalkingLike(Long walkieId, String authId) {
}

public Long saveWalkingHistory(HistoryDto historyDto) {
Walkie authWalkie = walkieRepository.findByAuthId(historyDto.getAuthId()).orElseThrow(EntityNotFoundException::new);

if (!authWalkie.getUserId().equals(historyDto.getWalkieId())) throw new InvalidParameterException();
Walkie walkie = walkieRepository.findById(historyDto.getWalkieId()).orElseThrow(EntityNotFoundException::new);

return walkingLikeRepository.updateCurrentWalkingHistory(historyDto);

Expand Down

0 comments on commit 35da2eb

Please sign in to comment.