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

main branch merge #114

Merged
merged 16 commits into from
Feb 17, 2024
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
2 changes: 2 additions & 0 deletions src/main/generated/umc/IRECIPE_Server/entity/QMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class QMember extends EntityPathBase<Member> {

public final StringPath personalId = createString("personalId");

public final ListPath<Post, QPost> postList = this.<Post, QPost>createList("postList", Post.class, QPost.class, PathInits.DIRECT2);

public final StringPath profileImage = createString("profileImage");

public final ListPath<Qna, QQna> qnaList = this.<Qna, QQna>createList("qnaList", Qna.class, QQna.class, PathInits.DIRECT2);
Expand Down
2 changes: 1 addition & 1 deletion src/main/generated/umc/IRECIPE_Server/entity/QReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class QReview extends EntityPathBase<Review> {

public final QPost post;

public final NumberPath<Float> score = createNumber("score", Float.class);
public final NumberPath<Integer> score = createNumber("score", Integer.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import umc.IRECIPE_Server.apiPayLoad.exception.handler.PostHandler;
import umc.IRECIPE_Server.common.S3.S3Service;
import umc.IRECIPE_Server.converter.MemberConverter;
import umc.IRECIPE_Server.converter.PostConverter;
import umc.IRECIPE_Server.dto.MemberRequest;
import umc.IRECIPE_Server.dto.MemberResponse;
import umc.IRECIPE_Server.dto.MemberLoginRequestDto;
Expand Down Expand Up @@ -113,15 +114,15 @@ public ApiResponse<MemberResponse.JoinResultDto> joinLogin(

@Operation(summary = "작성 글 API",description = "사용자가 작성한 글 보기")
@GetMapping(value = "/written")
public ApiResponse<List<MemberResponse.getPostsDto>> showWrittenPosts(
public ApiResponse<?> showWrittenPosts(
@RequestParam(name = "page") Integer page
){
if(page < 0) throw new PostHandler(ErrorStatus.INVALID_PAGE);
//사용자 id 찾기
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String userId = authentication.getName();//personal id

return ApiResponse.onSuccess(MemberConverter.postsListDto(memberService.getWrittenPostList(userId, page)));
return memberService.getWrittenPostList(userId, page);
}

@Operation(summary = "관심 글 API",description = "사용자가 좋아요 누른 글 보기")
Expand All @@ -134,7 +135,7 @@ public ApiResponse<?> showLikedPosts(
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String userId = authentication.getName();//personal id

return ApiResponse.onSuccess(MemberConverter.postsLikedListDto(memberService.getLikedPostList(userId, page)));
return memberService.getLikedPostList(userId, page);
}

@Operation(summary = "토큰 재발급 API", description = "토큰 재발급")
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/umc/IRECIPE_Server/controller/QnaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -62,8 +63,11 @@ public ApiResponse<List<QnaResponseDTO.getQnaDTO>> getQna(@PathVariable("postId"
public ApiResponse<QnaResponseDTO.updateQnaDTO> updateQna(@PathVariable("qnaId") Long qnaId,
@RequestPart(name = "QnaRequestDTO", required = false) QnaRequestDTO.updateQna request,
@RequestPart(value = "file", required = false) MultipartFile file) throws IOException {
// memberId 값 세팅
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String memberId = authentication.getName();

qnaService.updateQna(qnaId, request, file);
qnaService.updateQna(memberId, qnaId, request, file);
return ApiResponse.onSuccess(QnaConverter.updateQnaResult(qnaId));
}

Expand All @@ -74,7 +78,11 @@ public ApiResponse<QnaResponseDTO.updateQnaDTO> updateQna(@PathVariable("qnaId")
)
@DeleteMapping("/qna/{qnaId}")
public ApiResponse<QnaResponseDTO.deleteQnaDTO> deleteQna(@PathVariable("qnaId") Long qnaId) {
qnaService.deleteQna(qnaId);
// memberId 값 세팅
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String memberId = authentication.getName();

qnaService.deleteQna(memberId, qnaId);
return ApiResponse.onSuccess(QnaConverter.deleteQnaResult());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ public ApiResponse<List<ReviewResponseDTO.getReviewResponseDTO>> getPostReview(@
public ApiResponse<ReviewResponseDTO.updateReviewResponseDTO> updatePostReview(@PathVariable("reviewId") Long reviewId,
@RequestPart(name = "ReviewRequestDTO", required = false) ReviewRequestDTO.addReviewDTO request,
@RequestPart(value = "file", required = false) MultipartFile file) throws IOException {
// memberId 값 세팅
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String memberId = authentication.getName();

reviewService.updatePostReview(reviewId, request, file);
reviewService.updatePostReview(memberId, reviewId, request, file);
return ApiResponse.onSuccess(ReviewConverter.updateReviewResult(reviewId));
}

Expand All @@ -76,7 +79,11 @@ public ApiResponse<ReviewResponseDTO.updateReviewResponseDTO> updatePostReview(@
)
@DeleteMapping("/review/{reviewId}")
public ApiResponse<ReviewResponseDTO.deleteReviewResponseDTO> deletePostReview(@PathVariable("reviewId") Long reviewId) {
reviewService.deletePostReview(reviewId);
// memberId 값 세팅
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String memberId = authentication.getName();

reviewService.deletePostReview(memberId, reviewId);
return ApiResponse.onSuccess(ReviewConverter.deleteReviewResult());
}
}
32 changes: 0 additions & 32 deletions src/main/java/umc/IRECIPE_Server/converter/MemberConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,4 @@ public static MemberResponse.getPostsDto postsDto(Post post){
.build();
}

public static List<MemberResponse.getPostsDto> postsListDto(Page<Post> postPage){
return postPage.stream()
.map(val -> MemberResponse.getPostsDto.builder()
.title(val.getTitle())
.subhead(val.getSubhead())
.level(val.getLevel())
.score(val.getScore())
.content(val.getContent())
.likes(val.getLikes())
.imageUrl(val.getImageUrl())
.category(val.getCategory())
.fileName(val.getFileName())
.build())
.collect(Collectors.toList());
}

public static List<MemberResponse.getPostsDto> postsLikedListDto(List<Post> postList){
return postList.stream()
.map(val -> MemberResponse.getPostsDto.builder()
.title(val.getTitle())
.subhead(val.getSubhead())
.level(val.getLevel())
.score(val.getScore())
.content(val.getContent())
.likes(val.getLikes())
.imageUrl(val.getImageUrl())
.category(val.getCategory())
.fileName(val.getFileName())
.build())
.collect(Collectors.toList());
}

}
24 changes: 23 additions & 1 deletion src/main/java/umc/IRECIPE_Server/converter/PostConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static PostResponseDTO.getTempDTO toTempResponseDTO(Post post){



public static PostResponseDTO.getDTO toGetResponseDTO(Post post, Member member, boolean likeOrNot){
public static PostResponseDTO.getDTO toGetResponseDTO(Post post, Member member, boolean likeOrNot, boolean myPost){
return PostResponseDTO.getDTO.builder()
.postId(post.getId())
.title(post.getTitle())
Expand All @@ -56,6 +56,7 @@ public static PostResponseDTO.getDTO toGetResponseDTO(Post post, Member member,
.createdAt(post.getCreatedAt().toLocalDate())
.reviewsCount(post.getReviewList().size())
.likeOrNot(likeOrNot)
.myPost(myPost)
.build();
}

Expand All @@ -65,6 +66,27 @@ public static PostResponseDTO.updateDTO toUpdateResponseDTO(Post post){
.build();
}

public static List<PostResponseDTO.getDTO> toGetAllPostListDTO(Member member, List<Post> postPage, Map<Long, Boolean> likeMap){
return postPage.stream()
.map(m -> PostResponseDTO.getDTO.builder()
.postId(m.getId())
.title(m.getTitle())
.subhead(m.getSubhead())
.imageUrl(m.getImageUrl())
.likes(m.getLikes())
.score(m.getScore())
.reviewsCount(m.getReviewList().size())
.writerImage(m.getMember().getProfileImage())
.writerNickName(m.getMember().getNickname())
.createdAt(m.getCreatedAt().toLocalDate())
.likeOrNot(likeMap.get(m.getId()))
.category(m.getCategory())
.content(m.getContent())
.myPost(m.getMember().equals(member))
.build())
.collect(Collectors.toList());
}

public static List<PostResponseDTO.getAllPostDTO> toGetAllPostDTO(Page<Post> postPage, Map<Long, Boolean> likeMap){
return postPage.stream()
.map(m -> PostResponseDTO.getAllPostDTO.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class QnaRequestDTO {
public static class addQna {
@Schema(description = "Qna 내용", defaultValue = "설탕 대신 알룰로스를...")
private String content;
@Schema(description = "부모 댓글 Id", defaultValue = "1")
@Schema(description = "부모 댓글 Id", defaultValue = "0")
private Long parentId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public static class addReviewDTO {
private String context;

@Schema(description = "리뷰 별점", defaultValue = "4.3")
private Float score;
private int score;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public static class getDTO{
@Schema(description = "해당 사용자가 관심 눌렀는지", defaultValue = "false")
private boolean likeOrNot;

@Schema(description = "내가 쓴 글인지 아닌지", defaultValue = "false")
private boolean myPost;

@Schema(description = "게시글 생성일")
private LocalDate createdAt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ReviewResponseDTO {
@AllArgsConstructor
public static class addReviewResponseDTO {

@Schema(description = "리뷰 별점", defaultValue = "4.3")
private Float score;
@Schema(description = "리뷰 별점", defaultValue = "4")
private int score;

@Schema(description = "리뷰 내용", defaultValue = "노력대비 최고의 맛!...")
private String context;
Expand Down Expand Up @@ -52,7 +52,7 @@ public static class getReviewResponseDTO {
private String context;

@Schema(description = "리뷰 별점")
private Float score;
private int score;

@Schema(description = "리뷰 사진")
private String imageUrl;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/umc/IRECIPE_Server/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Review extends BaseEntity {
private Post post;

// 별점
private Float score;
private int score;

// 리뷰 내용
private String context;
Expand All @@ -53,7 +53,7 @@ public class Review extends BaseEntity {
// 사진 이름
private String fileName;

public void updateReview(Float score, String context, String imageUrl, String fileName) {
public void updateReview(int score, String context, String imageUrl, String fileName) {
this.score = score;
this.context = context;
this.imageUrl = imageUrl;
Expand Down
31 changes: 26 additions & 5 deletions src/main/java/umc/IRECIPE_Server/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Flow.Publisher;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,6 +16,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import umc.IRECIPE_Server.apiPayLoad.ApiResponse;
import umc.IRECIPE_Server.apiPayLoad.code.status.ErrorStatus;
import umc.IRECIPE_Server.apiPayLoad.exception.handler.AllergyHandler;
import umc.IRECIPE_Server.apiPayLoad.exception.handler.MemberHandler;
Expand All @@ -22,6 +25,7 @@
import umc.IRECIPE_Server.common.enums.Status;
import umc.IRECIPE_Server.converter.MemberAllergyConverter;
import umc.IRECIPE_Server.converter.MemberConverter;
import umc.IRECIPE_Server.converter.PostConverter;
import umc.IRECIPE_Server.dto.MemberRequest;
import umc.IRECIPE_Server.dto.MemberResponse;
import umc.IRECIPE_Server.dto.MemberLoginRequestDto;
Expand Down Expand Up @@ -188,7 +192,7 @@ public Member login(MemberLoginRequestDto.JoinLoginDto request){
}

@Transactional
public Page<Post> getWrittenPostList(String personalId, Integer page) {
public ApiResponse<?> getWrittenPostList(String personalId, Integer page) {
Page<Post> postPage;
Pageable pageable = PageRequest.of(page, 10);

Expand All @@ -205,11 +209,19 @@ public Page<Post> getWrittenPostList(String personalId, Integer page) {
else if(page == 0) throw new PostHandler(ErrorStatus.MEMBER_DONT_HAVE_POSTS);
}

return postPage;
// memberLike 에서 찾으면 관심 눌렀던 게시글, 못 찾으면 관심 안 누른 게시글
Map<Long, Boolean> likeMap = new HashMap<>();
for (Post post : postPage) {
Boolean likeOrNot = memberLikesRepository.findByMemberAndPost(mem, post).isPresent();
likeMap.put(post.getId(), likeOrNot);
}

return ApiResponse.onSuccess(PostConverter.toGetAllPostDTO(postPage, likeMap));
}

//회원 관심글 보기
@Transactional
public List<Post> getLikedPostList(String personalId, Integer page) {
public ApiResponse<?> getLikedPostList(String personalId, Integer page) {
Page<MemberLikes> postIdPage;
Pageable pageable = PageRequest.of(page, 10);

Expand All @@ -228,7 +240,7 @@ public List<Post> getLikedPostList(String personalId, Integer page) {

List<Post> postList = new ArrayList<>();
for(MemberLikes memberLikes : postIdPage.toList()){
Long id = memberLikes.getId();
Long id = memberLikes.getPost().getId();
Post tmp = postRepository.findByStatusAndId(Status.POST, id);
postList.add(tmp);
}
Expand All @@ -237,9 +249,17 @@ public List<Post> getLikedPostList(String personalId, Integer page) {
throw new MemberHandler(ErrorStatus.POST_NOT_FOUND);
}

return postList;
// memberLike 에서 찾으면 관심 눌렀던 게시글, 못 찾으면 관심 안 누른 게시글
Map<Long, Boolean> likeMap = new HashMap<>();
for (Post post : postList) {
Boolean likeOrNot = memberLikesRepository.findByMemberAndPost(mem, post).isPresent();
likeMap.put(post.getId(), likeOrNot);
}

return ApiResponse.onSuccess(PostConverter.toGetAllPostListDTO(mem, postList, likeMap));
}

//토큰 재발급
@Transactional
public Member refresh(Member member){
if(tokenRepository.existsByMember(member)){ // 이미 refresh token이 있다면
Expand All @@ -251,6 +271,7 @@ public Member refresh(Member member){
return member;
}

//회원 탈퇴
@Transactional
public void deleteMember(String personalId){
Optional<Member> member = memberRepository.findByPersonalId(personalId);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/umc/IRECIPE_Server/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,18 @@ public ApiResponse<?> getPost(Long postId, String userId){

Post post = findByPostId(postId);

boolean likeOrNot = memberLikesRepository.findByMemberAndPost(post.getMember(), post).isPresent();
Member member = memberRepository.findByPersonalId(userId)
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));

boolean likeOrNot = memberLikesRepository.findByMemberAndPost(member, post).isPresent();

boolean myPost = false;

if(member == post.getMember()){
myPost = true;
}

return ApiResponse.onSuccess(PostConverter.toGetResponseDTO(post, post.getMember(), likeOrNot));
return ApiResponse.onSuccess(PostConverter.toGetResponseDTO(post, post.getMember(), likeOrNot, myPost));

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/umc/IRECIPE_Server/service/QnaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public interface QnaService {
public List<QnaResponseDTO.getQnaDTO> getQna(Long postId);

// Qna 수정
public void updateQna(Long qnaId, QnaRequestDTO.updateQna request, MultipartFile file) throws IOException;
public void updateQna(String memberId, Long qnaId, QnaRequestDTO.updateQna request, MultipartFile file) throws IOException;

// Qna 삭제
public void deleteQna(Long qnaId);
public void deleteQna(String memberId, Long qnaId);
}
Loading
Loading