Skip to content

Commit

Permalink
Merge pull request #57 from KTB16Team/feature/56-refactor
Browse files Browse the repository at this point in the history
refactor: 게시글마다 좋아요, 투표, 작성 여부를 표기하는 변수 추가
  • Loading branch information
mng990 authored Nov 5, 2024
2 parents 555da50 + 2209750 commit a523535
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import aimo.backend.domains.post.dto.response.FindPostAndCommentsByIdResponse.ParentCommentDto;
import aimo.backend.domains.post.dto.response.FindPostsByPostTypeResponse;
import aimo.backend.domains.post.entity.Post;
import aimo.backend.domains.post.entity.Vote;
import aimo.backend.domains.post.model.Side;

public class PostMapper {

Expand Down Expand Up @@ -67,6 +69,13 @@ public static FindPostAndCommentsByIdResponse toFindPostAndCommentsByIdResponse(
) {
return new FindPostAndCommentsByIdResponse(
post.getMember() == member,
post.getPostLikes().stream()
.anyMatch(postLike -> postLike.getMember() == member),
post.getVotes().stream()
.filter(vote -> vote.getMember() == member)
.findFirst()
.map(Vote::getSide)
.orElse(Side.NONE),
post.getTitle(),
post.getMember().getNickname(),
post.getSummaryAi(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import org.springframework.web.bind.annotation.RestController;

import aimo.backend.domains.member.dto.request.CreateProfileImageUrlRequest;
import aimo.backend.domains.member.dto.request.DeleteRequest;
import aimo.backend.domains.member.dto.request.DeleteMemberRequest;
import aimo.backend.domains.member.dto.response.FindMyInfoResponse;
import aimo.backend.domains.member.dto.request.LogOutRequest;
import aimo.backend.domains.member.dto.request.LogoutRequest;
import aimo.backend.domains.member.dto.response.NicknameExistsResponse;
import aimo.backend.domains.member.dto.request.SendTemporaryPasswordRequest;
import aimo.backend.domains.member.dto.request.SignUpRequest;
Expand Down Expand Up @@ -50,7 +50,7 @@ public ResponseEntity<DataResponse<Void>> logoutMember(HttpServletRequest reques
String accessToken = jwtTokenProvider.extractAccessToken(request).orElse(null);
String refreshToken = jwtTokenProvider.extractRefreshToken(request).orElse(null);
log.info("logout member access token: {} refresh token: {}", accessToken, refreshToken);
memberService.logoutMember(new LogOutRequest(accessToken, refreshToken));
memberService.logoutMember(new LogoutRequest(accessToken, refreshToken));

return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created());
}
Expand All @@ -63,8 +63,8 @@ public ResponseEntity<DataResponse<Void>> signupMember(@RequestBody @Valid SignU
}

@DeleteMapping
public ResponseEntity<DataResponse<Void>> deleteMember(@RequestBody DeleteRequest deleteRequest) {
memberService.deleteMember(deleteRequest);
public ResponseEntity<DataResponse<Void>> deleteMember(@RequestBody DeleteMemberRequest deleteMemberRequest) {
memberService.deleteMember(deleteMemberRequest);

return ResponseEntity.status(HttpStatus.NO_CONTENT).body(DataResponse.noContent());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package aimo.backend.domains.member.dto.request;

public record DeleteMemberRequest(String password) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package aimo.backend.domains.member.dto.request;

public record LogOutRequest(
public record LogoutRequest(
String accessToken,
String refreshToken
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package aimo.backend.domains.member.dto.request;

public record LogoutRequest(
String accessToken,
String refreshToken
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import aimo.backend.common.exception.ApiException;
import aimo.backend.common.exception.ErrorCode;
import aimo.backend.domains.member.dto.request.DeleteRequest;
import aimo.backend.domains.member.dto.request.DeleteMemberRequest;
import aimo.backend.domains.member.dto.response.FindMyInfoResponse;
import aimo.backend.domains.member.dto.request.LogOutRequest;
import aimo.backend.domains.member.dto.request.LogoutRequest;
import aimo.backend.domains.member.dto.request.SendTemporaryPasswordRequest;
import aimo.backend.domains.member.dto.request.SignUpRequest;
import aimo.backend.domains.member.dto.request.UpdateNicknameRequest;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void signUp(SignUpRequest signUpRequest) {

//로그아웃
@Transactional(rollbackFor = ApiException.class)
public void logoutMember(LogOutRequest logOutRequest) {
public void logoutMember(LogoutRequest logOutRequest) {
// 회원의 refreshToken 만료 처리
String accessToken = logOutRequest.accessToken(), refreshToken = logOutRequest.refreshToken();
RefreshToken expiredToken = new RefreshToken(accessToken, refreshToken);
Expand All @@ -77,10 +77,10 @@ public void logoutMember(LogOutRequest logOutRequest) {

// 회원 삭제
@Transactional(rollbackFor = ApiException.class)
public void deleteMember(DeleteRequest deleteRequest) {
public void deleteMember(DeleteMemberRequest deleteMemberRequest) {
Member member = memberLoader.getMember();

if (!isValid(deleteRequest.password(), member.getPassword())) {
if (!isValid(deleteMemberRequest.password(), member.getPassword())) {
throw ApiException.from(ErrorCode.INVALID_PASSWORD);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import aimo.backend.domains.comment.entity.ParentComment;
import aimo.backend.domains.member.entity.Member;
import aimo.backend.domains.post.model.Side;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -13,6 +16,9 @@
@AllArgsConstructor
public class FindPostAndCommentsByIdResponse {
private final Boolean isMine;
private final Boolean isLiked;
@Enumerated(EnumType.STRING)
private final Side side;
private final String title;
private final String nickname;
private final String content;
Expand All @@ -29,6 +35,7 @@ public class FindPostAndCommentsByIdResponse {
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class ParentCommentDto {
private final Boolean isMine;
private final Boolean isLiked;
private final Long commentId;
private final String content;
private final String nickname;
Expand All @@ -39,14 +46,18 @@ public static class ParentCommentDto {
public static ParentCommentDto of(Member member, ParentComment parentComment) {
return new ParentCommentDto(
parentComment.getMember() == member,
parentComment.getParentCommentLikes().stream()
.anyMatch(like -> like.getMember() == member),
parentComment.getId(),
parentComment.getContent(),
parentComment.getNickname(),
parentComment.getLikesCount(),
parentComment.getCreatedAt(),
parentComment.getChildComments().stream()
.map(childComment -> new ChildCommentDto(
parentComment.getMember() == member,
childComment.getMember() == member,
childComment.getChildCommentLikes().stream()
.anyMatch(like -> like.getMember() == member),
childComment.getId(),
childComment.getContent(),
childComment.getNickname(),
Expand All @@ -62,6 +73,7 @@ public static ParentCommentDto of(Member member, ParentComment parentComment) {
@AllArgsConstructor
private static class ChildCommentDto {
private final Boolean isMine;
private final Boolean isLiked;
private final Long childCommentDd;
private final String content;
private final String nickname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import lombok.Getter;

public enum Side {
PLAINTIFF("원고"),
DEFENDANT("피고");
PLAINTIFF("plaintiff"),
DEFENDANT("defendant"),
NONE("none");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public class PrivatePostController {
@PostMapping("/judgement")
public ResponseEntity<DataResponse<Void>> summaryAndJudgment(@Valid @RequestBody JudgementToAiRequest judgementToAiRequest) {

JudgementResponse summaryAndJudgementResponse = privatePostService.serveScriptToAi(judgementToAiRequest);
JudgementResponse judgementResponse = privatePostService.serveScriptToAi(judgementToAiRequest);

privatePostService.save(summaryAndJudgementResponse);
privatePostService.save(judgementResponse);

return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created());
}
Expand All @@ -88,7 +88,6 @@ public ResponseEntity<DataResponse<SpeachToTextResponse>> speechToText(
return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created(audioRecordService.speachToText(speachToTextRequest)));
}


@GetMapping("/audio/presigned")
public ResponseEntity<DataResponse<CreatePresignedUrlResponse>> getPresignedUrlTo(
@Valid @RequestBody CreatePresignedUrlRequest createPresignedUrlRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import aimo.backend.domains.privatePost.dto.response.PrivatePostResponse;
import aimo.backend.domains.privatePost.dto.request.SummaryAndJudgementRequest;
import aimo.backend.domains.privatePost.dto.response.JudgementFromAiResponse;
import aimo.backend.domains.privatePost.dto.request.TextRecordRequest;
import aimo.backend.domains.privatePost.entity.PrivatePost;
import aimo.backend.domains.privatePost.repository.PrivatePostRepository;
import aimo.backend.util.memberLoader.MemberLoader;
Expand Down Expand Up @@ -75,8 +74,8 @@ public JudgementResponse serveScriptToAi(JudgementToAiRequest judgementToAiReque
}

@Transactional(rollbackFor = ApiException.class)
public PrivatePost save(JudgementResponse summaryAndJudgementResponse) {
PrivatePost privatePost = PrivatePostMapper.toEntity(summaryAndJudgementResponse);
public PrivatePost save(JudgementResponse judgementResponse) {
PrivatePost privatePost = PrivatePostMapper.toEntity(judgementResponse);

if (!isValid(memberLoader.getMember().getId(), privatePost)) {
throw ApiException.from(PRIVATE_POST_CREATE_UNAUTHORIZED);
Expand Down

0 comments on commit a523535

Please sign in to comment.