Skip to content

Commit

Permalink
Merge pull request #19 from study-hub-inu/feat/SH-110-mypage
Browse files Browse the repository at this point in the history
Feat/sh 110 mypage
  • Loading branch information
wellbeing-dough authored Sep 19, 2023
2 parents ff85f5f + a53d6f4 commit 6b959af
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package kr.co.studyhubinu.studyhubserver.exception.user;

import kr.co.studyhubinu.studyhubserver.exception.StatusType;
import kr.co.studyhubinu.studyhubserver.exception.common.CustomException;

public class UserNicknameDuplicateException extends CustomException {
private final StatusType status;
private static final String message = "이미 사용중인 닉네임 입니다";

public UserNicknameDuplicateException() {
super(message);
this.status = StatusType.BAD_REQUEST;
}

@Override
public StatusType getStatus() {
return status;
}

@Override
public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId;
import kr.co.studyhubinu.studyhubserver.user.dto.request.SignUpRequest;
import kr.co.studyhubinu.studyhubserver.user.dto.request.SignInRequest;
import kr.co.studyhubinu.studyhubserver.user.dto.request.UpdateUserRequest;
import kr.co.studyhubinu.studyhubserver.user.dto.request.*;
import kr.co.studyhubinu.studyhubserver.user.dto.response.GetUserResponse;
import kr.co.studyhubinu.studyhubserver.user.dto.response.JwtLoginResponse;
import kr.co.studyhubinu.studyhubserver.user.service.UserService;
Expand All @@ -24,47 +22,67 @@ public class UserController {

private final UserService userService;

@Operation(summary = "회원가입")
@PostMapping("/signup")
public ResponseEntity<HttpStatus> registerUser(@Valid @RequestBody SignUpRequest request) {

userService.registerUser(request.toService());

return new ResponseEntity<>(HttpStatus.CREATED);
}

@Operation(summary = "로그인", description = "바디에 {email, password} 를 json 형식으로 보내주시면 됩니다. " +
"email 은 꼭 email 형식으로 보내주셔야 합니다")
@PostMapping("/login")
public ResponseEntity<JwtLoginResponse> login(@RequestBody SignInRequest request) {

return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "회원 정보 수정", description = "바디에 {nickname, major} 를 json 형식으로 보내주시고 jwt 토큰 bearer 헤더에" +
"보내주시면 됩니다")
@PutMapping("")
public ResponseEntity<HttpStatus> updateUser(@Valid @RequestBody UpdateUserRequest request, UserId userId) {

userService.updateUser(request.toService(userId.getId()));

return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "회원 단건 조회", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다")
@Operation(summary = "회원 단건 조회(상세정보)", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다 마이페이지에 사용됩니다")
@GetMapping("")
public ResponseEntity<GetUserResponse> getUser(UserId userId) {

GetUserResponse response = userService.getUser(userId.getId());

return new ResponseEntity<>(response, HttpStatus.OK);
}

@Operation(summary = "닉네임 중복 검사")
@GetMapping("/duplication-nickname")
public ResponseEntity<HttpStatus> nicknameDuplicationValid(@RequestParam String nickname) {
userService.nicknameDuplicationValid(nickname);
return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "닉네임 수정", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다")
@PutMapping("/nickname")
public ResponseEntity<HttpStatus> updateNickname(@Valid @RequestBody UpdateNicknameRequest request, UserId userId) {
userService.updateNickname(request.toService(userId.getId()));
return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "학과 수정", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다")
@PutMapping("/major")
public ResponseEntity<HttpStatus> updateMajor(@Valid @RequestBody UpdateMajorRequest request, UserId userId) {
userService.updateMajor(request.toService(userId.getId()));
return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "비밀번호 수정", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다")
@PutMapping("/password")
public ResponseEntity<HttpStatus> updatePassword(@Valid @RequestBody UpdatePasswordRequest request, UserId userId) {
userService.updatePassword(request.toService(userId.getId()));
return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "회원 탈퇴", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다")
@DeleteMapping
public ResponseEntity<HttpStatus> deleteUser(UserId userId) {

userService.deleteUser(userId.getId());

return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package kr.co.studyhubinu.studyhubserver.user.domain;

import kr.co.studyhubinu.studyhubserver.common.domain.BaseTimeEntity;
import kr.co.studyhubinu.studyhubserver.user.dto.data.UpdatePasswordInfo;
import kr.co.studyhubinu.studyhubserver.user.dto.data.UpdateUserInfo;
import kr.co.studyhubinu.studyhubserver.user.enums.GenderType;
import kr.co.studyhubinu.studyhubserver.user.enums.MajorType;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -35,6 +37,8 @@ public class UserEntity extends BaseTimeEntity {

private GenderType gender;

private String imageUrl;

@Builder
public UserEntity(Long id, String email, String password, String nickname, String imaUrl, MajorType major, GenderType gender) {
this.id = id;
Expand All @@ -51,4 +55,16 @@ public void update(UpdateUserInfo info) {
this.nickname = info.getNickname();
this.major = info.getMajor();
}

public void updateNickname(String nickname) {
this.nickname = nickname;
}

public void updateMajor(MajorType major) {
this.major = major;
}

public void updatePassword(UpdatePasswordInfo info, BCryptPasswordEncoder bCryptPasswordEncoder) {
this.password = bCryptPasswordEncoder.encode(info.getPassword());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kr.co.studyhubinu.studyhubserver.user.dto.data;

import kr.co.studyhubinu.studyhubserver.user.enums.MajorType;
import lombok.Builder;
import lombok.Getter;

@Getter
public class UpdateMajorInfo {
private Long userId;
private MajorType major;

@Builder
public UpdateMajorInfo(Long userId, MajorType major) {
this.userId = userId;
this.major = major;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kr.co.studyhubinu.studyhubserver.user.dto.data;

import lombok.Builder;
import lombok.Getter;

@Getter
public class UpdateNicknameInfo {
private Long userId;
private String nickname;

@Builder
public UpdateNicknameInfo(Long userId, String nickname) {
this.userId = userId;
this.nickname = nickname;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.co.studyhubinu.studyhubserver.user.dto.data;

import lombok.Builder;
import lombok.Getter;

@Getter
public class UpdatePasswordInfo {
private Long userId;
private String password;
private boolean auth;

@Builder
public UpdatePasswordInfo(Long userId, String password, boolean auth) {
this.userId = userId;
this.password = password;
this.auth = auth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Getter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

@Getter
public class SignUpRequest {
Expand All @@ -18,6 +19,10 @@ public class SignUpRequest {
private String email;

@Schema(description = "유저 비밀번호", example = "asd123")
@Pattern(
regexp = "^(?=.*[!@#$%^&*?~_]).{10,}$",
message = "비밀번호는 10자 이상이어야 하며, 하나 이상의 특수문자를 포함해야 합니다."
)
@NotBlank
private String password;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.co.studyhubinu.studyhubserver.user.dto.request;

import kr.co.studyhubinu.studyhubserver.user.dto.data.UpdateMajorInfo;
import kr.co.studyhubinu.studyhubserver.user.enums.MajorType;
import lombok.Getter;

@Getter
public class UpdateMajorRequest {

private MajorType major;

public UpdateMajorInfo toService(Long userId) {
return UpdateMajorInfo.builder()
.userId(userId)
.major(major)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kr.co.studyhubinu.studyhubserver.user.dto.request;

import kr.co.studyhubinu.studyhubserver.user.dto.data.UpdateNicknameInfo;
import lombok.Getter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

@Getter
public class UpdateNicknameRequest {

@NotBlank(message = "닉네임은 있어야 합니다")
@Size(max = 10, message = "닉네임은 10자 이하여야 합니다")
private String nickname;

public UpdateNicknameInfo toService(Long userId) {
return UpdateNicknameInfo.builder()
.userId(userId)
.nickname(nickname)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kr.co.studyhubinu.studyhubserver.user.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import kr.co.studyhubinu.studyhubserver.user.dto.data.UpdatePasswordInfo;
import lombok.Getter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

@Getter
public class UpdatePasswordRequest {

@Schema(description = "유저 비밀번호", example = "asd123")
@Pattern(
regexp = "^(?=.*[!@#$%^&*?~_]).{10,}$",
message = "비밀번호는 10자 이상이어야 하며, 하나 이상의 특수문자를 포함해야 합니다."
)
@NotBlank(message = "비밀번호는 입력하셔야 합니다")
private String password;

@Schema(description = "해당 유저가 기존 비밀번호를 확인했는지", example = "asd1242")
@NotNull(message = "접근권한이 없는 유저입니다")
private boolean auth;

public UpdatePasswordInfo toService(Long userId) {
return UpdatePasswordInfo.builder()
.userId(userId)
.password(password)
.auth(auth)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
@Getter
public class GetUserResponse {

private Long userId;
private String email;
private String nickname;
private String imaUrl;
private MajorType major;
private GenderType gender;

private String email;
private String imageUrl;

public GetUserResponse(UserEntity user) {
this.userId = user.getId();
this.email = user.getEmail();
this.nickname = user.getNickname();
this.imaUrl = user.getImaUrl();
this.major = user.getMajor();
this.gender = user.getGender();
this.email = user.getEmail();
this.imageUrl = user.getImageUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {

Optional<UserEntity> findByEmail(String email);
Optional<UserEntity> findById(Long id);

Optional<UserEntity> findByNickname(String nickname);
}
Loading

0 comments on commit 6b959af

Please sign in to comment.