Skip to content

Commit

Permalink
Merge pull request #54 from KOA-TF/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
Jeongh00 authored Dec 4, 2023
2 parents a8e8dbc + 086991c commit f2c7117
Show file tree
Hide file tree
Showing 64 changed files with 1,053 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.koa.coremodule.member.application.service.MemberGetUseCase;
import com.koa.coremodule.member.application.service.MemberCheckUseCase;
import com.koa.coremodule.member.application.service.MemberPasswordChangeUseCase;
import com.koa.coremodule.member.application.service.MemberRegisterUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -40,6 +41,7 @@ public class MemberController {
private final MemberDeleteUseCase memberDeleteUseCase;
private final EmailVerificationUseCase emailVerificationUseCase;
private final MemberPasswordChangeUseCase memberPasswordChangeUseCase;
private final MemberRegisterUseCase memberRegisterUseCase;

@GetMapping("/info")
public ApplicationResponse<MemberInfoResponse> getMemberInfo(){
Expand All @@ -53,11 +55,19 @@ public ApplicationResponse<Void> postMemberDetail(@RequestPart(value = "dto") Me
return ApplicationResponse.ok(null);
}

@PostMapping("/register")
@PostMapping("/check/register")
public ApplicationResponse<CheckRegisterResponse> checkMemberRegistered(@RequestParam String email, @RequestParam String password) {
CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(email, password);
return ApplicationResponse.ok(response);
}

@PostMapping("/register")
public ApplicationResponse<Void> postMemberDetail(@RequestParam String email, @RequestParam String password){
memberRegisterUseCase.registerMember(email, password);
return ApplicationResponse.ok(null);
}


@GetMapping("/info/detail")
public ApplicationResponse<MemberDetailInfoResponse> getMemberDetailInfo() {
MemberDetailInfoResponse response = memberGetUseCase.getMemberDetailInfo();
Expand Down Expand Up @@ -99,4 +109,10 @@ public ApplicationResponse<Void> putPassword(@RequestBody MemberPasswordChangeRe
memberPasswordChangeUseCase.changePassword(memberPasswordChangeRequest);
return ApplicationResponse.ok(null);
}

@PutMapping("/password/unauthenticated")
public ApplicationResponse<Void> putPasswordUnauthenticated(@RequestParam String email, @RequestBody MemberPasswordChangeRequest memberPasswordChangeRequest) {
memberPasswordChangeUseCase.changePasswordUnauthenticated(email, memberPasswordChangeRequest);
return ApplicationResponse.ok(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public ApplicationResponse<Long> saveNotice(
@RequestPart(value = "dto") NoticeRequest request,
@RequestPart(value = "file") MultipartFile multipartFile) {

Member memberRequest = memberUtils.getAccessMember();
request.setMemberId(memberRequest.getId());
Long noticeId = noticeSaveUseCase.saveNotice(request, multipartFile);
return ApplicationResponse.ok(noticeId, "공지 작성에 성공했습니다.");
}
Expand Down Expand Up @@ -103,12 +101,12 @@ public ApplicationResponse<Void> deleteNotice(
* 공지 상세 조회 (내용)
*/
@GetMapping(value = "/{noticeId}/detail")
public ApplicationResponse<NoticeListResponse> noticeDetail(
public ApplicationResponse<NoticeDetailListResponse> noticeDetail(
@PathVariable Long noticeId) {

Member memberRequest = memberUtils.getAccessMember();

NoticeListResponse response = noticeSaveUseCase.selectNoticeDetail(memberRequest.getId(), noticeId);
NoticeDetailListResponse response = noticeSaveUseCase.selectNoticeDetail(memberRequest.getId(), noticeId);
return ApplicationResponse.ok(response, "공지 상세 조회에 성공했습니다.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.koa.apimodule.command.api;

import com.koa.commonmodule.common.ApplicationResponse;
import com.koa.coremodule.vote.application.dto.VoteRequest;
import com.koa.coremodule.vote.application.dto.VoteStatus;
import com.koa.coremodule.vote.application.service.VoteFindUseCase;
import com.koa.coremodule.vote.application.service.VoteSaveUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/vote")
public class VoteController {

private final VoteSaveUseCase voteSaveUseCase;
private final VoteFindUseCase voteFindUseCase;

/**
* 투표 생성
*/
@PostMapping
public ApplicationResponse<Long> makeVote(@RequestBody VoteRequest voteRequest) {

Long voteId = voteSaveUseCase.saveVote(voteRequest);
return ApplicationResponse.ok(voteId, "투표 생성을 완료했습니다.");
}

/**
* 투표 현황 조회 - 명단까지 리스트로 전달 필요
*/
@GetMapping
public ApplicationResponse<VoteStatus> getVoteStatus(Long noticeId) {

VoteStatus voteStatus = voteFindUseCase.findVoteStatus(noticeId);
return ApplicationResponse.ok(voteStatus, "투표 현황 조회 완료했습니다.");
}

/**
* 투표 참여
*/
@PostMapping(value = "/attend")
public ApplicationResponse<Long> attendVote(Long voteItemId) {

Long voteItemRecordId = voteSaveUseCase.attendVote(voteItemId);
return ApplicationResponse.ok(voteItemRecordId, "투표 참여를 완료했습니다.");
}

/**
* 투표 마감 처리
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public enum Error {
//REPORT
DUPLICATE_REPORT("이미 등록된 신고내용입니다.", 400),

//NOTICE
// VOTE
VOTE_NOT_FOUND("투표가 존재하지 않습니다.", 400),
VOTE_ITEM_NOT_FOUND("투표 항목이 존재하지 않습니다.", 400),
VOTE_ITEM_RECORD_NOT_FOUND("투표 항목 참여자가 존재하지 않습니다.", 400),

// MEMBER
MEMBER_NOT_FOUND("사용자를 찾을 수 없습니다.", 2000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ private static Map<String, Set<HttpMethod>> createIgnoredPathMap() {

map.put("/v1/auth/reissue", Set.of(HttpMethod.GET));
map.put("/v1/member/register", Set.of(HttpMethod.POST));
map.put("/v1/member/check/register", Set.of(HttpMethod.POST));
map.put("/h2-console/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/v1/auth/login/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/v1/member/email", Set.of(HttpMethod.POST));
map.put("/v1/member/verify", Set.of(HttpMethod.POST));
map.put("/v1/member/verify/code", Set.of(HttpMethod.POST));
map.put("/v1/member/password/unauthenticated", Set.of(HttpMethod.PUT));
map.put("/api-docs/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/error", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/favicon.ico", Set.of(HttpMethod.GET, HttpMethod.POST));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@NoArgsConstructor
public class CommentCreateRequest {
private String content;
private Boolean isAnonymous;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public class CommentInfoResponse {
private final String writer;
private final String createdAt;
private final Boolean isMine;
private final Boolean isAnonymous;
private final String profileImageUrl;
private final Long writerId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public class CommentListResponse {
private final String createdAt;
private final Integer commentCount;
private final Boolean isMine;
private final Boolean isAnonymous;
private final String profileImageUrl;
private final Long writerId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.koa.coremodule.comment.application.dto.response.CommentInfoResponse;
import com.koa.coremodule.comment.domain.entity.Comment;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.entity.MemberDetail;
import com.koa.coremodule.notice.domain.entity.Notice;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand All @@ -11,32 +12,37 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CommentMapper {

public static Comment mapToCommentWithUserAndAlbum(String content, Notice notice, Member member) {
public static Comment mapToCommentWithUserAndAlbum(String content, Notice notice, Member member, Boolean isAnonymous) {
Comment comment = Comment.builder()
.content(content)
.notice(notice)
.writer(member)
.isAnonymous(isAnonymous)
.build();
return comment;
}

public static Comment mapToCommentWithUserAndNoticeAndParent(String content, Notice notice, Member member, Comment parent) {
public static Comment mapToCommentWithUserAndNoticeAndParent(String content, Notice notice, Member member, Comment parent, Boolean isAnonymous) {
Comment comment = Comment.builder()
.content(content)
.notice(notice)
.writer(member)
.parent(parent)
.isAnonymous(isAnonymous)
.build();
return comment;
}

public static CommentInfoResponse mapToCommentInfoResponse(Comment comment, Member member) {
public static CommentInfoResponse mapToCommentInfoResponse(Comment comment, Member member, MemberDetail memberDetail) {
return CommentInfoResponse.builder()
.commentId(comment.getId())
.content(comment.getContent())
.writer(member.getName())
.createdAt(comment.getCreatedAt().toString())
.createdAt(comment.getCreatedAtByFormat())
.isMine(comment.getWriter().equals(member))
.isAnonymous(comment.getIsAnonymous())
.profileImageUrl(memberDetail.getProfileImage())
.writerId(member.getId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.koa.coremodule.comment.domain.service.CommentQueryService;
import com.koa.coremodule.comment.domain.service.CommentSaveService;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.entity.MemberDetail;
import com.koa.coremodule.member.domain.service.MemberDetailQueryService;
import com.koa.coremodule.member.domain.utils.MemberUtils;
import com.koa.coremodule.notice.domain.service.NoticeQueryService;
import com.koa.coremodule.notice.domain.entity.Notice;
Expand All @@ -21,25 +23,28 @@ public class CommentCreateUseCase {
private final NoticeQueryService noticeQueryService;
private final CommentSaveService commentSaveService;
private final CommentQueryService commentQueryService;
private final MemberDetailQueryService memberDetailQueryService;

@Transactional
public CommentInfoResponse createComment(Long noticeId, CommentCreateRequest commentCreateRequest){
final Member member = memberUtils.getAccessMember();
final Notice notice = noticeQueryService.findByNoticeId(noticeId);
final Comment comment = CommentMapper.mapToCommentWithUserAndAlbum(commentCreateRequest.getContent(), notice, member);
final Comment comment = CommentMapper.mapToCommentWithUserAndAlbum(commentCreateRequest.getContent(), notice, member, commentCreateRequest.getIsAnonymous());
final MemberDetail memberDetail = memberDetailQueryService.findMemberDetailByMemberId(member.getId());

commentSaveService.saveComment(comment);
return CommentMapper.mapToCommentInfoResponse(comment, member);
return CommentMapper.mapToCommentInfoResponse(comment, member, memberDetail);
}

@Transactional
public CommentInfoResponse createReComment(Long noticeId, Long commentId, CommentCreateRequest commentCreateRequest){
final Member member = memberUtils.getAccessMember();
final Notice notice = noticeQueryService.findByNoticeId(noticeId);
final Comment parent = commentQueryService.getCommentById(commentId);
final Comment comment = CommentMapper.mapToCommentWithUserAndNoticeAndParent(commentCreateRequest.getContent(), notice, member, parent);
final Comment comment = CommentMapper.mapToCommentWithUserAndNoticeAndParent(commentCreateRequest.getContent(), notice, member, parent, commentCreateRequest.getIsAnonymous());
final MemberDetail memberDetail = memberDetailQueryService.findMemberDetailByMemberId(member.getId());

commentSaveService.saveComment(comment);
return CommentMapper.mapToCommentInfoResponse(comment, member);
return CommentMapper.mapToCommentInfoResponse(comment, member, memberDetail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import com.koa.coremodule.comment.domain.entity.Comment;
import com.koa.coremodule.comment.domain.service.CommentQueryService;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.entity.MemberDetail;
import com.koa.coremodule.member.domain.service.MemberDetailQueryService;
import com.koa.coremodule.member.domain.utils.MemberUtils;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -20,28 +26,60 @@
public class CommentGetUseCase {
private final CommentQueryService commentQueryService;
private final MemberUtils memberUtils;
private final MemberDetailQueryService memberDetailQueryService;

public List<CommentListResponse> getCommentList(Long noticeId){
final Member member = memberUtils.getAccessMember();
final Map<Long, List<Comment>> childCommentMap = commentQueryService.getChildCommentByNoticeId(noticeId);
final ArrayList<CommentListResponse> commentListResponses = new ArrayList<>();
List<Comment> commentList = commentQueryService.getCommentByNoticeId(noticeId);
for (Comment comment : commentList) {
final Map<Comment, MemberDetail> commentMemberDetailMap = createCommentMemberDetailMapWithNoticeId(noticeId);
for (Comment comment : commentMemberDetailMap.keySet()) {
final List<Comment> childCommentList = childCommentMap.get(comment.getId());
commentListResponses.add(new CommentListResponse(comment.getId(), comment.getContent(), comment.getWriter().getName(), comment.getCreatedAt().toString()
,childCommentList != null ? childCommentList.size() : 0, comment.getWriter().equals(member)));
commentListResponses.add(new CommentListResponse(comment.getId(), comment.getContent(), comment.getWriter().getName(),
comment.getCreatedAtByFormat() ,childCommentList != null ? childCommentList.size() : 0,
comment.getWriter().equals(member), comment.getIsAnonymous(), commentMemberDetailMap.get(comment).getProfileImage(),
comment.getWriter().getId()));
}
return commentListResponses;
}

public List<CommentInfoResponse> getReCommentList(Long commentId){
final Member member = memberUtils.getAccessMember();
final List<Comment> childCommentList = commentQueryService.getChildCommentByCommentId(commentId);
final Map<Comment, MemberDetail> childCommentMemberDetailMap = createCommentMemberDetailMapWithCommentId(commentId);
final ArrayList<CommentInfoResponse> childCommentInfoResponses = new ArrayList<>();
for (Comment comment : childCommentList) {
for (Comment comment : childCommentMemberDetailMap.keySet()) {
childCommentInfoResponses.add(new CommentInfoResponse(comment.getId(), comment.getContent()
, comment.getWriter().getName(), comment.getCreatedAt().toString(), comment.getWriter().equals(member)));
, comment.getWriter().getName(), comment.getCreatedAtByFormat(),
comment.getWriter().equals(member), comment.getIsAnonymous(),
childCommentMemberDetailMap.get(comment).getProfileImage(), comment.getWriter().getId()));
}
return childCommentInfoResponses;
}

private <T> Map<Comment, MemberDetail> createCommentMemberDetailMap(Long id, Function<Long, List<Comment>> commentGetter) {
final List<Comment> commentList = commentGetter.apply(id);
final List<Long> memberIdList = commentList.stream()
.map(comment -> comment.getWriter().getId())
.collect(Collectors.toList());
final List<MemberDetail> memberDetailList = memberDetailQueryService.findMemberDetailListByMemberIdList(memberIdList);
final Map<Long, MemberDetail> memberDetailMap = memberDetailList.stream()
.collect(Collectors.toMap(memberDetail -> memberDetail.getMember().getId(), memberDetail -> memberDetail));
final Map<Comment, MemberDetail> commentMemberDetailMap = commentList.stream()
.sorted(Comparator.comparing(Comment::getCreatedAt))
.collect(Collectors.toMap(
comment -> comment,
comment -> memberDetailMap.get(comment.getWriter().getId()),
(existing, replacement) -> existing,
LinkedHashMap::new
));
return commentMemberDetailMap;
}

public Map<Comment, MemberDetail> createCommentMemberDetailMapWithNoticeId(Long noticeId) {
return createCommentMemberDetailMap(noticeId, commentQueryService::getCommentByNoticeId);
}

public Map<Comment, MemberDetail> createCommentMemberDetailMapWithCommentId(Long commentId) {
return createCommentMemberDetailMap(commentId, commentQueryService::getChildCommentByCommentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.koa.coremodule.notice.domain.entity.Notice;
import com.koa.coremodule.member.domain.entity.Member;
import jakarta.persistence.*;
import java.time.format.DateTimeFormatter;
import lombok.*;

@Builder
Expand Down Expand Up @@ -31,7 +32,13 @@ public class Comment extends BaseEntity {
@JoinColumn(name = "parent_id")
private Comment parent;

private Boolean isAnonymous;

public Long getParentId() {
return this.parent != null ? this.parent.getId() : null;
}

public String getCreatedAtByFormat() {
return this.createdAt.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
public interface CommentRepository extends JpaRepository<Comment, Long> {


@Query("select c from Comment c where c.notice.id = :noticeId and c.parent is null order by c.createdAt asc")
@Query("select c from Comment c join fetch c.writer where c.notice.id = :noticeId and c.parent is null order by c.createdAt asc")
List<Comment> findByNoticeId(@Param("noticeId") Long noticeId);

@Query("select c from Comment c where c.notice.id = :noticeId and c.parent is not null order by c.createdAt asc")
@Query("select c from Comment c join fetch c.writer where c.notice.id = :noticeId and c.parent is not null order by c.createdAt asc")
List<Comment> findChildByNoticeId(@Param("noticeId") Long noticeId);

@Query("select c from Comment c where c.parent.id = :commentId order by c.createdAt asc")
Expand Down
Loading

0 comments on commit f2c7117

Please sign in to comment.