Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] 운동 종료 필수 요청 파라미터 변경 #28

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/whyranoid/walkie/domain/Agreement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/whyranoid/walkie/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 2 additions & 7 deletions src/main/java/com/whyranoid/walkie/domain/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions src/main/java/com/whyranoid/walkie/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Walkie> liker = new ArrayList<>();

// @OneToOne(optional = false) // optional = false 안해주면 history가 겹치는 경우가 발생 시 에러
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/whyranoid/walkie/domain/Walkie.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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