Skip to content

Commit

Permalink
Merge pull request #30 from road-found-in-the-text/TEXTROAD-24-api-pr…
Browse files Browse the repository at this point in the history
…ofile

닉네임과 자기소개를 한꺼번에 변경하는 api 생성 및 memberId값 토큰으로 가져오도록 변경
  • Loading branch information
Youngseo-Jeon0313 authored Aug 16, 2023
2 parents 1193471 + 818187d commit f205ef5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/com/example/Back/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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<UpdateMypageRes> updateUserNickname (@RequestBody UpdateMypageReq updateMypageReq) {
UpdateMypageRes updateMypageRes = authMemberService.updateProfile(updateMypageReq);
return ResponseEntity.ok(updateMypageRes);
}

@PostMapping("/nickname") @ResponseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/example/Back/dto/request/UpdateMypageReq.java
Original file line number Diff line number Diff line change
@@ -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;

}
14 changes: 14 additions & 0 deletions src/main/java/com/example/Back/dto/response/UpdateMypageRes.java
Original file line number Diff line number Diff line change
@@ -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;

}
21 changes: 21 additions & 0 deletions src/main/java/com/example/Back/service/AuthMemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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("해당하는 멤버를 찾을 수 없습니다."));
Expand All @@ -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("해당하는 멤버를 찾을 수 없습니다."));
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/example/Back/service/ScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class ScriptService {


public ResponseEntity<?> writeScript(ScriptRequestDto.Register script1) {
String socialId = tokenService.getSocialId();
Optional<Member> optionalMember = socialMemberRepository.findMemberBySocialId(socialId);
Long memberId = optionalMember.get().getId();

// Member script_member=memberRepository.getUser(script1.getMemberId());
ArrayList<ParagraphReq> contents = script1.getContents();
Expand All @@ -53,7 +56,7 @@ public ResponseEntity<?> writeScript(ScriptRequestDto.Register script1) {
List<Paragraph> paragraphs_list = new ArrayList<Paragraph>();

Script script=Script.builder()
.memberId(script1.getMemberId())
.memberId(memberId)
.title(script1.getScript_title())
.cnt(cnt_list)
.deleted(false)
Expand Down

0 comments on commit f205ef5

Please sign in to comment.