diff --git a/layer-api/src/main/java/org/layer/domain/member/controller/MemberApi.java b/layer-api/src/main/java/org/layer/domain/member/controller/MemberApi.java new file mode 100644 index 00000000..37237344 --- /dev/null +++ b/layer-api/src/main/java/org/layer/domain/member/controller/MemberApi.java @@ -0,0 +1,17 @@ +package org.layer.domain.member.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.layer.common.annotation.MemberId; +import org.layer.domain.form.controller.dto.response.FormGetResponse; +import org.layer.domain.member.controller.dto.UpdateMemberInfoRequest; +import org.layer.domain.member.controller.dto.UpdateMemberInfoResponse; +import org.springframework.http.ResponseEntity; + +@Tag(name = "회원 서비스", description = "회원 관련 api") +public interface MemberApi { + @Operation(summary = "회원 정보(이름, 프로필 사진) 수정", method = "POST", description = "회원의 이름과 프로필 사진(url)을 수정합니다.") + ResponseEntity updateMemberInfo(@MemberId Long memberId, @Valid UpdateMemberInfoRequest updateMemberInfoRequest); + +} diff --git a/layer-api/src/main/java/org/layer/domain/member/controller/MemberController.java b/layer-api/src/main/java/org/layer/domain/member/controller/MemberController.java new file mode 100644 index 00000000..0e6211a6 --- /dev/null +++ b/layer-api/src/main/java/org/layer/domain/member/controller/MemberController.java @@ -0,0 +1,26 @@ +package org.layer.domain.member.controller; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.layer.common.annotation.MemberId; +import org.layer.domain.member.controller.dto.UpdateMemberInfoRequest; +import org.layer.domain.member.controller.dto.UpdateMemberInfoResponse; +import org.layer.domain.member.service.MemberService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RequestMapping("/api/member") +@RequiredArgsConstructor +@RestController +public class MemberController implements MemberApi { + private final MemberService memberService; + + @Override + @PatchMapping("/update-profile") + public ResponseEntity updateMemberInfo(@MemberId Long memberId, @Valid @RequestBody UpdateMemberInfoRequest updateMemberInfoRequest) { + UpdateMemberInfoResponse response = memberService.updateMemberInfo(memberId, updateMemberInfoRequest); + + return new ResponseEntity<>(response, HttpStatus.OK); + } +} diff --git a/layer-api/src/main/java/org/layer/domain/member/controller/dto/UpdateMemberInfoRequest.java b/layer-api/src/main/java/org/layer/domain/member/controller/dto/UpdateMemberInfoRequest.java new file mode 100644 index 00000000..45210a56 --- /dev/null +++ b/layer-api/src/main/java/org/layer/domain/member/controller/dto/UpdateMemberInfoRequest.java @@ -0,0 +1,14 @@ +package org.layer.domain.member.controller.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Builder; + +@Builder +@Schema(description = "변경할 회원 정보") +public record UpdateMemberInfoRequest(@NotNull + @Schema(description = "변경할 이름") + String name, + @Schema(description = "변경할 이미지 url") + String profileImageUrl) { +} diff --git a/layer-api/src/main/java/org/layer/domain/member/controller/dto/UpdateMemberInfoResponse.java b/layer-api/src/main/java/org/layer/domain/member/controller/dto/UpdateMemberInfoResponse.java new file mode 100644 index 00000000..7152c28f --- /dev/null +++ b/layer-api/src/main/java/org/layer/domain/member/controller/dto/UpdateMemberInfoResponse.java @@ -0,0 +1,16 @@ +package org.layer.domain.member.controller.dto; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Builder; + +@Builder +@Schema(description = "정보가 변경된 회원") +public record UpdateMemberInfoResponse(@NotNull + @Schema(description = "정보가 변경된 회원 ID") + Long memberId, + @NotNull + @Schema(description = "변경된 이름") + String name, + @Schema(description = "변경된 이미지 url") + String profileImageUrl) { +} diff --git a/layer-api/src/main/java/org/layer/domain/member/service/MemberService.java b/layer-api/src/main/java/org/layer/domain/member/service/MemberService.java index 886fa7c5..e9b4ebf2 100644 --- a/layer-api/src/main/java/org/layer/domain/member/service/MemberService.java +++ b/layer-api/src/main/java/org/layer/domain/member/service/MemberService.java @@ -5,11 +5,14 @@ import org.layer.common.exception.MemberExceptionType; import org.layer.domain.auth.controller.dto.SignUpRequest; import org.layer.domain.jwt.SecurityUtil; +import org.layer.domain.member.controller.dto.UpdateMemberInfoRequest; +import org.layer.domain.member.controller.dto.UpdateMemberInfoResponse; import org.layer.domain.member.entity.Member; import org.layer.domain.member.entity.SocialType; import org.layer.domain.member.repository.MemberRepository; import org.layer.oauth.dto.service.MemberInfoServiceResponse; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Optional; @@ -48,6 +51,7 @@ public void checkIsNewMember(String socialId, SocialType socialType) { } } + @Transactional public Member saveMember(SignUpRequest signUpRequest, MemberInfoServiceResponse memberInfo) { Member member = Member.builder() .name(signUpRequest.name()) @@ -74,9 +78,24 @@ public Member getMemberByMemberId(Long memberId) { .orElseThrow(() -> new BaseCustomException(NOT_FOUND_USER)); } + @Transactional public void withdrawMember(Long memberId) { Member currentMember = getCurrentMember(); memberRepository.delete(currentMember); } + + @Transactional + public UpdateMemberInfoResponse updateMemberInfo(Long memberId, UpdateMemberInfoRequest updateMemberInfoRequest) { + Member member = memberRepository.findByIdOrThrow(memberId); + member.updateName(updateMemberInfoRequest.name()); + member.updateProfileImageUrl(updateMemberInfoRequest.profileImageUrl()); + + + return UpdateMemberInfoResponse.builder() + .memberId(member.getId()) + .name(member.getName()) + .profileImageUrl(member.getProfileImageUrl()) + .build(); + } } diff --git a/layer-domain/src/main/java/org/layer/domain/form/enums/FormPublishedBy.java b/layer-domain/src/main/java/org/layer/domain/form/enums/FormPublishedBy.java index 58151fb3..6df8c9ce 100644 --- a/layer-domain/src/main/java/org/layer/domain/form/enums/FormPublishedBy.java +++ b/layer-domain/src/main/java/org/layer/domain/form/enums/FormPublishedBy.java @@ -9,7 +9,7 @@ public enum FormPublishedBy { ADMIN("관리자","0"), PERSONAL("개인","1"); - ; + private String description; private String code; diff --git a/layer-domain/src/main/java/org/layer/domain/member/entity/Member.java b/layer-domain/src/main/java/org/layer/domain/member/entity/Member.java index e4b21e06..d953b499 100644 --- a/layer-domain/src/main/java/org/layer/domain/member/entity/Member.java +++ b/layer-domain/src/main/java/org/layer/domain/member/entity/Member.java @@ -1,20 +1,12 @@ package org.layer.domain.member.entity; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.validation.Valid; +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -33,15 +25,15 @@ public class Member { @Enumerated(value = EnumType.STRING) private MemberRole memberRole; - @Valid @NotNull @Enumerated(value = EnumType.STRING) private SocialType socialType; - @Valid @NotNull private String socialId; + private String profileImageUrl; + @Builder(access = AccessLevel.PUBLIC) private Member(String name,String email, MemberRole memberRole, @@ -52,4 +44,12 @@ private Member(String name,String email, MemberRole memberRole, this.socialType = socialType; this.socialId = socialId; } + + public void updateName(String name) { + this.name = name; + } + + public void updateProfileImageUrl(String profileImageUrl) { + this.profileImageUrl = profileImageUrl; + } } diff --git a/layer-domain/src/main/java/org/layer/domain/member/repository/MemberRepository.java b/layer-domain/src/main/java/org/layer/domain/member/repository/MemberRepository.java index 94d045cb..62bd36e2 100644 --- a/layer-domain/src/main/java/org/layer/domain/member/repository/MemberRepository.java +++ b/layer-domain/src/main/java/org/layer/domain/member/repository/MemberRepository.java @@ -2,10 +2,17 @@ import org.layer.domain.member.entity.Member; import org.layer.domain.member.entity.SocialType; +import org.layer.domain.member.exception.MemberException; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; +import static org.layer.common.exception.MemberExceptionType.NOT_FOUND_USER; + public interface MemberRepository extends JpaRepository { Optional findBySocialIdAndSocialType(String socialId, SocialType socialType); + + default Member findByIdOrThrow(Long memberId) { + return findById(memberId).orElseThrow(() -> new MemberException(NOT_FOUND_USER)); + } }