From 389685e8adcb3a10ecc369283b028db3aca91845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=9C=EB=A0=B9?= Date: Wed, 31 Jul 2024 12:14:02 +0900 Subject: [PATCH 1/4] =?UTF-8?q?featrue:=20=EA=B3=B5=EC=9C=A0=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=20=EC=B0=B8=EC=97=AC=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShareGroupController.java | 9 ++++++ .../converter/ShareGroupConverter.java | 8 +++++ .../shareGroup/dto/ShareGroupRequest.java | 11 +++++++ .../shareGroup/dto/ShareGroupResponse.java | 8 +++++ .../domain/shareGroup/entity/Profile.java | 7 ++--- .../shareGroup/service/ShareGroupService.java | 1 + .../service/ShareGroupServiceImpl.java | 31 +++++++++++++++++++ .../error/code/ShareGroupErrorCode.java | 3 ++ .../result/code/ShareGroupResultCode.java | 4 ++- 9 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java b/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java index 8c13a8c..896d95c 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java @@ -55,4 +55,13 @@ public ResultResponse getShareGroupInfo(@Path ShareGroupConverter.toShareGroupDetailInfoDTO(shareGroup, profileList)); } + @PostMapping("/join") + @Operation(summary = "공유그룹 참여 API", description = "특정 공유그룹에 참여하는 API입니다.") + public ResultResponse joinShareGroup(@Valid @RequestBody ShareGroupRequest.joinShareGroupRequest request, + @LoginMember Member member) { + ShareGroup shareGroup = shareGroupService.joinShareGroup(request.getShareGroupId(), request.getProfileId(), member.getId()); + return ResultResponse.of(ShareGroupResultCode.JOIN_SHARE_GROUP, + ShareGroupConverter.toJoinShareGroupInfoDTO(shareGroup)); + } + } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java b/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java index 3ca2e68..9d3c66b 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java @@ -29,6 +29,13 @@ public static ShareGroupResponse.ShareGroupInfo toShareGroupInfoDTO(ShareGroup s .build(); } + // 그룹 참여 시 반환하는 DTO + public static ShareGroupResponse.JoinShareGroupInfo toJoinShareGroupInfoDTO(ShareGroup shareGroup) { + return ShareGroupResponse.JoinShareGroupInfo.builder() + .shareGroupId(shareGroup.getId()) + .build(); + } + // 조회 시, 디테일한 그룹 정보를 반환하는 DTO public static ShareGroupResponse.ShareGroupInfo toShareGroupDetailInfoDTO(ShareGroup shareGroup, List profiles) { List profileInfoList = profiles.stream() @@ -45,6 +52,7 @@ public static ShareGroupResponse.ShareGroupInfo toShareGroupDetailInfoDTO(ShareG .build(); } + // profile 정보 반환 DTO public static ShareGroupResponse.ProfileInfo toProfileInfo(Profile profile) { return ShareGroupResponse.ProfileInfo.builder() .profileId(profile.getId()) diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java index cf62e8e..6282abe 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java @@ -27,4 +27,15 @@ public static class createShareGroupRequest { private String place; } + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class joinShareGroupRequest { + @NotNull(message = "공유그룹 ID를 입력해야 합니다.") + private Long shareGroupId; + @NotNull(message = "프로필 ID를 입력해야 합니다.") + private Long profileId; + } + } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java index 72d2d19..84eb3bd 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java @@ -27,6 +27,14 @@ public static class ShareGroupInfo { private LocalDateTime createdAt; } + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class JoinShareGroupInfo { + private Long shareGroupId; + } + @Getter @Builder @NoArgsConstructor diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java b/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java index 419320e..dbb3bee 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java @@ -13,11 +13,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.SQLRestriction; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -29,6 +25,7 @@ @Table(name = "profiles") @SQLRestriction("deleted_at is NULL") @Getter +@Setter @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java index 4e5da9b..a9d0ff1 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java @@ -11,4 +11,5 @@ public interface ShareGroupService { ShareGroup createShareGroup(ShareGroupRequest.createShareGroupRequest request, Member member); ShareGroup findShareGroup(Long shareGroupId); List findProfileList(Long shareGroupId); + ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Long memberId); } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java index 9c7c285..aaecad1 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java @@ -1,6 +1,7 @@ package com.umc.naoman.domain.shareGroup.service; import com.umc.naoman.domain.member.entity.Member; +import com.umc.naoman.domain.member.repository.MemberRepository; import com.umc.naoman.domain.shareGroup.converter.ShareGroupConverter; import com.umc.naoman.domain.shareGroup.dto.ShareGroupRequest; import com.umc.naoman.domain.shareGroup.entity.Profile; @@ -9,6 +10,7 @@ import com.umc.naoman.domain.shareGroup.repository.ProfileRepository; import com.umc.naoman.domain.shareGroup.repository.ShareGroupRepository; import com.umc.naoman.global.error.BusinessException; +import com.umc.naoman.global.error.code.MemberErrorCode; import com.umc.naoman.global.error.code.ShareGroupErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -25,6 +27,7 @@ public class ShareGroupServiceImpl implements ShareGroupService { private final ShareGroupRepository shareGroupRepository; private final ProfileRepository profileRepository; + private final MemberRepository memberRepository; @Transactional @Override @@ -59,6 +62,34 @@ public ShareGroup createShareGroup(ShareGroupRequest.createShareGroupRequest req return savedShareGroup; } + @Transactional + @Override + public ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Long memberId) { + + ShareGroup shareGroup = findShareGroup(shareGroupId); + + //Profile 객체 + Profile profile = profileRepository.findById(profileId) + .orElseThrow(() -> new BusinessException(ShareGroupErrorCode.PROFILE_NOT_FOUND)); + + //공유그룹에 해당 profile이 존재하지 않으면 + if (!profile.getShareGroup().getId().equals(shareGroupId)) { + throw new BusinessException(ShareGroupErrorCode.INVALID_PROFILE_FOR_GROUP); + } + + //Member 객체 (현재 로그인된 본인 id) + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new BusinessException(MemberErrorCode.MEMBER_NOT_FOUND_BY_MEMBER_ID)); + + //해당 멤버(본인)을 선택한 profile에 세팅, 저장 + profile.setMember(member); + profile.setJoinedAt(LocalDateTime.now()); + + profileRepository.save(profile); + + return shareGroup; + } + @Override public ShareGroup findShareGroup(Long shareGroupId) { return shareGroupRepository.findById(shareGroupId) diff --git a/src/main/java/com/umc/naoman/global/error/code/ShareGroupErrorCode.java b/src/main/java/com/umc/naoman/global/error/code/ShareGroupErrorCode.java index 2f0a6b3..a67406a 100644 --- a/src/main/java/com/umc/naoman/global/error/code/ShareGroupErrorCode.java +++ b/src/main/java/com/umc/naoman/global/error/code/ShareGroupErrorCode.java @@ -14,6 +14,9 @@ public enum ShareGroupErrorCode implements ErrorCode { SHARE_GROUP_NOT_FOUND(404, "EG005", "공유 그룹을 찾을 수 없습니다."), + PROFILE_NOT_FOUND(404, "EG006", "프로필을 찾을 수 없습니다."), + INVALID_PROFILE_FOR_GROUP(400, "EG007", "해당 프로필은 이 공유 그룹에 속하지 않습니다."), + ; private final int status; diff --git a/src/main/java/com/umc/naoman/global/result/code/ShareGroupResultCode.java b/src/main/java/com/umc/naoman/global/result/code/ShareGroupResultCode.java index b7fb76c..a889a21 100644 --- a/src/main/java/com/umc/naoman/global/result/code/ShareGroupResultCode.java +++ b/src/main/java/com/umc/naoman/global/result/code/ShareGroupResultCode.java @@ -8,7 +8,9 @@ @RequiredArgsConstructor public enum ShareGroupResultCode implements ResultCode { CREATE_SHARE_GROUP(200, "SG001", "성공적으로 공유 그룹을 생성하였습니다."), - SHARE_GROUP_INFO(200, "SG002", "공유 그룹을 성공적으로 조회했습니다.") + SHARE_GROUP_INFO(200, "SG002", "공유 그룹을 성공적으로 조회했습니다."), + JOIN_SHARE_GROUP(200, "SG003", "성공적으로 공유 그룹에 참여했습니다." ) + ; private final int status; private final String code; From 3e927958691c9de6a42a77d8562a2c3bb7585b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=9C=EB=A0=B9?= Date: Wed, 31 Jul 2024 20:06:02 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EB=A6=AC=EB=B7=B0=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShareGroupController.java | 4 +-- .../converter/ShareGroupConverter.java | 4 +-- .../shareGroup/dto/ShareGroupRequest.java | 2 +- .../shareGroup/dto/ShareGroupResponse.java | 2 +- .../domain/shareGroup/entity/Profile.java | 9 ++++-- .../shareGroup/service/ShareGroupService.java | 3 +- .../service/ShareGroupServiceImpl.java | 28 +++++++++++-------- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java b/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java index 896d95c..c4d8ec7 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/controller/ShareGroupController.java @@ -57,9 +57,9 @@ public ResultResponse getShareGroupInfo(@Path @PostMapping("/join") @Operation(summary = "공유그룹 참여 API", description = "특정 공유그룹에 참여하는 API입니다.") - public ResultResponse joinShareGroup(@Valid @RequestBody ShareGroupRequest.joinShareGroupRequest request, + public ResultResponse joinShareGroup(@Valid @RequestBody ShareGroupRequest.JoinShareGroupRequest request, @LoginMember Member member) { - ShareGroup shareGroup = shareGroupService.joinShareGroup(request.getShareGroupId(), request.getProfileId(), member.getId()); + ShareGroup shareGroup = shareGroupService.joinShareGroup(request.getShareGroupId(), request.getProfileId(), member); return ResultResponse.of(ShareGroupResultCode.JOIN_SHARE_GROUP, ShareGroupConverter.toJoinShareGroupInfoDTO(shareGroup)); } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java b/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java index 9d3c66b..055a952 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/converter/ShareGroupConverter.java @@ -30,8 +30,8 @@ public static ShareGroupResponse.ShareGroupInfo toShareGroupInfoDTO(ShareGroup s } // 그룹 참여 시 반환하는 DTO - public static ShareGroupResponse.JoinShareGroupInfo toJoinShareGroupInfoDTO(ShareGroup shareGroup) { - return ShareGroupResponse.JoinShareGroupInfo.builder() + public static ShareGroupResponse.ShareGroupId toJoinShareGroupInfoDTO(ShareGroup shareGroup) { + return ShareGroupResponse.ShareGroupId.builder() .shareGroupId(shareGroup.getId()) .build(); } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java index 6282abe..29a29eb 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupRequest.java @@ -31,7 +31,7 @@ public static class createShareGroupRequest { @Builder @NoArgsConstructor @AllArgsConstructor - public static class joinShareGroupRequest { + public static class JoinShareGroupRequest { @NotNull(message = "공유그룹 ID를 입력해야 합니다.") private Long shareGroupId; @NotNull(message = "프로필 ID를 입력해야 합니다.") diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java index 84eb3bd..242b1a8 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/dto/ShareGroupResponse.java @@ -31,7 +31,7 @@ public static class ShareGroupInfo { @Builder @NoArgsConstructor @AllArgsConstructor - public static class JoinShareGroupInfo { + public static class ShareGroupId { private Long shareGroupId; } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java b/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java index dbb3bee..3beca0c 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java @@ -13,7 +13,12 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.hibernate.annotations.SQLRestriction; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -21,7 +26,6 @@ import java.time.LocalDateTime; @Entity -@EntityListeners(AuditingEntityListener.class) @Table(name = "profiles") @SQLRestriction("deleted_at is NULL") @Getter @@ -45,7 +49,6 @@ public class Profile { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "share_group_id") private ShareGroup shareGroup; - @CreatedDate @Column(name = "joined_at", nullable = false, updatable = false) private LocalDateTime joinedAt; @Column(name = "deleted_at") diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java index a9d0ff1..c91006d 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupService.java @@ -11,5 +11,6 @@ public interface ShareGroupService { ShareGroup createShareGroup(ShareGroupRequest.createShareGroupRequest request, Member member); ShareGroup findShareGroup(Long shareGroupId); List findProfileList(Long shareGroupId); - ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Long memberId); + ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Member member); + Profile findProfile(Long profileId); } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java index aaecad1..158ddcf 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java @@ -64,27 +64,20 @@ public ShareGroup createShareGroup(ShareGroupRequest.createShareGroupRequest req @Transactional @Override - public ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Long memberId) { + public ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Member member) { ShareGroup shareGroup = findShareGroup(shareGroupId); - //Profile 객체 - Profile profile = profileRepository.findById(profileId) - .orElseThrow(() -> new BusinessException(ShareGroupErrorCode.PROFILE_NOT_FOUND)); + //repo에서 Profile 객체 꺼내오기 + Profile profile = findProfile(profileId); //공유그룹에 해당 profile이 존재하지 않으면 if (!profile.getShareGroup().getId().equals(shareGroupId)) { throw new BusinessException(ShareGroupErrorCode.INVALID_PROFILE_FOR_GROUP); } - //Member 객체 (현재 로그인된 본인 id) - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new BusinessException(MemberErrorCode.MEMBER_NOT_FOUND_BY_MEMBER_ID)); - //해당 멤버(본인)을 선택한 profile에 세팅, 저장 - profile.setMember(member); - profile.setJoinedAt(LocalDateTime.now()); - + setMemberAndJoinedAt(profile, member, LocalDateTime.now()); profileRepository.save(profile); return shareGroup; @@ -100,4 +93,15 @@ public ShareGroup findShareGroup(Long shareGroupId) { public List findProfileList(Long shareGroupId) { return profileRepository.findByShareGroupId(shareGroupId); } -} + + @Override + public Profile findProfile(Long profileId) { + return profileRepository.findById(profileId) + .orElseThrow(() -> new BusinessException(ShareGroupErrorCode.PROFILE_NOT_FOUND)); + } + + private void setMemberAndJoinedAt(Profile profile, Member member, LocalDateTime joinedAt) { + profile.setMember(member); + profile.setJoinedAt(joinedAt); + } +} \ No newline at end of file From 77568a3dea8e5b586a9264312faa390e8f5442da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=9C=EB=A0=B9?= Date: Wed, 31 Jul 2024 20:18:09 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20Profile=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=9D=98=20image=EB=A5=BC=20member=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EB=A1=9C=EB=B6=80=ED=84=B0=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8F=84=EB=A1=9D=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naoman/domain/shareGroup/service/ShareGroupServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java index 158ddcf..62a904b 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java @@ -103,5 +103,6 @@ public Profile findProfile(Long profileId) { private void setMemberAndJoinedAt(Profile profile, Member member, LocalDateTime joinedAt) { profile.setMember(member); profile.setJoinedAt(joinedAt); + profile.setImage(member.getImage()); } } \ No newline at end of file From 8577b2488c96033e5e924be9910f47b7852c6fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=9C=EB=A0=B9?= Date: Wed, 31 Jul 2024 20:29:43 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20setter=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/shareGroup/entity/Profile.java | 23 ++++++------------- .../service/ShareGroupServiceImpl.java | 7 +----- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java b/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java index 5787b75..29e4e67 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/entity/Profile.java @@ -1,27 +1,13 @@ package com.umc.naoman.domain.shareGroup.entity; import com.umc.naoman.domain.member.entity.Member; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.annotations.SQLRestriction; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; @@ -29,7 +15,6 @@ @Table(name = "profiles") @SQLRestriction("deleted_at is NULL") @Getter -@Setter @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -58,4 +43,10 @@ public class Profile { public void delete() { this.deletedAt = LocalDateTime.now(); } + + public void setInfo(Member member) { + this.member = member; + this.image = member.getImage(); + this.joinedAt = LocalDateTime.now(); + } } diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java index 62a904b..8e9090a 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/service/ShareGroupServiceImpl.java @@ -77,7 +77,7 @@ public ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Member membe } //해당 멤버(본인)을 선택한 profile에 세팅, 저장 - setMemberAndJoinedAt(profile, member, LocalDateTime.now()); + profile.setInfo(member); profileRepository.save(profile); return shareGroup; @@ -100,9 +100,4 @@ public Profile findProfile(Long profileId) { .orElseThrow(() -> new BusinessException(ShareGroupErrorCode.PROFILE_NOT_FOUND)); } - private void setMemberAndJoinedAt(Profile profile, Member member, LocalDateTime joinedAt) { - profile.setMember(member); - profile.setJoinedAt(joinedAt); - profile.setImage(member.getImage()); - } } \ No newline at end of file