Skip to content

Commit

Permalink
Merge pull request #21 from Team-Walkie/mvc/seungmin
Browse files Browse the repository at this point in the history
community upload api 구현
  • Loading branch information
peter-j0y authored Aug 29, 2023
2 parents 4f0d1dd + a8acdac commit 599ea64
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 76 deletions.
17 changes: 12 additions & 5 deletions src/main/java/com/whyranoid/walkie/controller/BadgeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@ public class BadgeController {

@Operation(summary = "유저 아이디로 배지 가져오기", description = "유저 아이디를 통해 배지를 해당 유저가 획득한 배지들을 조회합니다.")
@Parameters({
@Parameter(name = "userId", description = "유저 아이디", example = "123")
@Parameter(name = "walkieId", description = "유저 아이디", example = "123")
})
@ApiResponse(responseCode = "200", description = "호출 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BadgeDto.class))))
@GetMapping("/badges")
public ResponseEntity getBadges(@RequestParam("userId") Long userId) {
List<BadgeDto> badges = badgeService.getBadges(userId);
public ResponseEntity getBadges(@RequestParam("walkieId") Long walkieId) {
List<BadgeDto> badges = badgeService.getBadges(walkieId);
return new ResponseEntity<>(badges, httpHeaders, HttpStatus.OK);
}

@Operation(summary = "배지 획득하기", description = "챌린지 조건에 만족할 때 해당 api를 호출하면 유저가 배지를 획득합니다.")
@Parameters({
@Parameter(name = "walkieId", description = "유저 아이디", example = "123"),
@Parameter(name = "badgeId", description = "배지 아이디", example = "3")
})
@ApiResponse(responseCode = "200", description = "호출 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = com.whyranoid.walkie.dto.response.ApiResponse.class))))

@PostMapping("/obtain-badge")
public ResponseEntity obtainBadge(@RequestParam("userId") Long userId, @RequestParam("badgeId") Long badgeId) {
return ResponseEntity.ok(badgeService.obtainBadge(userId, badgeId));
public ResponseEntity obtainBadge(@RequestParam("walkieId") Long walkieId, @RequestParam("badgeId") Long badgeId) {
return ResponseEntity.ok(badgeService.obtainBadge(walkieId, badgeId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class ChallengeController {

@Operation(summary = "새로운 챌린지 가져오기", description = "새로운 챌린지들을 가져옵니다.")
@Parameters({
@Parameter(name = "userId", description = "유저 아이디", example = "123")
@Parameter(name = "walkieId", description = "유저 아이디", example = "123")
})
@ApiResponse(responseCode = "200", description = "호출 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ChallengePreviewDto.class))))
@GetMapping("/challenges/new")
public ResponseEntity getNewChallenges(@RequestParam("userId") Long userId) {
List<ChallengePreviewDto> challenges = challengeService.getNewChallenges(userId);
public ResponseEntity getNewChallenges(@RequestParam("walkieId") Long walkieId) {
List<ChallengePreviewDto> challenges = challengeService.getNewChallenges(walkieId);
return new ResponseEntity<>(challenges, httpHeaders, HttpStatus.OK);
}

Expand All @@ -51,35 +51,35 @@ public ResponseEntity getPopularChallenges() {
@Operation(summary = "카테고리별 챌린지 가져오기", description = "카테고리를 넣어주면 해당 카테고리의 챌린지들을 반환합니다.")
@ApiResponse(responseCode = "200", description = "호출 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ChallengePreviewDto.class))))
@Parameters({
@Parameter(name = "userId", description = "유저 아이디", example = "123"),
@Parameter(name = "walkieId", description = "유저 아이디", example = "123"),
@Parameter(name = "category", description = "카테고리(L은 라이프, C는 칼로리, D는 거리)", example = "C")
})
@GetMapping("/challenges/category")
public ResponseEntity getChallengesByCategory(@RequestParam("userId") Long userId, @RequestParam("category") char category) {
List<ChallengePreviewDto> challenges = challengeService.getChallengesByCategory(userId, category);
public ResponseEntity getChallengesByCategory(@RequestParam("walkieId") Long walkieId, @RequestParam("category") char category) {
List<ChallengePreviewDto> challenges = challengeService.getChallengesByCategory(walkieId, category);
return new ResponseEntity<>(challenges, httpHeaders, HttpStatus.OK);
}

@Operation(summary = "진행중인 챌린지 가져오기", description = "현재 유저가 진행 중인 챌린지들을 반환합니다.")
@ApiResponse(responseCode = "200", description = "호출 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ChallengePreviewDto.class))))
@Parameters({
@Parameter(name = "userId", description = "유저 아이디", example = "123")
@Parameter(name = "walkieId", description = "유저 아이디", example = "123")
})
@GetMapping("/challenges/progress")
public ResponseEntity getProgressChallenge(@RequestParam("userId") Long userId) {
List<ChallengePreviewDto> progressChallenges = challengeService.getProgressChallenges(userId);
public ResponseEntity getProgressChallenge(@RequestParam("walkieId") Long walkieId) {
List<ChallengePreviewDto> progressChallenges = challengeService.getProgressChallenges(walkieId);
return new ResponseEntity<>(progressChallenges, httpHeaders, HttpStatus.OK);
}

@Operation(summary = "챌린지 상세 정보 보기", description = "챌린지의 상세한 정보를 반환합니다.")
@Parameters({
@Parameter(name = "challengeId", description = "챌린지 아이디", example = "2"),
@Parameter(name = "userId", description = "유저 아이디", example = "123")
@Parameter(name = "walkieId", description = "유저 아이디", example = "123")
})
@ApiResponse(responseCode = "200", description = "호출 성공", content = @Content(schema = @Schema(implementation = ChallengeDetailDto.class)))
@GetMapping("/challenge-detail")
public ResponseEntity getChallengeDetail(@RequestParam("challengeId") Long challengeId, @RequestParam("userId") Long userId) {
ChallengeDetailDto challenge = challengeService.getChallengeDetail(challengeId, userId);
public ResponseEntity getChallengeDetail(@RequestParam("challengeId") Long challengeId, @RequestParam("walkieId") Long walkieId) {
ChallengeDetailDto challenge = challengeService.getChallengeDetail(challengeId, walkieId);
return new ResponseEntity<>(challenge, httpHeaders, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.whyranoid.walkie.controller;

import com.whyranoid.walkie.dto.request.PostRequest;
import com.whyranoid.walkie.service.CommunityService;
import io.swagger.v3.oas.annotations.Operation;
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.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.RestController;

@Tag(name = "community", description = "커뮤니티 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/community")
public class CommunityController {
HttpHeaders httpHeaders = new HttpHeaders();

private final CommunityService communityService;
@Operation(summary = "게시글 올리기", description = "커뮤니티에 게시글을 업로드합니다.")
@ApiResponse(responseCode = "200", description = "업로드 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = com.whyranoid.walkie.dto.response.ApiResponse.class))))
@PostMapping("/upload-post")
public ResponseEntity uploadPost(
@RequestBody PostRequest postRequest
) {
return ResponseEntity.ok(communityService.uploadPost(postRequest));
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.whyranoid.walkie.controller;

import com.whyranoid.walkie.service.WalkieService;
import com.whyranoid.walkie.dto.request.MyInfoRequest;
import com.whyranoid.walkie.dto.request.WalkieSignUpRequest;
import com.whyranoid.walkie.dto.response.MyInfoResponse;
import com.whyranoid.walkie.dto.response.WalkieSignUpResponse;
import com.whyranoid.walkie.service.WalkieService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
Expand Down Expand Up @@ -39,4 +41,26 @@ public ResponseEntity<WalkieSignUpResponse> check(@RequestParam String userName)
.build()
);
}

@Operation(description = "마이페이지에서 내 정보를 불러오는 api")
@Parameters({
@Parameter(name = "walkieId", required = true, description = "내 walkieId", example = "123")
})
@GetMapping("/my")
public ResponseEntity<MyInfoResponse> getMyInfo(@RequestParam Long walkieId) {
return ResponseEntity.ok(
walkieService.getMyInfo(walkieId)
);
}

@Operation(description = "마이페이지에서 내 정보를 수정하는 api")
@Parameters({
@Parameter(name = "walkieId", required = true, description = "내 walkieId", example = "123")
})
@PostMapping("/my")
public ResponseEntity<MyInfoResponse> changeMyInfo(@RequestParam Long walkieId, @RequestBody MyInfoRequest myInfoRequest) {
return ResponseEntity.ok(
walkieService.changeMyInfo(walkieId, myInfoRequest)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BadgeCollection {

@NotNull
@Column(name = "user_id", nullable = false)
private Long userId;
private Long walkieId;

@NotNull
@Column(name = "badge_id", nullable = false)
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/whyranoid/walkie/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Post {
Expand All @@ -30,7 +31,7 @@ public class Post {

@NotNull
@Column(name = "date", nullable = false)
private Date date;
private String date;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false) // referencedColumnName는 디폴트가 pk
Expand All @@ -42,7 +43,7 @@ public class Post {
inverseJoinColumns = @JoinColumn(name = "user_id", nullable = false))
private List<Walkie> liker = new ArrayList<>();

@OneToOne(optional = false) // optional = false 안해주면 history가 겹치는 경우가 발생 시 에러
@JoinColumn(name = "history", nullable = false)
private History history;
// @OneToOne(optional = false) // optional = false 안해주면 history가 겹치는 경우가 발생 시 에러
// @JoinColumn(name = "history", nullable = false)
// private History history;
}
14 changes: 3 additions & 11 deletions src/main/java/com/whyranoid/walkie/domain/Walkie.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package com.whyranoid.walkie.domain;

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter // 클래스 레벨에 선언할 경우 모든 필드에 접근자 자동 생성
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED) // 파라미터가 없는 기본 생성자 생성
public class Walkie {
@Id // Entity의 primary key임을 명시
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
public class ChallengeStatusCreateRequest {
@NotNull
@Schema(example = "123")
private Long userId;
private Long walkieId;

@NotNull
@Schema(example = "4")
private Long challengeId;

@Builder
public ChallengeStatusCreateRequest(Long userId, Long challengeId) {
this.userId = userId;
public ChallengeStatusCreateRequest(Long walkieId, Long challengeId) {
this.walkieId = walkieId;
this.challengeId = challengeId;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/whyranoid/walkie/dto/request/MyInfoRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.whyranoid.walkie.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Setter
public class MyInfoRequest {
@Schema(description = "변경하고자 하는 프로필 이미지")
private String profileImg;

@Schema(description = "변경하고자 하는 닉네임")
private String nickname;

@Builder
MyInfoRequest(String profileImg, String nickname) {
this.profileImg = profileImg;
this.nickname = nickname;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/whyranoid/walkie/dto/request/PostRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.whyranoid.walkie.dto.request;

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

import javax.validation.constraints.NotNull;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class PostRequest {
@NotNull
@Schema(example = "123")
private Long walkieId;

@NotNull
@Schema(example = "업로드할 사진 이미지 url")
private String photo;

@NotNull
@Schema(example = "오늘 진짜 많이 걸었다~~")
private String content;

@Builder
public PostRequest(Long walkieId, String photo, String content) {
this.walkieId = walkieId;
this.photo = photo;
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.whyranoid.walkie.dto.response;

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

@Getter
@Builder
public class MyInfoResponse {
@Schema(description = "나의 프로필 이미지")
private String profileImg;

@Schema(description = "나의 닉네임")
private String nickname;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class BadgeRepository {
@PersistenceContext
private final EntityManager em;

public List<BadgeDto> getBadges(Long userId) {
return em.createQuery("select new com.whyranoid.walkie.dto.response.BadgeDto(b.badgeId, b.img, b.badgeName, bc.receivedAt) from BadgeCollection bc left join Badge b on bc.badgeId = b.badgeId where bc.userId = :userId")
.setParameter("userId", userId)
public List<BadgeDto> getBadges(Long walkieId) {
return em.createQuery("select new com.whyranoid.walkie.dto.response.BadgeDto(b.badgeId, b.img, b.badgeName, bc.receivedAt) from BadgeCollection bc left join Badge b on bc.badgeId = b.badgeId where bc.userId = :walkieId")
.setParameter("walkieId", walkieId)
.getResultList();
}

Expand Down
Loading

0 comments on commit 599ea64

Please sign in to comment.