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] 러닝종료, 게시글 좋아요 #26

Merged
merged 4 commits into from
Sep 14, 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
@@ -1,6 +1,7 @@
package com.whyranoid.walkie.controller;

import com.google.firebase.auth.FirebaseAuthException;
import com.whyranoid.walkie.dto.PostLikeDto;
import com.whyranoid.walkie.service.CommunityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -13,6 +14,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
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.RestController;
Expand Down Expand Up @@ -47,4 +49,13 @@ public ResponseEntity uploadPost(
) throws IOException, FirebaseAuthException {
return ResponseEntity.ok(communityService.uploadPost(image, walkieId, content, colorMode, historyContent));
}

@Operation(summary = "게시글에 좋아요 누르기")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = PostLikeDto.class)),
description = "성공 시 요청에 게시글의 현재 좋아요 수를 넣어 반환, 중복 좋아요 시 좋아요 수에 -1을 넣어 반환, 실패 시 예외발생")
@PostMapping("/send-like")
public ResponseEntity<PostLikeDto> sendPostLike(@RequestBody PostLikeDto postLikeDto) {
return ResponseEntity.ok(communityService.sendPostLike(postLikeDto));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.whyranoid.walkie.service.FollowService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -26,34 +30,44 @@ public class FollowController {

private final FollowService followService;

@Operation(description = "팔로우하기")
@Operation(summary = "팔로우하기")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = FollowDto.class)),
description = "성공 시 요청한 정보를 그대로 리턴")
@PostMapping("/follow")
public ResponseEntity<FollowDto> follow(@RequestBody FollowDto followRequest) {
return ResponseEntity.ok(followService.doFollow(followRequest));
}

@Operation(description = "언팔로우하기")
@Operation(summary = "언팔로우하기")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = FollowDto.class)),
description = "성공 시 요청 정보에 unfollow = follow를 추가해 리턴")
@DeleteMapping("/unfollow")
public ResponseEntity<FollowDto> unfollow(@RequestBody FollowDto followRequest) {
return ResponseEntity.ok(followService.doUnfollow(followRequest));
}

@Operation(description = "내가 팔로우하는 사람 리스트 가져오기")
@Operation(summary = "내가 팔로우하는 사람 리스트 가져오기")
@Parameter(name = "워키 아이디", required = true, description = "팔로잉 리스트를 가져올 유저의 id", example = "3")
@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = WalkieDto.class))),
description = "성공 시 id가 팔로우하는 유저 정보의 리스트를 반환")
@GetMapping("/{walkie}/following")
public ResponseEntity<List<WalkieDto>> getFollowingList(@PathVariable("walkie") Long walkieId) {
return ResponseEntity.ok(followService.getFollowingList(walkieId));
}

@Operation(description = "나를 팔로우하는 사람 리스트 가져오기")
@Operation(summary = "나를 팔로우하는 사람 리스트 가져오기")
@Parameter(name = "워키 아이디", required = true, description = "팔로워 리스트를 가져올 유저의 id", example = "3")
@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = WalkieDto.class))),
description = "성공 시 id를 팔로우하는 유저 정보의 리스트를 반환")
@GetMapping("/{walkie}/follower")
public ResponseEntity<List<WalkieDto>> getFollowerList(@PathVariable("walkie") Long walkieId) {
return ResponseEntity.ok(followService.getFollowerList(walkieId));
}

@Operation(description = "운동 중인 친구 목록 조회")
@Operation(summary = "운동 중인 친구 목록 조회")
@Parameter(name = "워키 아이디", required = true, description = "운동 중인 친구 목록을 가져올 유저의 id", example = "3")
@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = WalkieDto.class))),
description = "성공 시 id가 팔로우 하고 운동 중인 유저 정보의 리스트를 반환")
@GetMapping("/{walkie}/walking-followings")
public ResponseEntity<List<WalkieDto>> getWalkingFollowingList(@PathVariable("walkie") Long walkieId) {
return ResponseEntity.ok(followService.getWalkingFollowingList(walkieId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.RestController;

@Tag(name = "WalkieController")
@RequiredArgsConstructor
Expand All @@ -21,16 +29,18 @@ public class WalkieController {

private final WalkieService walkieService;

@Operation(description = "소셜 로그인 이후 워키 회원가입 요청")
@Operation(summary = "회원가입", description = "소셜 로그인 이후 워키 회원가입 요청")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WalkieSignUpResponse.class)),
description = "성공 시 요청한 아이디, 닉네임과 hasDuplicated=false를, 닉네임 중복 시 hasDuplicated=true를 반환")
@PostMapping("/signup")
public ResponseEntity<WalkieSignUpResponse> signUp(@RequestBody WalkieSignUpRequest walkieSignUpRequest) {
return ResponseEntity.ok(walkieService.joinWalkie(walkieSignUpRequest));
}

@Operation(description = "닉네임 중복 확인 -- 회원가입과 동일한 dto 사용")
@Parameters({
@Parameter(name = "userName", required = true, description = "닉네임", example = "군자동 불주먹")
})
@Operation(summary = "닉네임 중복 확인", description = "회원가입과 동일한 dto를 응답으로 사용")
@Parameter(name = "userName", required = true, description = "닉네임", example = "군자동 불주먹")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WalkieSignUpResponse.class)),
description = "통과 시 false, 중복 시 true를 반환")
@GetMapping("/signup/check")
public ResponseEntity<WalkieSignUpResponse> check(@RequestParam String userName) {
return ResponseEntity.ok(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.whyranoid.walkie.controller;

import com.whyranoid.walkie.dto.HistoryDto;
import com.whyranoid.walkie.dto.WalkingDto;
import com.whyranoid.walkie.dto.WalkingLikeDto;
import com.whyranoid.walkie.dto.response.WalkieSignUpResponse;
import com.whyranoid.walkie.service.WalkingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,28 +27,41 @@ public class WalkingController {

private final WalkingService walkingService;

@Operation(description = "운동 시작 정보 저장")
@Operation(summary = "운동 시작 정보 저장")
@ApiResponse(responseCode = "200", description = "OK -- 생성된 히스토리 아이디 반환")
@PostMapping("/start")
@ApiResponse(responseCode = "200", description = "OK -- 생성된 히스토리 아이디")
public ResponseEntity<Long> startWalking(@RequestBody WalkingDto walkingDto) {
return ResponseEntity.ok(walkingService.startWalking(walkingDto));
}

@Operation(description = "운동 중인 친구에게 좋아요 보내기")
@Operation(summary = "운동 중인 친구에게 좋아요 보내기")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WalkingLikeDto.class)),
description = "성공 시 요청 그대로 반환")
@PostMapping("/send-like")
public ResponseEntity<WalkingLikeDto> sendWalkingLike(@RequestBody WalkingLikeDto walkingLikeDto) {
return ResponseEntity.ok(walkingService.sendWalkingLike(walkingLikeDto));
}

