Skip to content

Commit

Permalink
[FEAT]#14 회원 정보 논리 삭제 구현 성공/ 응답 부분 마무리 수정 필요
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEJaeHyeok97 committed Aug 28, 2023
1 parent 2215354 commit 1be35d5
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.rcp1.domain.user.dto.SignUpReq;
import com.example.rcp1.global.CustomAuthenticationException;
import com.example.rcp1.global.config.security.util.JwtUtil;
import io.jsonwebtoken.Jwt;
import lombok.RequiredArgsConstructor;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -72,4 +73,18 @@ public String signIn(SignInReq signInReq) {
}


// 유저 정보 논리 삭제
public String deleteUser(String token) {
String subtractedEmail = JwtUtil.getUserEmail(token, secret_key);

Optional<User> user = userRepository.findByEmail(subtractedEmail);

User tmpUser = user.get();

tmpUser.setStatusD();

userRepository.save(tmpUser);

return "finish";
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/example/rcp1/domain/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public User(Long id, String email, String password, String name, String phoneNum
}


// 논리 삭제 상태 수정
public void setStatusD() {
this.status = "D";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.rcp1.domain.user.dto;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class UpdateProfileReq {

@Email
private String email;

private String password;

private String name;

private String phoneNumber;


private String specializedField;

private Long career;

private String position;

private String school;

private String job;


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.rcp1.domain.user.domain.User;
import com.example.rcp1.domain.user.dto.SignInReq;
import com.example.rcp1.domain.user.dto.SignUpReq;
import com.example.rcp1.domain.user.dto.UpdateProfileReq;
import com.example.rcp1.global.BaseResponse;
import com.example.rcp1.global.CustomAuthenticationException;
import com.example.rcp1.global.ErrorCode;
Expand Down Expand Up @@ -42,7 +43,6 @@ public ResponseEntity<BaseResponse<User>> signUp(@Valid @RequestBody SignUpReq s
public ResponseEntity<BaseResponse<String>> signIn(@Valid @RequestBody SignInReq signInReq) {
try {
String token = userService.signIn(signInReq);
System.out.println("token = " + token);

if (token != null) {
return ResponseEntity.ok(BaseResponse.success(SuccessCode.SIGNIN_SUCCESS, token));
Expand All @@ -68,8 +68,46 @@ public ResponseEntity<String> writeReview(Authentication authentication) {
return ResponseEntity.ok().body(authentication.getName() + "님의 글작성이 완료되었습니다.");
}

@PostMapping("/write2")
public ResponseEntity<String> writeReview2(@RequestHeader("Authorization") String Authorization) {
return ResponseEntity.ok().body(Authorization + "님의 글작성이 완료되었습니다.");
}


// 유저 정보 수정
@PatchMapping("/profile")
public ResponseEntity<String> updateProfile(
@RequestHeader("Authorization") String Authorization, // 헤더에서 Authorization 값을 받아온다
@Valid @RequestBody UpdateProfileReq updateProfileReq) {
try {
String access_token = Authorization.substring(7); // Bearer 이후 토큰만 파싱
System.out.println("access_token = " + access_token);
System.out.println("test 성공!!!!");

// 토큰에서 이메일 파싱 후 이메일이랑 updateprofilereq 객체랑 같이 서비스에 보낸 후 수정처리 하는 코드

return ResponseEntity.ok().body("성공");

} catch (Exception e) {
return ResponseEntity.ok().body("실패");
// return ResponseEntity.status(HttpStatus.BAD_REQUEST)
// .body(BaseResponse.error(ErrorCode.REQUEST_VALIDATION_EXCEPTION, "유저 정보 수정에 실패했습니다."));
}

}


// 유저 정보 탈퇴(논리 삭제)
@PatchMapping("/delete")
public ResponseEntity<String> deleteUser(
@RequestHeader("Authorization") String authorization
) {
String token = authorization.substring(7);
String t = userService.deleteUser(token);


return ResponseEntity.ok().body(t);
}


}
3 changes: 2 additions & 1 deletion src/main/java/com/example/rcp1/global/SuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum SuccessCode {
// CUSTOM_SUCCESS(OK, "~ 조회에 성공했습니다."),
// CUSTOM_CREATED_SUCCESS(CREATED, "~ 생성에 성공했습니다.");
SIGNUP_SUCCESS(OK, "회원가입에 성공했습니다."),
SIGNIN_SUCCESS(OK, "로그인에 성공했습니다.");
SIGNIN_SUCCESS(OK, "로그인에 성공했습니다."),
UPDATE_PROFILE_SUCCESS(OK, "프로필이 성공적으로 수정되었습니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.csrf().disable()
.cors().and()
.authorizeHttpRequests()
.requestMatchers("/user/signUp", "/user/signIn").permitAll()
.requestMatchers("/user/signUp", "/user/signIn", "/user/delete").permitAll()
.requestMatchers(HttpMethod.POST, "/user/**").authenticated()
.and()
.sessionManagement()
Expand Down

0 comments on commit 1be35d5

Please sign in to comment.