Skip to content

Commit

Permalink
Main merge
Browse files Browse the repository at this point in the history
* hotfix: Swagger 경로 설정

* Chore: Swagger 환경변수 설정

* Chore: Swagger 환경변수 설정

* Feat: gitignore yml파일추가

* Feat: Swagger 주소 설정

* Hotfix: 스웨거 경로 설정

* Update README.md

* Update README.md

* Feat: 댓글 조회/작성 구현

* Feat: 댓글 작성, 조회 구현

* Fix: 디렉토리 에러 해결

* Fix: 게시글 조회 방식 수정

* Fix: dto 수정

* Fix: 날짜 표기 변경

* Refactor: 가방 API 멤버 관련 수정

* Refactor: #48 - memberId 삭제 및 주석 추가

* Refactor: #48 - 스웨거 어노테이션 추가

* Refactor: #48 - 스웨거 어노테이션 추가

---------

Co-authored-by: tjdgns8439 <[email protected]>
Co-authored-by: Minhyeok Song <[email protected]>
  • Loading branch information
3 people authored Apr 4, 2024
1 parent 241df3e commit bbd0bd2
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 트리피
## 클밋


## MVP 핵심기능소개
Expand Down
35 changes: 28 additions & 7 deletions src/main/java/com/example/tripy/domain/bag/BagController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import com.example.tripy.domain.material.dto.MaterialResponseDto.MaterialListByCountry;
import com.example.tripy.global.common.dto.PageResponseDto;
import com.example.tripy.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -17,6 +21,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "여행 가방 API")
@RequiredArgsConstructor
@RestController
@RequestMapping("/travel-bag")
Expand All @@ -28,7 +33,10 @@ public class BagController {
/**
* [GET] 내 여행 가방 모두 불러오기
*/
@GetMapping("/members/bags/{memberId}")
@Operation(summary = "내 여행 가방 모두 불러오기", description = "여행 가방이 존재하는 목록을 불러옵니다.")
@Parameter(name = "page", description = "내 여행 가방 목록 페이지 번호, query string 입니다.")
@Parameter(name = "size", description = "내 여행 가방 목록 페이지 번호, query string 입니다.")
@GetMapping("/members/bags")
public ApiResponse<PageResponseDto<List<BagListSimpleInfo>>> getBagsList(
@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
return ApiResponse.onSuccess(bagService.getTravelBagExistsList(page, size));
Expand All @@ -37,32 +45,45 @@ public ApiResponse<PageResponseDto<List<BagListSimpleInfo>>> getBagsList(
/**
* [POST] 내 여행 일정 목록에서 해당하는 가방 목록 생성하기
*/
@Operation(summary = "내 여행 일정 목록에서 해당하는 가방 목록 생성하기", description = "여행 일정 목록에서 가방을 생성하기 위해 해당하는 가방 목록을 생성합니다.")
@Parameter(name = "travelPlanId", description = "여행 계획 Id, Path Variable 입니다.")
@PostMapping("/members/bags/{travelPlanId}")
public ApiResponse<String> updateBagExists(
@PathVariable(value = "travelPlanId") Long travelPlanId) {
return ApiResponse.onSuccess(bagService.updateBagExists(travelPlanId));
}

/**
* [GET] 여행지별 준비물 불러오기
*/
@Operation(summary = "여행지별 준비물 불러오기", description = "나라별 존재하는 추천 준비물을 불러옵니다.")
@Parameter(name = "countryName", description = "나라 이름, query string 입니다.")
@GetMapping("/material-name")
public ApiResponse<MaterialListByCountry> getCountryMaterials(
@RequestParam(value = "countryName") String countryName) {
return ApiResponse.onSuccess(countryMaterialService.getCountryMaterials(countryName));
}

/**
* [POST] 여행 일정에 해당하는 개별 가방 생성(추가)하기
*/
@Operation(summary = "여행 일정에 해당하는 개별 가방 생성(추가)하기", description = "여행 일정에 해당하는 캐리어, 크로스백과 같은 가방을 생성합니다.")
@Parameter(name = "travelPlanId", description = "여행 계획 Id, query string 입니다.")
@PostMapping("/members/bags")
public ApiResponse<String> createBag(@RequestBody CreateBagRequest createBagRequest,
@RequestParam Long travelPlanId) {
return ApiResponse.onSuccess(bagService.addBag(createBagRequest, travelPlanId));
}
}

/**
* [GET] 여행 가방 리스트와 가방 내 준비물 불러오기
*/
@GetMapping("/members/{memberId}/materials/{travelPlanId}")
@Operation(summary = "내 여행 가방 리스트와 가방 내 준비물 불러오기", description = "여행 가방 리스트와 그 가방에 존재하는 준비물을 불러오고, isChecked로 챙겼는지 확인합니다.")
@Parameter(name = "travelPlanId", description = "여행 계획 Id, Path Variable 입니다.")
@GetMapping("/members/materials/{travelPlanId}")
public ApiResponse<List<BagListWithMaterialInfo>> getBagsListAndMaterialsByTravelPlan(
@PathVariable Long memberId, @PathVariable(value = "travelPlanId") Long travelPlanId) {
return ApiResponse.onSuccess(
bagService.getBagsListAndMaterialsByTravelPlan(memberId, travelPlanId));
}
@PathVariable(value = "travelPlanId") Long travelPlanId) {
return ApiResponse.onSuccess(bagService.getBagsListAndMaterialsByTravelPlan(travelPlanId));
}

}
13 changes: 8 additions & 5 deletions src/main/java/com/example/tripy/domain/bag/BagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ public List<BagListSimpleInfo> setBagListSimpleInfo(List<TravelPlan> travelPlans
// 내 일정에 맞는 가방 목록 모두 불러오기
public PageResponseDto<List<BagListSimpleInfo>> getTravelBagExistsList(int page, int size) {

// Member 관련 메서드가 추가되면 수정 예정
Member member = memberRepository.findById(1L)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_MEMBER));