@Operation(description = "운동 중에 받은 좋아요 수 가져오기")
@Operation(summary = "운동 중에 받은 좋아요 수 가져오기")
@ApiResponse(responseCode = "200", description = "성공 시 좋아요 수 리턴, 실패 시 Exception")
@GetMapping("/count-like")
public ResponseEntity<Long> countWalkingLike(@RequestParam Long walkieId, @RequestParam String authId) {
return ResponseEntity.ok(walkingService.countWalkingLike(walkieId, authId));
}

@Operation(description = "운동 종료 시 받은 좋아요 수와 좋아요 누른 사람 프로필 가져오기")
@Operation(summary = "운동 종료 시 받은 좋아요 수와 좋아요 누른 사람 프로필 가져오기")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WalkingLikeDto.class)),
description = "성공 시 운동한 사람의 아이디, 받은 좋아요 수, 좋아요 누른 사람의 유저 정보 리스트를 반환")
@GetMapping("/count-total")
public ResponseEntity<WalkingLikeDto> getTotalWalkingLike(@RequestParam Long walkieId, @RequestParam String authId) {
return ResponseEntity.ok(walkingService.getTotalWalkingLike(walkieId, authId));
}

@Operation(summary = "운동 종료 시 데이터 저장하기")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WalkieSignUpResponse.class)),
description = "저장 성공 시 기록의 DB pk값, 실패 시 -1")
@PostMapping("/save")
public ResponseEntity<Long> saveWalkingHistory(@RequestBody HistoryDto historyDto) {
return ResponseEntity.ok(walkingService.saveWalkingHistory(historyDto));
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/whyranoid/walkie/domain/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public class History {

private Integer step;

private String path;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private Walkie user;
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/whyranoid/walkie/domain/PostLike.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.whyranoid.walkie.domain;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class PostLike {

@Id
@Column(name = "post_like_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long postLikeId;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "liker")
private Walkie liker;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post")
private Post post;

@Builder
public PostLike(Long postLikeId, Walkie liker, Post post) {
this.postLikeId = postLikeId;
this.liker = liker;
this.post = post;
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/whyranoid/walkie/dto/FollowDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
@AllArgsConstructor
public class FollowDto {

@Schema(description = "팔로우 신청 유저 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "24576")
@Schema(description = "[요청 필수] 팔로우 신청 유저 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "24576")
private Long followerId;

@Schema(description = "팔로우 받은 유저 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "1608")
@Schema(description = "[요청 필수] 팔로우 받은 유저 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "1608")
private Long followedId;

@Schema(description = "(검증용) 언팔로우 되었는지 여부", example = "false")
@Schema(description = "(검증용) 언팔로우 시 true 반환", example = "true")
private boolean unfollow;

@QueryProjection
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/whyranoid/walkie/dto/HistoryDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.whyranoid.walkie.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
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")
private String authId;

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

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

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

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

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

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

@Builder
public HistoryDto(Long walkieId, String authId, Long historyId, String date, String endTime, Integer totalTime, Double distance, Integer calorie, Integer step, String path) {
this.walkieId = walkieId;
this.authId = authId;
this.historyId = historyId;
this.endTime = endTime;
this.totalTime = totalTime;
this.distance = distance;
this.calorie = calorie;
this.step = step;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/whyranoid/walkie/dto/PostDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.whyranoid.walkie.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PostDto {

@Schema(description = "[응답] 워키 아이디", example = "3")
private Long viewerId;

@Schema(description = "[응답] 작성자 아이디", example = "2")
private Long posterId;

@Schema(description = "[응답] 게시글 pk", example = "26343")
private Long postId;

@Schema(description = "[응답] 좋아요 여부", example = "true")
private Boolean liked;

@Schema(description = "[응답] 좋아요 개수", example = "36")
private Integer likeCount;

@Schema(description = "[응답] 사진파일 URI", example = "")
private String photo;

@Schema(description = "[응답] 게시글 내용", example = "오운완.")
private String content;

@Schema(description = "[응답] 게시 시각", example = "2023-09-09 09:09:09")
private String date;

@Schema(description = "[응답] 글씨색 설정", example = "0")
private Integer colorMode;

@Schema(description = "[응답] 기록 데이터", example = "")
private String historyContent;
}
Loading