From 610aa07e7bf88e4f5c06b236a40082ba1ec3f7bd Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:21:09 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat=20:=20=EB=A7=B4=EB=B2=84=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=EC=99=80=20=EC=83=81=ED=83=9C=EB=A5=BC=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=EC=9C=BC=EB=A1=9C=20=EC=B0=BE=EB=8A=94=20?= =?UTF-8?q?=EB=A0=88=ED=8F=AC=EC=A7=80=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/linkode/api_server/repository/AvatarRepository.java | 3 ++- .../com/linkode/api_server/repository/MemberRepository.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/repository/AvatarRepository.java b/src/main/java/com/linkode/api_server/repository/AvatarRepository.java index b8e0ae4..9acf334 100644 --- a/src/main/java/com/linkode/api_server/repository/AvatarRepository.java +++ b/src/main/java/com/linkode/api_server/repository/AvatarRepository.java @@ -2,8 +2,9 @@ import com.linkode.api_server.domain.Avatar; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +@Repository public interface AvatarRepository extends JpaRepository { - } diff --git a/src/main/java/com/linkode/api_server/repository/MemberRepository.java b/src/main/java/com/linkode/api_server/repository/MemberRepository.java index f2b2f73..1f8fa87 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberRepository.java @@ -3,11 +3,15 @@ import com.linkode.api_server.domain.Member; import com.linkode.api_server.domain.base.BaseStatus; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.Optional; +@Repository public interface MemberRepository extends JpaRepository { boolean existsByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); Optional findByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); + Optional findByMemberIdAndStatus(long memberId, BaseStatus ACTIVE); + } From b3e416a394d66c4659c69e9126dfbc2e3cec6402 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:21:32 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat=20:=20=EB=A7=B4=EB=B2=84=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=97=90=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20+=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/linkode/api_server/domain/Member.java | 7 +++++++ .../dto/member/UpdateAvatarRequest.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/main/java/com/linkode/api_server/dto/member/UpdateAvatarRequest.java diff --git a/src/main/java/com/linkode/api_server/domain/Member.java b/src/main/java/com/linkode/api_server/domain/Member.java index 6493855..62a1634 100644 --- a/src/main/java/com/linkode/api_server/domain/Member.java +++ b/src/main/java/com/linkode/api_server/domain/Member.java @@ -68,4 +68,11 @@ public Member(String githubId, String nickname, Avatar avatar, String color, Bas this.avatar = avatar; this.status = status; } + + public void updateMemberInfo(String nickname, Avatar avatar, String color){ + this.nickname=nickname; + this.avatar=avatar; + this.color=color; + } + } diff --git a/src/main/java/com/linkode/api_server/dto/member/UpdateAvatarRequest.java b/src/main/java/com/linkode/api_server/dto/member/UpdateAvatarRequest.java new file mode 100644 index 0000000..65602ac --- /dev/null +++ b/src/main/java/com/linkode/api_server/dto/member/UpdateAvatarRequest.java @@ -0,0 +1,15 @@ +package com.linkode.api_server.dto.member; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter +@AllArgsConstructor +@NoArgsConstructor +public class UpdateAvatarRequest { + private String nickname; + private Long avatarId; + private String color; +} From 500f347ebf5570a838d45fa72c4d7b60f7d61d97 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:21:54 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat=20:=20=EB=A7=B4=EB=B2=84=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EA=B3=84=EC=B8=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 일부 값만 수정 가능하도록 추가 --- .../api_server/service/MemberService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/linkode/api_server/service/MemberService.java b/src/main/java/com/linkode/api_server/service/MemberService.java index 3b2ba2a..c27261f 100644 --- a/src/main/java/com/linkode/api_server/service/MemberService.java +++ b/src/main/java/com/linkode/api_server/service/MemberService.java @@ -6,6 +6,7 @@ import com.linkode.api_server.domain.Member; import com.linkode.api_server.domain.base.BaseStatus; import com.linkode.api_server.dto.member.CreateAvatarRequest; +import com.linkode.api_server.dto.member.UpdateAvatarRequest; import com.linkode.api_server.repository.AvatarRepository; import com.linkode.api_server.repository.MemberRepository; import lombok.RequiredArgsConstructor; @@ -43,4 +44,25 @@ public void createAvatar(CreateAvatarRequest createAvatarRequest){ memberRepository.save(member); } } + + + @Transactional + public void updateAvatar(long memberId, UpdateAvatarRequest request){ + log.info("[MemberService.updateAvatar]"); + Member member = memberRepository.findByMemberIdAndStatus(memberId,BaseStatus.ACTIVE) + .orElseThrow(()-> new IllegalArgumentException("Invalid memberId: " + memberId)); + + String newNickname= request.getNickname()==null ? member.getNickname():request.getNickname() ; + + Avatar newAvatar= request.getAvatarId()==null ? member.getAvatar() : avatarRepository.findById(request.getAvatarId()) + .orElseThrow(()-> new IllegalArgumentException("Invalid avatarId: " + request.getAvatarId())); + + String newColor= request.getColor()==null ? member.getColor(): request.getColor(); + + member.updateMemberInfo(newNickname,newAvatar,newColor); + + memberRepository.save(member); + + } + } From f76503dbbd5bf0eec5750d04ea2f68af5895c70c Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:22:29 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EA=B3=84=EC=B8=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/controller/MemberController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/linkode/api_server/controller/MemberController.java b/src/main/java/com/linkode/api_server/controller/MemberController.java index a0ae35a..984136c 100644 --- a/src/main/java/com/linkode/api_server/controller/MemberController.java +++ b/src/main/java/com/linkode/api_server/controller/MemberController.java @@ -3,6 +3,7 @@ import com.linkode.api_server.common.response.BaseResponse; import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; import com.linkode.api_server.dto.member.CreateAvatarRequest; +import com.linkode.api_server.dto.member.UpdateAvatarRequest; import com.linkode.api_server.service.MemberService; import com.linkode.api_server.util.JwtProvider; import lombok.RequiredArgsConstructor; @@ -32,4 +33,15 @@ public BaseResponse createAvatar(@RequestBody CreateAvatarRequest createAv return new BaseResponse<>(null); } + /** + * 캐릭터 수정(프로필 수정) + */ + @PatchMapping("/avatar") + public BaseResponse modifyAvatar(@RequestHeader("Authorization") String authorization, @RequestBody UpdateAvatarRequest request) { + log.info("[MemberController.modifyAvatar]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + memberService.updateAvatar(memberId, request); + return new BaseResponse<>(null); + } + }