Skip to content

Commit

Permalink
Merge pull request #91 from tukcomCD2024/feat#90/get-member
Browse files Browse the repository at this point in the history
  • Loading branch information
ggamD00 authored May 25, 2024
2 parents 0582f33 + 9be396e commit 79c0397
Show file tree
Hide file tree
Showing 51 changed files with 877 additions and 690 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class CommentService {

@Transactional
public void register(CommentServiceDto commentServiceDto) {
Member foundMember = memberService.findByEmail(commentServiceDto.getEmail());
Memes foundMemes = memesService.getMemesBetweenService(commentServiceDto.getMemesId());
Member foundMember = memberService.findMemberFromEmail(commentServiceDto.getEmail());
Memes foundMemes = memesService.findMemesFromMemesId(commentServiceDto.getMemesId());
foundMemes.addCommentCount();

Comment newComment = commentServiceDto.toEntity(foundMember, foundMemes);
Expand All @@ -34,7 +34,7 @@ public void register(CommentServiceDto commentServiceDto) {
@Transactional
public void delete(CommentServiceDto commentServiceDto) {
Comment foundComment = commentRepository.findById(commentServiceDto.getCommentId()).orElseThrow(NotFoundCommentException::new);
Memes foundMemes = memesService.getMemesBetweenService(foundComment.getMemes().getId());
Memes foundMemes = memesService.findMemesFromMemesId(foundComment.getMemes().getId());
foundMemes.cancelCommentCount();

commentRepository.delete(foundComment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ComplainService {

@Transactional
public void register(ComplainServiceDto complainServiceDto) {
Member foundMember = memberService.findByEmail(complainServiceDto.getEmail());
Memes foundMemes = memesService.getMemesBetweenService(complainServiceDto.getMemesId());
Member foundMember = memberService.findMemberFromEmail(complainServiceDto.getEmail());
Memes foundMemes = memesService.findMemesFromMemesId(complainServiceDto.getMemesId());

Complain newComplain = complainServiceDto.toEntity(foundMember, foundMemes);
complainRepository.save(newComplain);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public class LikeServiceDto {
private Long memesId;
private String email;

public static LikeServiceDto create(String email, Long memesId) {
public static LikeServiceDto fromEmailAndMemesId(String email, Long memesId) {
return LikeServiceDto.builder()
.email(email)
.memesId(memesId)
.build();
}

public Like toEntity(Member member, Memes memes) {
public Like toEntityFromMemberAndMemes(Member member, Memes memes) {
return Like.builder()
.member(member)
.memes(memes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.memetory.domain.like.exception;

import com.example.memetory.global.exception.BusinessException;
import com.example.memetory.global.response.ErrorCode;

public class NotCreateLikeException extends BusinessException {

public NotCreateLikeException() {
super(ErrorCode.LIKE_NOT_CREATE);
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
package com.example.memetory.domain.like.service;

import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.memetory.domain.like.dto.LikeServiceDto;
import com.example.memetory.domain.like.entity.Like;
import com.example.memetory.domain.like.exception.NotCreateLikeException;
import com.example.memetory.domain.like.exception.NotFoundLikeException;
import com.example.memetory.domain.like.repository.LikeRepository;
import com.example.memetory.domain.member.entity.Member;
import com.example.memetory.domain.member.service.MemberService;
import com.example.memetory.domain.memes.entity.Memes;
import com.example.memetory.domain.memes.service.MemesService;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class LikeService {

private final MemberService memberService;
private final MemesService memesService;
private final LikeRepository likeRepository;

@Transactional
public void register(LikeServiceDto likeServiceDto) {
Member member = memberService.findByEmail(likeServiceDto.getEmail());
Memes memes = memesService.getMemesBetweenService(likeServiceDto.getMemesId());
memes.addLikeCount();

Like newLike = likeServiceDto.toEntity(member, memes);
likeRepository.save(newLike);
}

@Transactional
public void cancel(LikeServiceDto likeServiceDto) {
Member member = memberService.findByEmail(likeServiceDto.getEmail());
Memes memes = memesService.getMemesBetweenService(likeServiceDto.getMemesId());
memes.cancelLikeCount();

Like like = likeRepository.findLikeByMemberAndMemes(member, memes).orElseThrow(NotFoundLikeException::new);

likeRepository.delete(like);
}
private final MemberService memberService;
private final MemesService memesService;
private final LikeRepository likeRepository;

@Transactional
public void registerLike(LikeServiceDto likeServiceDto) {
Member member = memberService.findMemberFromEmail(likeServiceDto.getEmail());
Memes memes = memesService.findMemesFromMemesId(likeServiceDto.getMemesId());

Like newLike = likeServiceDto.toEntityFromMemberAndMemes(member, memes);
saveLike(newLike);
memes.addLikeCount();
}

private void saveLike(Like like) {
try {
likeRepository.save(like);
} catch (DataIntegrityViolationException e) {
throw new NotCreateLikeException();
}
}

@Transactional
public void cancelLike(LikeServiceDto likeServiceDto) {
Member member = memberService.findMemberFromEmail(likeServiceDto.getEmail());
Memes memes = memesService.findMemesFromMemesId(likeServiceDto.getMemesId());
Like like = likeRepository.findLikeByMemberAndMemes(member, memes).orElseThrow(NotFoundLikeException::new);

likeRepository.delete(like);
memes.cancelLikeCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.http.ResponseEntity;

import com.example.memetory.domain.member.dto.MemberUpdateDto;
import com.example.memetory.domain.member.dto.request.MemberUpdateRequest;
import com.example.memetory.global.response.ResultResponse;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -30,5 +30,13 @@ public interface MemberApi {
description = "닉네임 중복"
)}
)
ResponseEntity<ResultResponse> updateMember(@Parameter(hidden = true) String email, MemberUpdateDto memberUpdateDto);
ResponseEntity<ResultResponse> updateMember(@Parameter(hidden = true) String email,
MemberUpdateRequest memberUpdateRequest);

@Operation(
summary = "단일 멤버 조회",
description = "로그인한 멤버의 프로필을 조회하기 위한 용도",
security = {@SecurityRequirement(name = "access_token")}
)
ResponseEntity<ResultResponse> findMember(@Parameter(hidden = true) String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import static com.example.memetory.global.response.ResultCode.*;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
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;

import com.example.memetory.domain.member.dto.MemberServiceDto;
import com.example.memetory.domain.member.dto.MemberUpdateDto;
import com.example.memetory.domain.member.dto.request.MemberUpdateRequest;
import com.example.memetory.domain.member.dto.response.MemberResponse;
import com.example.memetory.domain.member.service.MemberService;
import com.example.memetory.global.annotation.LoginMemberEmail;
import com.example.memetory.global.response.ResultResponse;
Expand All @@ -24,11 +26,20 @@ public class MemberController implements MemberApi {

@PostMapping
public ResponseEntity<ResultResponse> updateMember(@LoginMemberEmail String email,
@RequestBody MemberUpdateDto memberUpdateDto) {
MemberServiceDto memberServiceDto = memberUpdateDto.toServiceDto(email);
@RequestBody MemberUpdateRequest memberUpdateRequest) {
MemberServiceDto memberServiceDto = memberUpdateRequest.toServiceDtoFromEmail(email);

memberService.update(memberServiceDto);
MemberResponse response = memberService.updateMember(memberServiceDto);

return ResponseEntity.ok(ResultResponse.of(UPDATE_MEMBER_SUCCESS));
return ResponseEntity.ok(ResultResponse.of(UPDATE_MEMBER_SUCCESS, response));
}

@GetMapping
public ResponseEntity<ResultResponse> findMember(@LoginMemberEmail String email) {
MemberServiceDto memberServiceDto = MemberServiceDto.createFromEmail(email);

MemberResponse response = memberService.findMemberResponse(memberServiceDto);

return ResponseEntity.ok(ResultResponse.of(GET_MEMBER_SUCCESS, response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ public class MemberServiceDto {
private String email;
private String nickname;
private String imageUrl;

public static MemberServiceDto createFromEmail(String email) {
return MemberServiceDto.builder()
.email(email)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.example.memetory.domain.member.dto;
package com.example.memetory.domain.member.dto.request;

import com.example.memetory.domain.member.dto.MemberServiceDto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
Expand All @@ -10,13 +12,13 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
@Schema(description = "멤버 업데이트 포맷")
public class MemberUpdateDto {
public class MemberUpdateRequest {
@Schema(description = "변경할 닉네임")
private String nickname;
@Schema(description = "변경할 이미지 S3 Url")
private String imageUrl;

public MemberServiceDto toServiceDto(String email) {
public MemberServiceDto toServiceDtoFromEmail(String email) {
return MemberServiceDto.builder()
.email(email)
.nickname(this.nickname)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.memetory.domain.member.dto;
package com.example.memetory.domain.member.dto.response;

import java.time.LocalDateTime;

Expand All @@ -14,19 +14,22 @@
public class MemberResponse {
private Long memberId;
private String nickName;
private String imageUrl;
private LocalDateTime createdAt;

@Builder
public MemberResponse(Long memberId, String nickName, LocalDateTime createdAt) {
public MemberResponse(Long memberId, String nickName, String imageUrl, LocalDateTime createdAt) {
this.memberId = memberId;
this.nickName = nickName;
this.imageUrl = imageUrl;
this.createdAt = createdAt;
}

public static MemberResponse of(Member member) {
return MemberResponse.builder()
.memberId(member.getId())
.nickName(member.getNickname())
.imageUrl(member.getImageUrl())
.createdAt(member.getCreatedAt())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface MemberQueryRepository {

Optional<Member> findByEmail(String email);

boolean existsMemberByNickname(String email);
boolean existMemberByNickname(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Optional<Member> findByEmail(String email) {
}

@Override
public boolean existsMemberByNickname(String nickname) {
public boolean existMemberByNickname(String nickname) {
return jpaQueryFactory.selectFrom(member).where(member.nickname.eq(nickname)).fetchOne() != null;
}
}
Loading

0 comments on commit 79c0397

Please sign in to comment.