Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
17d1958
feat : DTO 추가
duehee Mar 20, 2024
688ef63
Merge branch 'develop' of https://github.com/BCSDLab/KOIN_API_V2 into…
duehee Mar 20, 2024
2cd4809
feat : 유저 수정 추가
duehee Mar 23, 2024
a05f899
feat : 충돌 해결
duehee Mar 23, 2024
9a15e02
test : log.all() 삭제 및 422번 오류 삭제
duehee Mar 25, 2024
9948155
chore : update 수정 및 사용하지 않는 Request 객체 삭제
duehee Mar 25, 2024
9d03c7b
refactor : update 이름 수정
duehee Mar 25, 2024
fa1cace
refactor : DTO major 라인 포맷팅
duehee Mar 26, 2024
7c6aeb8
chore : bulider() 미사용 및 update 로직 수
duehee Mar 26, 2024
bbc8eb9
chore : 리뷰 반영 및 학부/학번 404 -> 400번 오류로 수정
duehee Mar 27, 2024
14acf71
feat : 충돌 해결
duehee Mar 27, 2024
bd1f71d
chore : ApiResponse 수정
duehee Mar 27, 2024
7e4005b
chore : 리뷰 반영
duehee Mar 28, 2024
08664cd
chore : withDetail 수정
duehee Mar 28, 2024
a631ea5
chore : 리뷰 반영(코드 스타일 및 메소드 분리)
duehee Mar 29, 2024
a0daa35
feat : 충돌 해결
duehee Mar 29, 2024
302e7dd
chore : Local 내 회원 정보 조회 오류 확인 추가
duehee Mar 29, 2024
f7df525
chore : 삼항 연산자 제거
duehee Mar 29, 2024
7cb4e31
chore : Response department null 처리 추가
duehee Mar 29, 2024
91c2de4
chore : 변수 수정 및 Gender null 처리 추가
duehee Mar 29, 2024
d64505c
chore : 변수 수정 및 department null 처리 추가
duehee Mar 29, 2024
07cf7a7
chore : DB 학과 한글 저장
duehee Mar 29, 2024
95accd0
chore : DB 저장 체크(Enumerated 삭제)
duehee Mar 29, 2024
25db4ab
chore : DB 저장 체크(Enumerated 삭제 및 model 이름 수정)
duehee Mar 29, 2024
b8e5867
chore : ENUM 사용하도록 재수정
duehee Mar 29, 2024
b592981
fix : ENUM -> STRING 사용
duehee Mar 30, 2024
fcea148
chore : 검증 ENUM으로 이동
duehee Mar 30, 2024
c13775c
chore : ENUM 영어 변수로 수정
duehee Mar 30, 2024
fe6adfb
chore : ENUM 후행 쉼표 추가
duehee Mar 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions src/main/java/in/koreatech/koin/domain/user/controller/UserApi.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package in.koreatech.koin.domain.user.controller;

import static in.koreatech.koin.domain.user.model.UserType.OWNER;
import static in.koreatech.koin.domain.user.model.UserType.STUDENT;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import in.koreatech.koin.domain.user.dto.EmailCheckExistsRequest;
import in.koreatech.koin.domain.user.dto.NicknameCheckExistsRequest;
import in.koreatech.koin.domain.user.dto.NotificationPermitRequest;
import in.koreatech.koin.domain.user.dto.NotificationStatusResponse;
import in.koreatech.koin.domain.user.dto.StudentResponse;
import in.koreatech.koin.domain.user.dto.StudentUpdateRequest;
import in.koreatech.koin.domain.user.dto.StudentUpdateResponse;
import in.koreatech.koin.domain.user.dto.UserLoginRequest;
import in.koreatech.koin.domain.user.dto.UserLoginResponse;
import in.koreatech.koin.domain.user.dto.UserTokenRefreshRequest;
import in.koreatech.koin.domain.user.dto.UserTokenRefreshResponse;

import static in.koreatech.koin.domain.user.model.UserType.OWNER;
import static in.koreatech.koin.domain.user.model.UserType.STUDENT;