Pageable pageable = PageRequest.of(page, size);
Page<TravelPlan> result = travelPlanRepository.findAllByMemberIdAndBagExistsIsTrue(1L,
Page<TravelPlan> result = travelPlanRepository.findAllByMemberAndBagExistsIsTrue(member,
pageable);

return new PageResponseDto<>(result.getNumber(), result.getTotalPages(),
Expand Down Expand Up @@ -100,12 +104,11 @@ public String addBag(CreateBagRequest createBagRequest, Long travelPlanId) {
bagRepository.save(bag);

return "가방 추가 완료";
}
}

public List<BagListWithMaterialInfo> getBagsListAndMaterialsByTravelPlan(Long memberId,
Long travelPlanId) {
public List<BagListWithMaterialInfo> getBagsListAndMaterialsByTravelPlan(Long travelPlanId) {
//Member 관련 메서드가 추가되면 수정 예정
Member member = memberRepository.findById(memberId)
Member member = memberRepository.findById(1L)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_MEMBER));

TravelPlan travelPlan = travelPlanRepository.findByMemberAndIdAndBagExistsIsTrue(member,
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/example/tripy/domain/comment/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.tripy.domain.comment;

import com.example.tripy.domain.member.Member;
import com.example.tripy.domain.post.Post;
import com.example.tripy.global.utils.BaseTimeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Builder
public class Comment extends BaseTimeEntity {


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
private String content;

@ManyToOne
private Member member;

@ManyToOne
private Post post;

public static Comment toEntity(Member member, Post post, String content) {
return Comment.builder()
.member(member)
.post(post)
.content(content)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.tripy.domain.comment;

import com.example.tripy.domain.comment.dto.CommentRequestDto.CreateCommentRequest;
import com.example.tripy.domain.comment.dto.CommentResponseDto.GetCommentInfo;
import com.example.tripy.global.common.dto.PageResponseDto;
import com.example.tripy.global.common.response.ApiResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class CommentController {

private final CommentService commentService;

/**
* [POST] 댓글 작성
*/
@PostMapping("api/{posts-id}/comments")
public ApiResponse<String> createComment(
@PathVariable(value = "posts-id") Long postId,
@RequestBody CreateCommentRequest createCommentRequest
) {
commentService.addComment(createCommentRequest.getContent(), postId);
return ApiResponse.onSuccess("댓글 작성에 성공했습니다.");
}

/**
* [GET] 댓글 조회
*/
@GetMapping("/api/{posts-id}/comments")
public ApiResponse<PageResponseDto<List<GetCommentInfo>>> findComments(
@RequestParam int page, @RequestParam int size, @PathVariable(value="posts-id") Long postsId

) {
return ApiResponse.onSuccess(commentService.findComments(page, size, postsId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.tripy.domain.comment;

import com.example.tripy.domain.comment.Comment;
import com.example.tripy.domain.post.Post;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CommentRepository extends JpaRepository<Comment, Long> {

Page<Comment> findByPost(Post post, Pageable pageable);
}
56 changes: 56 additions & 0 deletions src/main/java/com/example/tripy/domain/comment/CommentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.example.tripy.domain.comment;

import com.example.tripy.domain.comment.dto.CommentResponseDto.GetCommentInfo;
import com.example.tripy.domain.member.Member;
import com.example.tripy.domain.member.MemberRepository;
import com.example.tripy.domain.post.Post;
import com.example.tripy.domain.post.PostRepository;
import com.example.tripy.global.common.dto.PageResponseDto;
import com.example.tripy.global.common.response.code.status.ErrorStatus;
import com.example.tripy.global.common.response.exception.GeneralException;
import com.example.tripy.global.utils.DateTimeConverter;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CommentService {

private final CommentRepository commentRepository;
private final MemberRepository memberRepository;
private final PostRepository postRepository;

//댓글 추가
public void addComment(String content, Long postId) {

Member member = memberRepository.findById(1L)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_MEMBER));

Post post = postRepository.findById(postId)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_POST));

Comment comment = Comment.toEntity(member, post, content);
commentRepository.save(comment);
}

//댓글 조회
PageResponseDto<List<GetCommentInfo>> findComments(int page, int size, Long postsId) {

Pageable pageable = PageRequest.of(page, size);
Post post = postRepository.findById(postsId)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_POST));

Page<Comment> commentList = commentRepository.findByPost(post, pageable);

List<GetCommentInfo> dtoList = commentList.stream()
.map(comment -> GetCommentInfo.toDto(comment, comment.getMember(),
DateTimeConverter.convertToDisplayTime(comment.getCreatedAt())))
.toList();

return new PageResponseDto<>(commentList.getNumber(), commentList.getTotalPages(), dtoList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.tripy.domain.comment.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class CommentRequestDto {

@AllArgsConstructor
@NoArgsConstructor
@Getter
public static class CreateCommentRequest {
private String content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.tripy.domain.comment.dto;

import com.example.tripy.domain.comment.Comment;
import com.example.tripy.domain.member.Member;
import lombok.Builder;
import lombok.Getter;

public class CommentResponseDto {

@Getter
@Builder
public static class GetCommentInfo {

private String nickname;
private String profileImageUrl;
private String content;
private String createdAt;

public static GetCommentInfo toDto(Comment comment, Member member, String createdAt) {
return GetCommentInfo.builder()
.nickname(member.getNickName())
.profileImageUrl(member.getProfileImgUrl())
.content(comment.getContent())
.createdAt(createdAt)
.build();

}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/tripy/domain/post/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class Post extends BaseTimeEntity {
private String content;

@ColumnDefault("0")
private Long view;
private Long view = 0L;

@ColumnDefault("0")
private Integer recommendationCount;
private Integer recommendationCount = 0;

@ColumnDefault("0")
private int rank;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/example/tripy/domain/post/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.example.tripy.global.common.response.exception.GeneralException;
import jakarta.transaction.Transactional;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -162,6 +163,10 @@ public GetPostDetailInfo findPost(Long postsId) {
List<String> fileUrls = postFileService.findImageFileUrlsByPostAndFileType(post, FileType.FILE);
List<String> postTags = postTagService.findTagsStringByPost(post);

return GetPostDetailInfo.toDto(post, imageUrls, fileUrls, postTags);
Long travelPlanId = Optional.ofNullable(post.getTravelPlan())
.map(TravelPlan::getId)
.orElse(null);

return GetPostDetailInfo.toDto(post, travelPlanId, imageUrls, fileUrls, postTags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public static class GetPostDetailInfo {
private String createdAt;


public static GetPostDetailInfo toDto(Post post, List<String> imgUrls, List<String> fileUrls, List<String> postTags) {
public static GetPostDetailInfo toDto(Post post, Long travelPlanId, List<String> imgUrls, List<String> fileUrls, List<String> postTags) {
return GetPostDetailInfo.builder()
.postId(post.getId())
.title(post.getTitle())
.nickname(post.getMember().getNickName())
.travelPlanId(post.getTravelPlan().getId())
.travelPlanId(travelPlanId)
.content(post.getContent())
.imgUrls(imgUrls)
.fileUrls(fileUrls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface TravelPlanRepository extends JpaRepository<TravelPlan, Long> {

Optional<TravelPlan> findByMemberAndIdAndBagExistsIsFalse(Member member, Long id);

Page<TravelPlan> findAllByMemberIdAndBagExistsIsTrue(Long memberId, Pageable pageable);
Page<TravelPlan> findAllByMemberAndBagExistsIsTrue(Member member, Pageable pageable);

Optional<TravelPlan> findByMemberAndIdAndBagExistsIsTrue(Member member, Long id);

Expand Down
Loading

0 comments on commit bbd0bd2

Please sign in to comment.