diff --git a/build.gradle b/build.gradle index 66ced5b..f298f7b 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok:1.18.20' annotationProcessor 'org.projectlombok:lombok:1.18.20' - runtimeOnly 'com.mysql:mysql-connector-j' - testImplementation 'org.springframework.boot:spring-boot-starter-test' + runtimeOnly 'mysql:mysql-connector-java' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' compileOnly 'org.projectlombok:lombok' diff --git a/src/main/java/com/example/Back/controller/MemberController.java b/src/main/java/com/example/Back/controller/MemberController.java index 3ef4877..94897a0 100644 --- a/src/main/java/com/example/Back/controller/MemberController.java +++ b/src/main/java/com/example/Back/controller/MemberController.java @@ -2,8 +2,10 @@ import com.example.Back.domain.CurrentUser; import com.example.Back.domain.Member; +import com.example.Back.dto.request.UpdateMypageReq; import com.example.Back.dto.request.UpdateNickNameReq; import com.example.Back.dto.response.MemberRes; +import com.example.Back.dto.response.UpdateMypageRes; import com.example.Back.service.AuthMemberService; import com.example.Back.service.TokenService; import io.swagger.v3.oas.annotations.Operation; @@ -27,17 +29,11 @@ public MemberController(TokenService tokenService, AuthMemberService authMemberS this.authMemberService = authMemberService; } - @PutMapping("/nickname") @ResponseBody - @Operation(summary = "닉네임 변경", security = @SecurityRequirement(name = "bearer-key")) - public ResponseEntity updateUserNickname (@RequestBody UpdateNickNameReq updateNickNameReq) { - try { - String nickName = updateNickNameReq.getNickname(); - String memberId = tokenService.getSocialId(); - authMemberService.updateNickName(memberId, nickName); - return ResponseEntity.ok(nickName); - } catch (IllegalArgumentException e) { - return ResponseEntity.badRequest().body(e.getMessage()); - } + @PutMapping("/profile") @ResponseBody + @Operation(summary = "닉네임 및 자기소개 변경", security = @SecurityRequirement(name = "bearer-key")) + public ResponseEntity updateUserNickname (@RequestBody UpdateMypageReq updateMypageReq) { + UpdateMypageRes updateMypageRes = authMemberService.updateProfile(updateMypageReq); + return ResponseEntity.ok(updateMypageRes); } @PostMapping("/nickname") @ResponseBody diff --git a/src/main/java/com/example/Back/dto/request/ScriptRequestDto.java b/src/main/java/com/example/Back/dto/request/ScriptRequestDto.java index 58e7b06..12ee025 100644 --- a/src/main/java/com/example/Back/dto/request/ScriptRequestDto.java +++ b/src/main/java/com/example/Back/dto/request/ScriptRequestDto.java @@ -12,10 +12,6 @@ public class ScriptRequestDto { @Getter @Setter public static class Register { - - // @NotNull(message = "member id는 필수 입력값입니다.") - private Long memberId; - @NotNull(message = "title은 필수 입력값입니다.") private String script_title; diff --git a/src/main/java/com/example/Back/dto/request/UpdateMypageReq.java b/src/main/java/com/example/Back/dto/request/UpdateMypageReq.java new file mode 100644 index 0000000..eaeeab6 --- /dev/null +++ b/src/main/java/com/example/Back/dto/request/UpdateMypageReq.java @@ -0,0 +1,20 @@ +package com.example.Back.dto.request; + +import javax.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class UpdateMypageReq { + @Size(min = 1, max = 30, message = "이름이 입력되지 않았거나 너무 긴 이름입니다.") + private String nickname; + + @Size(min = 1, max = 150, message = "소개말이 입력되지 않았거나 너무 긴 소개말입니다.") + private String introduction; + +} diff --git a/src/main/java/com/example/Back/dto/response/UpdateMypageRes.java b/src/main/java/com/example/Back/dto/response/UpdateMypageRes.java new file mode 100644 index 0000000..f8b7a16 --- /dev/null +++ b/src/main/java/com/example/Back/dto/response/UpdateMypageRes.java @@ -0,0 +1,14 @@ +package com.example.Back.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class UpdateMypageRes { + private String nickName; + private String intro; + +} diff --git a/src/main/java/com/example/Back/service/AuthMemberService.java b/src/main/java/com/example/Back/service/AuthMemberService.java index 715319a..0ab0e6f 100644 --- a/src/main/java/com/example/Back/service/AuthMemberService.java +++ b/src/main/java/com/example/Back/service/AuthMemberService.java @@ -3,13 +3,16 @@ import com.example.Back.domain.*; import com.example.Back.dto.request.AuthReq; +import com.example.Back.dto.request.UpdateMypageReq; import com.example.Back.dto.response.AuthRes; import com.example.Back.dto.response.MemberRes; +import com.example.Back.dto.response.UpdateMypageRes; import com.example.Back.repository.SocialMemberRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -90,6 +93,18 @@ public void withdrawl(Member member){ socialMemberRepository.save(member); } + + public UpdateMypageRes updateProfile(UpdateMypageReq updateMypageReq) { + String nickName = updateMypageReq.getNickname(); + String introduction = updateMypageReq.getIntroduction(); + String memberId = tokenService.getSocialId(); + updateNickName(memberId, nickName); + updateIntroduction(memberId,introduction); + UpdateMypageRes updateMypageRes = new UpdateMypageRes(nickName, introduction); + return updateMypageRes; + } + + public void updateNickName(String memberId, String updateNickname) { Member member = socialMemberRepository.findBySocialId(memberId) .orElseThrow(() -> new IllegalArgumentException("해당하는 멤버를 찾을 수 없습니다.")); @@ -99,6 +114,12 @@ public void updateNickName(String memberId, String updateNickname) { } + public void updateIntroduction(String memberId, String updateIntro ){ + Member member = socialMemberRepository.findBySocialId(memberId) + .orElseThrow(() -> new IllegalArgumentException("해당하는 멤버를 찾을 수 없습니다.")); + member.setIntroduction(updateIntro); + socialMemberRepository.save(member); + } public MemberRes getMemberInfo(String memberId) { Member member = socialMemberRepository.findBySocialId(memberId) .orElseThrow(() -> new IllegalArgumentException("해당하는 멤버를 찾을 수 없습니다.")); diff --git a/src/main/java/com/example/Back/service/ScriptService.java b/src/main/java/com/example/Back/service/ScriptService.java index ff6b311..bb63111 100644 --- a/src/main/java/com/example/Back/service/ScriptService.java +++ b/src/main/java/com/example/Back/service/ScriptService.java @@ -45,6 +45,9 @@ public class ScriptService { public ResponseEntity writeScript(ScriptRequestDto.Register script1) { + String socialId = tokenService.getSocialId(); + Optional optionalMember = socialMemberRepository.findMemberBySocialId(socialId); + Long memberId = optionalMember.get().getId(); // Member script_member=memberRepository.getUser(script1.getMemberId()); ArrayList contents = script1.getContents(); @@ -53,7 +56,7 @@ public ResponseEntity writeScript(ScriptRequestDto.Register script1) { List paragraphs_list = new ArrayList(); Script script=Script.builder() - .memberId(script1.getMemberId()) + .memberId(memberId) .title(script1.getScript_title()) .cnt(cnt_list) .deleted(false)