diff --git a/src/main/java/com/whyranoid/walkie/controller/CommunityController.java b/src/main/java/com/whyranoid/walkie/controller/CommunityController.java index b9d176f..597528b 100644 --- a/src/main/java/com/whyranoid/walkie/controller/CommunityController.java +++ b/src/main/java/com/whyranoid/walkie/controller/CommunityController.java @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -39,9 +40,9 @@ public class CommunityController { @Parameter(name = "colorMode", description = "글자색 카테고리(0은 검정, 1은 흰색)", example = "1"), @Parameter(name = "historyContent", description = "운동기록 정보", example = "7.51km 01:03:45 08'29\"") }) - @PostMapping(value = "/upload-post") + @PostMapping(value = "/upload-post", consumes = {"multipart/form-data"}) public ResponseEntity uploadPost( - @RequestParam("image")MultipartFile image, + @RequestPart(value = "image", required = false) MultipartFile image, @RequestParam("walkieId")Long walkieId, @RequestParam("content")String content, @RequestParam("colorMode")Integer colorMode, diff --git a/src/main/java/com/whyranoid/walkie/domain/Agreement.java b/src/main/java/com/whyranoid/walkie/domain/Agreement.java index b26f19e..90ff64c 100644 --- a/src/main/java/com/whyranoid/walkie/domain/Agreement.java +++ b/src/main/java/com/whyranoid/walkie/domain/Agreement.java @@ -24,7 +24,7 @@ public class Agreement { private Long agreementId; @OneToOne - @JoinColumn(name = "user_id", nullable = false) + @JoinColumn(name = "walkie_id", nullable = false) private Walkie user; @Column(name = "gps_service", nullable = false) diff --git a/src/main/java/com/whyranoid/walkie/domain/BadgeCollection.java b/src/main/java/com/whyranoid/walkie/domain/BadgeCollection.java index 1ac0855..1e67657 100644 --- a/src/main/java/com/whyranoid/walkie/domain/BadgeCollection.java +++ b/src/main/java/com/whyranoid/walkie/domain/BadgeCollection.java @@ -21,7 +21,7 @@ public class BadgeCollection { private Long collectionId; @NotNull - @Column(name = "user_id", nullable = false) + @Column(name = "walkie_id", nullable = false) private Long walkieId; @NotNull diff --git a/src/main/java/com/whyranoid/walkie/domain/ChallengeStatus.java b/src/main/java/com/whyranoid/walkie/domain/ChallengeStatus.java index 87831e8..50c2d74 100644 --- a/src/main/java/com/whyranoid/walkie/domain/ChallengeStatus.java +++ b/src/main/java/com/whyranoid/walkie/domain/ChallengeStatus.java @@ -18,7 +18,7 @@ public class ChallengeStatus { private Long statusId; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id", nullable = false) + @JoinColumn(name = "walkie_id", nullable = false) private Walkie walkie; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/com/whyranoid/walkie/domain/Comment.java b/src/main/java/com/whyranoid/walkie/domain/Comment.java index 7cb774b..04d5b16 100644 --- a/src/main/java/com/whyranoid/walkie/domain/Comment.java +++ b/src/main/java/com/whyranoid/walkie/domain/Comment.java @@ -30,6 +30,6 @@ public class Comment { private Post post; @ManyToOne - @JoinColumn(name = "user_id", nullable = false) + @JoinColumn(name = "walkie_id", nullable = false) private Walkie user; } diff --git a/src/main/java/com/whyranoid/walkie/domain/History.java b/src/main/java/com/whyranoid/walkie/domain/History.java index 41a7dc2..1f00c96 100644 --- a/src/main/java/com/whyranoid/walkie/domain/History.java +++ b/src/main/java/com/whyranoid/walkie/domain/History.java @@ -20,20 +20,15 @@ public class History { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long historyId; - @NotNull - @Column(nullable = false) private Double distance; - @NotNull - @Column(nullable = false) private String date; @NotNull @Column(name = "start_time", nullable = false) private String startTime; - @NotNull - @Column(name = "end_time", nullable = false) + @Column(name = "end_time") private String endTime; @Column(name = "total_time") @@ -44,6 +39,6 @@ public class History { private Integer step; @ManyToOne - @JoinColumn(name = "user_id", nullable = false) + @JoinColumn(name = "walkie_id", nullable = false) private Walkie user; } diff --git a/src/main/java/com/whyranoid/walkie/domain/Post.java b/src/main/java/com/whyranoid/walkie/domain/Post.java index 24cfadb..f78565c 100644 --- a/src/main/java/com/whyranoid/walkie/domain/Post.java +++ b/src/main/java/com/whyranoid/walkie/domain/Post.java @@ -42,13 +42,13 @@ public class Post { private String historyContent; @ManyToOne - @JoinColumn(name = "user_id", nullable = false) // referencedColumnName는 디폴트가 pk + @JoinColumn(name = "walkie_id", nullable = false) // referencedColumnName는 디폴트가 pk private Walkie user; @ManyToMany @JoinTable(name = "walkie_post_like", joinColumns = @JoinColumn(name = "post_id", nullable = false), - inverseJoinColumns = @JoinColumn(name = "user_id", nullable = false)) + inverseJoinColumns = @JoinColumn(name = "walkie_id", nullable = false)) private List liker = new ArrayList<>(); // @OneToOne(optional = false) // optional = false 안해주면 history가 겹치는 경우가 발생 시 에러 diff --git a/src/main/java/com/whyranoid/walkie/domain/Walkie.java b/src/main/java/com/whyranoid/walkie/domain/Walkie.java index d9ab31c..77d0d59 100644 --- a/src/main/java/com/whyranoid/walkie/domain/Walkie.java +++ b/src/main/java/com/whyranoid/walkie/domain/Walkie.java @@ -13,7 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) // 파라미터가 없는 기본 생성자 생성 public class Walkie { @Id // Entity의 primary key임을 명시 - @Column(name = "user_id") + @Column(name = "walkie_id") @Schema(example = "123") @GeneratedValue(strategy = GenerationType.IDENTITY) // 기본 키 생성을 데이터베이스에 위임, mysql의 경우 auto-increment가 기본 private Long userId; diff --git a/src/main/java/com/whyranoid/walkie/dto/HistoryDto.java b/src/main/java/com/whyranoid/walkie/dto/HistoryDto.java index d38c77f..600995a 100644 --- a/src/main/java/com/whyranoid/walkie/dto/HistoryDto.java +++ b/src/main/java/com/whyranoid/walkie/dto/HistoryDto.java @@ -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 diff --git a/src/main/java/com/whyranoid/walkie/repository/querydsl/WalkingLikeRepositoryImpl.java b/src/main/java/com/whyranoid/walkie/repository/querydsl/WalkingLikeRepositoryImpl.java index 1d1be60..5d46866 100644 --- a/src/main/java/com/whyranoid/walkie/repository/querydsl/WalkingLikeRepositoryImpl.java +++ b/src/main/java/com/whyranoid/walkie/repository/querydsl/WalkingLikeRepositoryImpl.java @@ -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; } diff --git a/src/main/java/com/whyranoid/walkie/service/WalkingService.java b/src/main/java/com/whyranoid/walkie/service/WalkingService.java index 0c2a581..1800bd3 100644 --- a/src/main/java/com/whyranoid/walkie/service/WalkingService.java +++ b/src/main/java/com/whyranoid/walkie/service/WalkingService.java @@ -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); @@ -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);