import in.koreatech.koin.global.auth.Auth;
import in.koreatech.koin.domain.user.dto.NotificationPermitRequest;
import in.koreatech.koin.domain.user.dto.NotificationStatusResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -48,6 +50,23 @@ ResponseEntity<StudentResponse> getStudent(
@Auth(permit = STUDENT) Long userId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "409", content = @Content(schema = @Schema(hidden = true)))
}
)
@Operation(summary = "회원 정보 수정")
@SecurityRequirement(name = "Jwt Authentication")
@PutMapping("/user/student/me")
ResponseEntity<StudentUpdateResponse> updateStudent(
@Auth(permit = STUDENT) Long userId,
@Valid StudentUpdateRequest studentUpdateRequest
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "201"),
Expand Down Expand Up @@ -123,20 +142,6 @@ ResponseEntity<Void> checkUserEmailExist(
@Valid EmailCheckExistsRequest request
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "409", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "닉네임 중복 체크")
@GetMapping("/user/check/nickname")
ResponseEntity<Void> checkDuplicationOfNickname(
@ModelAttribute("nickname")
@Valid NicknameCheckExistsRequest request
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
Expand Down Expand Up @@ -182,4 +187,18 @@ ResponseEntity<Void> permitNotification(
ResponseEntity<Void> rejectNotification(
@Auth(permit = {STUDENT, OWNER}) Long memberId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "409", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "닉네임 중복 체크")
@GetMapping("/user/check/nickname")
ResponseEntity<Void> checkDuplicationOfNickname(
@ModelAttribute("nickname")
@Valid NicknameCheckExistsRequest request
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package in.koreatech.koin.domain.user.controller;

import static in.koreatech.koin.domain.user.model.UserType.STUDENT;

import java.net.URI;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import in.koreatech.koin.domain.user.dto.EmailCheckExistsRequest;
import in.koreatech.koin.domain.user.dto.NicknameCheckExistsRequest;
import in.koreatech.koin.domain.user.dto.StudentResponse;
import in.koreatech.koin.domain.user.dto.StudentUpdateRequest;
import in.koreatech.koin.domain.user.dto.StudentUpdateResponse;
import in.koreatech.koin.domain.user.dto.UserLoginRequest;
import in.koreatech.koin.domain.user.dto.UserLoginResponse;
import in.koreatech.koin.domain.user.dto.UserTokenRefreshRequest;
Expand Down Expand Up @@ -43,6 +48,15 @@ public ResponseEntity<StudentResponse> getStudent(
return ResponseEntity.ok().body(studentResponse);
}

@PutMapping("/user/student/me")
public ResponseEntity<StudentUpdateResponse> updateStudent(
@Auth(permit = STUDENT) Long userId,
@Valid @RequestBody StudentUpdateRequest request
) {
StudentUpdateResponse studentUpdateResponse = studentService.updateStudent(userId, request);
return ResponseEntity.ok(studentUpdateResponse);
}

@PostMapping("/user/login")
public ResponseEntity<UserLoginResponse> login(
@RequestBody @Valid UserLoginRequest request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ public record StudentResponse(
@Schema(description = "익명 닉네임", example = "익명_1676688416361")
String anonymousNickname,

@Schema(description = "이메일 주소 \n", example = "koin123@koreatech.ac.kr")
@Schema(description = "이메일 주소", example = "koin123@koreatech.ac.kr")
String email,

@Schema(description = "성별(남:0, 여:1)", example = "1")
String gender,

@Schema(description = "전공{기계공학부, 컴퓨터공학부, 메카트로닉스공학부, 전기전자통신공학부, 디자인건축공학부, 에너지신소재화학공학부, 산업경영학부}", example = "컴퓨터공학부")
@Schema(description = "전공{기계공학부, 컴퓨터공학부, 메카트로닉스공학부, 전기전자통신공학부, 디자인공학부, "
+ "건축공학부, 화학생명공학부, 에너지신소재공학부, 산업경영학부, 고용서비스정책학과}", example = "컴퓨터공학부")
String major,

@Schema(description = "이름 \n", example = "최준호")
@Schema(description = "이름", example = "최준호")
String name,

@Schema(description = "닉네임", example = "juno")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package in.koreatech.koin.domain.user.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;

@JsonNaming(value = SnakeCaseStrategy.class)
public record StudentUpdateRequest
(
@Schema(description = "성별(남:0, 여:1)", example = "1")
Integer gender,

@Schema(description = "[NOT UPDATE]신원(학생, 사장님)", example = "학생")
Integer userIdentity,

@Schema(description = "[NOT UPDATE]졸업 여부(true, false)", example = "false")
Boolean isGraduated,

@Schema(description = "전공{기계공학부, 컴퓨터공학부, 메카트로닉스공학부, 전기전자통신공학부, 디자인공학부,"
+ "건축공학부, 화학생명공학부, 에너지신소재공학부, 산업경영학부, 고용서비스정책학과}", example = "컴퓨터공학부")
String major,

@Size(max = 50, message = "이름의 길이는 최대 50자 입니다.")
@Schema(description = "이름", example = "최준호")
String name,

@Size(max = 10, message = "닉네임은 10자 이내여야 합니다.")
@Schema(description = "닉네임", example = "juno")
String nickname,

@Schema(description = "휴대폰 번호", example = "010-0000-0000")
String phoneNumber,

@Size(min = 10, max = 10, message = "학번은 10자여야 합니다.")
@Schema(description = "학번", example = "2020136065")
String studentNumber
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package in.koreatech.koin.domain.user.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.domain.user.model.Student;
import in.koreatech.koin.domain.user.model.User;
import io.swagger.v3.oas.annotations.media.Schema;

@JsonNaming(value = SnakeCaseStrategy.class)
public record StudentUpdateResponse(
@Schema(description = "익명 닉네임", example = "익명_1676688416361")
String anonymousNickname,

@Schema(description = "이메일 주소", example = "koin123@koreatech.ac.kr")
String email,

@Schema(description = "성별(남:0, 여:1)", example = "1")
Integer gender,

@Schema(description = "전공{기계공학부, 컴퓨터공학부, 메카트로닉스공학부, 전기전자통신공학부, 디자인공학부,"
+ "건축공학부, 화학생명공학부, 에너지신소재공학부, 산업경영학부, 고용서비스정책학과}", example = "컴퓨터공학부")
String major,

@Schema(description = "이름", example = "최준호")
String name,

@Schema(description = "닉네임", example = "juno")
String nickname,

@Schema(description = "휴대폰 번호", example = "010-0000-0000")
String phoneNumber,

@Schema(description = "학번", example = "2029136012")
String studentNumber
) {

public static StudentUpdateResponse from(Student student) {
User user = student.getUser();
return new StudentUpdateResponse(
student.getAnonymousNickname(),
user.getEmail(),
user.getGender().ordinal(),
student.getDepartment(),
user.getName(),
user.getNickname(),
user.getPhoneNumber(),
student.getStudentNumber()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package in.koreatech.koin.domain.user.exception;

public class StudentDepartmentNotValidException extends IllegalArgumentException {

private static final String DEFAULT_MESSAGE = "학생의 전공 형식이 아닙니다.";

public StudentDepartmentNotValidException(String message) {
super(message);
}

public static StudentDepartmentNotValidException withDetail(String detail) {
String message = String.format("%s %s", DEFAULT_MESSAGE, detail);
return new StudentDepartmentNotValidException(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package in.koreatech.koin.domain.user.exception;

public class UserGenderNotValidException extends IllegalArgumentException {

private static final String DEFAULT_MESSAGE = "잘못된 성별 인덱스입니다.";

public UserGenderNotValidException(String message) {
super(message);
}

public static UserGenderNotValidException withDetail(String detail) {
String message = String.format("%s %s", DEFAULT_MESSAGE, detail);
return new UserGenderNotValidException(message);
}
}
10 changes: 7 additions & 3 deletions src/main/java/in/koreatech/koin/domain/user/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class Student {
@Column(name = "student_number", length = 20)
private String studentNumber;

@Size(max = 50)
@Column(name = "major", length = 50)
private String department;

Expand All @@ -49,13 +48,18 @@ public class Student {
private User user;

@Builder
private Student(String anonymousNickname, String studentNumber, String department, UserIdentity userIdentity,
Boolean isGraduated, User user) {
private Student(String anonymousNickname, String studentNumber, String department,
UserIdentity userIdentity, Boolean isGraduated, User user) {
this.anonymousNickname = anonymousNickname;
this.studentNumber = studentNumber;
this.department = department;
this.userIdentity = userIdentity;
this.isGraduated = isGraduated;
this.user = user;
}

public void update(String studentNumber, String department) {
this.studentNumber = studentNumber;
this.department = department;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package in.koreatech.koin.domain.user.model;

import lombok.Getter;

@Getter
public enum StudentDepartment {
COMPUTER("컴퓨터공학부"),
MECHANICAL("기계공학부"),
MECHATRONICS("메카트로닉스공학부"),
ELECTRONIC("전기전자통신공학부"),
DESIGN("디자인공학부"),
ARCHITECTURAL("건축공학부"),
CHEMICAL("화학생명공학부"),
ENERGY("에너지신소재공학부"),
INDUSTRIAL("산업경영학부"),
EMPLOYMENT("고용서비스정책학과"),
;

private final String value;

StudentDepartment(String value) {
this.value = value;
}

public static boolean isValid(String department) {
for (StudentDepartment value : StudentDepartment.values()) {
if (value.getValue().equals(department)) {
return true;
}
}
return false;
}
}
7 changes: 7 additions & 0 deletions src/main/java/in/koreatech/koin/domain/user/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,11 @@ public void updateLastLoggedTime(LocalDateTime lastLoggedTime) {
public void updatePassword(PasswordEncoder passwordEncoder, String password) {
this.password = passwordEncoder.encode(password);
}

public void update(String nickname, String name, String phoneNumber, UserGender gender) {
this.nickname = nickname;
this.name = name;
this.phoneNumber = phoneNumber;
this.gender = gender;
}
}
14 changes: 14 additions & 0 deletions src/main/java/in/koreatech/koin/domain/user/model/UserGender.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package in.koreatech.koin.domain.user.model;

import java.util.Arrays;

import in.koreatech.koin.domain.user.exception.UserGenderNotValidException;

public enum UserGender {
MAN,
WOMAN,
;

public static UserGender from(Integer index) {
if (index == null) {
return null;
}
return Arrays.stream(values())
.filter(it -> it.ordinal() == index)
.findAny()
.orElseThrow(() -> UserGenderNotValidException.withDetail("index : " + index));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ default User getByNickname(String nickname) {
.orElseThrow(() -> UserNotFoundException.withDetail("nickname: " + nickname));
}

boolean existsByNickname(String nickname);

void delete(User user);
}
Loading