From 77e178af2dde76897fbd27ce91f702f4e63c264b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 00:47:37 +0900 Subject: [PATCH 01/15] =?UTF-8?q?refactor:=20global=20enum=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=ED=8C=8C=EC=9D=BC=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/album/entity/Album.java | 2 +- .../domain/board/entity/Board.java | 2 +- .../domain/branch/entity/Branch.java | 2 +- .../domain/inviteCode/entity/InviteCode.java | 2 +- .../domain/member/entity/Member.java | 8 +++----- .../domain/project/entity/Project.java | 2 +- .../domain/project/entity/ProjectMember.java | 2 +- .../domain/schedule/entity/Schedule.java | 2 +- .../todayILearned/entity/TodayILearned.java | 2 +- .../networkingService/global/common/Role.java | 19 ------------------- .../global/common/{ => enums}/Part.java | 2 +- .../global/common/{ => enums}/Semester.java | 2 +- 12 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 src/main/java/com/umc/networkingService/global/common/Role.java rename src/main/java/com/umc/networkingService/global/common/{ => enums}/Part.java (88%) rename src/main/java/com/umc/networkingService/global/common/{ => enums}/Semester.java (85%) diff --git a/src/main/java/com/umc/networkingService/domain/album/entity/Album.java b/src/main/java/com/umc/networkingService/domain/album/entity/Album.java index 859885ea..1f7dd5ea 100644 --- a/src/main/java/com/umc/networkingService/domain/album/entity/Album.java +++ b/src/main/java/com/umc/networkingService/domain/album/entity/Album.java @@ -2,7 +2,7 @@ import com.umc.networkingService.domain.member.entity.Member; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Semester; +import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/domain/board/entity/Board.java b/src/main/java/com/umc/networkingService/domain/board/entity/Board.java index ad75259f..33b1b82a 100644 --- a/src/main/java/com/umc/networkingService/domain/board/entity/Board.java +++ b/src/main/java/com/umc/networkingService/domain/board/entity/Board.java @@ -2,7 +2,7 @@ import com.umc.networkingService.domain.member.entity.Member; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Semester; +import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java b/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java index e4f55dd9..e71a481b 100644 --- a/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java +++ b/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java @@ -1,7 +1,7 @@ package com.umc.networkingService.domain.branch.entity; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Semester; +import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/domain/inviteCode/entity/InviteCode.java b/src/main/java/com/umc/networkingService/domain/inviteCode/entity/InviteCode.java index e5bbf377..2d478d1f 100644 --- a/src/main/java/com/umc/networkingService/domain/inviteCode/entity/InviteCode.java +++ b/src/main/java/com/umc/networkingService/domain/inviteCode/entity/InviteCode.java @@ -2,7 +2,7 @@ import com.umc.networkingService.domain.member.entity.Member; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Role; +import com.umc.networkingService.global.common.enums.Role; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java index e3584f21..0d05cf4d 100644 --- a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java +++ b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java @@ -3,12 +3,10 @@ import com.umc.networkingService.domain.branch.entity.Branch; import com.umc.networkingService.domain.university.entity.University; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Part; -import com.umc.networkingService.global.common.Role; -import com.umc.networkingService.global.common.Semester; +import com.umc.networkingService.global.common.enums.Part; +import com.umc.networkingService.global.common.enums.Role; +import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/umc/networkingService/domain/project/entity/Project.java b/src/main/java/com/umc/networkingService/domain/project/entity/Project.java index 78f10da3..dfafb6ab 100644 --- a/src/main/java/com/umc/networkingService/domain/project/entity/Project.java +++ b/src/main/java/com/umc/networkingService/domain/project/entity/Project.java @@ -1,7 +1,7 @@ package com.umc.networkingService.domain.project.entity; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Semester; +import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/domain/project/entity/ProjectMember.java b/src/main/java/com/umc/networkingService/domain/project/entity/ProjectMember.java index e8ec067f..9492385d 100644 --- a/src/main/java/com/umc/networkingService/domain/project/entity/ProjectMember.java +++ b/src/main/java/com/umc/networkingService/domain/project/entity/ProjectMember.java @@ -2,7 +2,7 @@ import com.umc.networkingService.domain.member.entity.Member; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Part; +import com.umc.networkingService.global.common.enums.Part; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/umc/networkingService/domain/schedule/entity/Schedule.java b/src/main/java/com/umc/networkingService/domain/schedule/entity/Schedule.java index e509a462..0cf8f4f9 100644 --- a/src/main/java/com/umc/networkingService/domain/schedule/entity/Schedule.java +++ b/src/main/java/com/umc/networkingService/domain/schedule/entity/Schedule.java @@ -3,7 +3,7 @@ import com.umc.networkingService.domain.board.entity.HostType; import com.umc.networkingService.domain.member.entity.Member; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Semester; +import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/domain/todayILearned/entity/TodayILearned.java b/src/main/java/com/umc/networkingService/domain/todayILearned/entity/TodayILearned.java index 4bd6a9d4..3dcb5eaf 100644 --- a/src/main/java/com/umc/networkingService/domain/todayILearned/entity/TodayILearned.java +++ b/src/main/java/com/umc/networkingService/domain/todayILearned/entity/TodayILearned.java @@ -2,7 +2,7 @@ import com.umc.networkingService.domain.member.entity.Member; import com.umc.networkingService.global.common.base.BaseEntity; -import com.umc.networkingService.global.common.Part; +import com.umc.networkingService.global.common.enums.Part; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/com/umc/networkingService/global/common/Role.java b/src/main/java/com/umc/networkingService/global/common/Role.java deleted file mode 100644 index 6b7109c5..00000000 --- a/src/main/java/com/umc/networkingService/global/common/Role.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.umc.networkingService.global.common; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Role { - ADMIN("관리자", null), - STAFF("운영진", null), - CENTERSTAFF("중앙운영진", null), - BRANCHSTAFF("지부운영진", null), - CAMPUSSTAFF("학교운영진", null), - MEMBER("챌린저", null); - - private final String toKorean; - - private final Long priority; -} diff --git a/src/main/java/com/umc/networkingService/global/common/Part.java b/src/main/java/com/umc/networkingService/global/common/enums/Part.java similarity index 88% rename from src/main/java/com/umc/networkingService/global/common/Part.java rename to src/main/java/com/umc/networkingService/global/common/enums/Part.java index 270e3b06..f58c40f7 100644 --- a/src/main/java/com/umc/networkingService/global/common/Part.java +++ b/src/main/java/com/umc/networkingService/global/common/enums/Part.java @@ -1,4 +1,4 @@ -package com.umc.networkingService.global.common; +package com.umc.networkingService.global.common.enums; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/umc/networkingService/global/common/Semester.java b/src/main/java/com/umc/networkingService/global/common/enums/Semester.java similarity index 85% rename from src/main/java/com/umc/networkingService/global/common/Semester.java rename to src/main/java/com/umc/networkingService/global/common/enums/Semester.java index 3bbd0a32..a4cb877f 100644 --- a/src/main/java/com/umc/networkingService/global/common/Semester.java +++ b/src/main/java/com/umc/networkingService/global/common/enums/Semester.java @@ -1,4 +1,4 @@ -package com.umc.networkingService.global.common; +package com.umc.networkingService.global.common.enums; import lombok.Getter; import lombok.RequiredArgsConstructor; From ef3bbcc076564893d5ee7bf3940377290b2a3b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 01:01:41 +0900 Subject: [PATCH 02/15] =?UTF-8?q?fix:=20Role=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/SecurityConfig.java | 2 +- .../global/common/enums/Role.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/umc/networkingService/global/common/enums/Role.java diff --git a/src/main/java/com/umc/networkingService/config/security/SecurityConfig.java b/src/main/java/com/umc/networkingService/config/security/SecurityConfig.java index 5a6f6f18..1a203b93 100644 --- a/src/main/java/com/umc/networkingService/config/security/SecurityConfig.java +++ b/src/main/java/com/umc/networkingService/config/security/SecurityConfig.java @@ -34,7 +34,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .httpBasic(AbstractHttpConfigurer::disable) .authorizeHttpRequests((authorizeRequests) -> authorizeRequests - .requestMatchers("/staff/**").hasAnyRole("STAFF", "CENTERSTAFF", "BRANCHSTAFF", "CAMPUSSTAFF", "ADMIN") + .requestMatchers("/staff/**").hasAnyRole("STAFF", "TOTAL_STAFF", "CENTER_STAFF", "BRANCH_STAFF", "CAMPUS_STAFF", "ADMIN") .requestMatchers("/admin/**").hasRole("ADMIN") .anyRequest().permitAll() ) diff --git a/src/main/java/com/umc/networkingService/global/common/enums/Role.java b/src/main/java/com/umc/networkingService/global/common/enums/Role.java new file mode 100644 index 00000000..9e0abdf0 --- /dev/null +++ b/src/main/java/com/umc/networkingService/global/common/enums/Role.java @@ -0,0 +1,20 @@ +package com.umc.networkingService.global.common.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Role { + ADMIN("관리자", 0), + TOTAL_STAFF("총괄운영진", 1), + CENTER_STAFF("중앙운영진", 2), + BRANCH_STAFF("지부운영진", 3), + CAMPUS_STAFF("학교운영진", 4), + STAFF("운영진", 4), + MEMBER("챌린저", 5); + + private final String toKorean; + + private final int priority; +} From 0078c5ac3c9a0d90fe463ab75f169668136dbb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 01:01:55 +0900 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20MemberPosition=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/entity/Member.java | 3 -- .../domain/member/entity/MemberPosition.java | 33 +++++++++++++++++++ .../domain/member/entity/Position.java | 21 ------------ .../domain/member/entity/PositionType.java | 13 ++++++++ 4 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java delete mode 100644 src/main/java/com/umc/networkingService/domain/member/entity/Position.java create mode 100644 src/main/java/com/umc/networkingService/domain/member/entity/PositionType.java diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java index 0d05cf4d..0c6c17d5 100644 --- a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java +++ b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java @@ -69,9 +69,6 @@ public class Member extends BaseEntity { @Column(nullable = false) private Role role; - @Enumerated(EnumType.STRING) - private Position position; - private String gitNickname; private String notionLink; diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java b/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java new file mode 100644 index 00000000..a0f2e9e6 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java @@ -0,0 +1,33 @@ +package com.umc.networkingService.domain.member.entity; + +import com.umc.networkingService.global.common.base.BaseEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLRestriction; +import org.hibernate.annotations.UuidGenerator; + +import java.util.UUID; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLRestriction("deleted_at is null") +public class MemberPosition extends BaseEntity { + + @Id + @UuidGenerator + @Column(name = "position_id") + private UUID id; + + @Column(nullable = false) + private String name; + + @Enumerated(EnumType.STRING) + private PositionType type; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private Member member; +} diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/Position.java b/src/main/java/com/umc/networkingService/domain/member/entity/Position.java deleted file mode 100644 index 91c53053..00000000 --- a/src/main/java/com/umc/networkingService/domain/member/entity/Position.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.umc.networkingService.domain.member.entity; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Position { - LEADER("회장"), - SECONDLEADER("부회장"), - MANAGER("총무"), - PMLEADER("피엠파트장"), - DESIGNLEADER("디자인파트장"), - SPRINGLEADER("스프링파트장"), - NODELEADER("노드파트장"), - WEBLEADER("웹파트장"), - IOSLEADER("아이오에스파트장"), - ANDROIDLEADER("안드로이드파트장"); - - private final String toKorean; -} diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/PositionType.java b/src/main/java/com/umc/networkingService/domain/member/entity/PositionType.java new file mode 100644 index 00000000..3098987a --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/entity/PositionType.java @@ -0,0 +1,13 @@ +package com.umc.networkingService.domain.member.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum PositionType { + CENTER("중앙"), + CAMPUS("교내"); + + private final String Korean; +} From 5656a2c9f63ad1fa310e28bddaf38a272ebe8155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 01:23:59 +0900 Subject: [PATCH 04/15] =?UTF-8?q?chore:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20API=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 26 +++++++++++++++++++ .../dto/request/MemberSignUpRequest.java | 26 +++++++++++++++++++ .../dto/response/MemberSignUpResponse.java | 12 +++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java create mode 100644 src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java create mode 100644 src/main/java/com/umc/networkingService/domain/member/dto/response/MemberSignUpResponse.java diff --git a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java new file mode 100644 index 00000000..d3daa5c0 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java @@ -0,0 +1,26 @@ +package com.umc.networkingService.domain.member.controller; + +import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; +import com.umc.networkingService.domain.member.dto.response.MemberSignUpResponse; +import com.umc.networkingService.global.common.base.BaseResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "멤버 API", description = "멤버 관련 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/members") +public class MemberController { + + @Operation(summary = "회원가입 API", description = "최초 멤버 정보를 등록하는 API입니다.") + @PostMapping + public BaseResponse signUp(@Valid @RequestBody MemberSignUpRequest request) { + return null; + } +} diff --git a/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java b/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java new file mode 100644 index 00000000..754fe8ad --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java @@ -0,0 +1,26 @@ +package com.umc.networkingService.domain.member.dto.request; + +import com.umc.networkingService.global.common.enums.Part; +import com.umc.networkingService.global.common.enums.Semester; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class MemberSignUpRequest { + @NotBlank(message = "이름은 필수 입력값입니다.") + private String name; + @NotBlank(message = "닉네임은 필수 입력값입니다.") + private String nickname; + @Size(min = 1, message = "최소 1개의 파트를 선택해야 합니다.") + private List parts; + @Size(min = 1, message = "최소 1개의 기수를 선택해야 합니다.") + private List semesters; + private String universityName; + private List campusPositions; + private List centerPositions; +} diff --git a/src/main/java/com/umc/networkingService/domain/member/dto/response/MemberSignUpResponse.java b/src/main/java/com/umc/networkingService/domain/member/dto/response/MemberSignUpResponse.java new file mode 100644 index 00000000..95146b5b --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/dto/response/MemberSignUpResponse.java @@ -0,0 +1,12 @@ +package com.umc.networkingService.domain.member.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.UUID; + +@Getter +@AllArgsConstructor +public class MemberSignUpResponse { + private UUID memberId; +} From f2921a0fb24867712741001b58e70576beaaf477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 02:14:06 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20findUniversityByName=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/UniversityRepository.java | 11 ++++++++++ .../university/service/UniversityService.java | 7 +++++++ .../service/UniversityServiceImpl.java | 20 +++++++++++++++++++ .../global/common/exception/ErrorCode.java | 5 ++++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/umc/networkingService/domain/university/repository/UniversityRepository.java create mode 100644 src/main/java/com/umc/networkingService/domain/university/service/UniversityService.java create mode 100644 src/main/java/com/umc/networkingService/domain/university/service/UniversityServiceImpl.java diff --git a/src/main/java/com/umc/networkingService/domain/university/repository/UniversityRepository.java b/src/main/java/com/umc/networkingService/domain/university/repository/UniversityRepository.java new file mode 100644 index 00000000..3f20ce5d --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/university/repository/UniversityRepository.java @@ -0,0 +1,11 @@ +package com.umc.networkingService.domain.university.repository; + +import com.umc.networkingService.domain.university.entity.University; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; +import java.util.UUID; + +public interface UniversityRepository extends JpaRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/umc/networkingService/domain/university/service/UniversityService.java b/src/main/java/com/umc/networkingService/domain/university/service/UniversityService.java new file mode 100644 index 00000000..2d52264a --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/university/service/UniversityService.java @@ -0,0 +1,7 @@ +package com.umc.networkingService.domain.university.service; + +import com.umc.networkingService.domain.university.entity.University; + +public interface UniversityService { + University findUniversityByName(String universityName); +} diff --git a/src/main/java/com/umc/networkingService/domain/university/service/UniversityServiceImpl.java b/src/main/java/com/umc/networkingService/domain/university/service/UniversityServiceImpl.java new file mode 100644 index 00000000..98cdaae4 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/university/service/UniversityServiceImpl.java @@ -0,0 +1,20 @@ +package com.umc.networkingService.domain.university.service; + +import com.umc.networkingService.domain.university.entity.University; +import com.umc.networkingService.domain.university.repository.UniversityRepository; +import com.umc.networkingService.global.common.exception.ErrorCode; +import com.umc.networkingService.global.common.exception.RestApiException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UniversityServiceImpl implements UniversityService { + + private final UniversityRepository universityRepository; + @Override + public University findUniversityByName(String universityName) { + return universityRepository.findByName(universityName) + .orElseThrow(() -> new RestApiException(ErrorCode.EMPTY_UNIVERSITY)); + } +} diff --git a/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java b/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java index 133e10e2..7cb4a3d9 100644 --- a/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java +++ b/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java @@ -32,7 +32,10 @@ public enum ErrorCode { UNSUPPORTED_JWT(HttpStatus.UNAUTHORIZED, "AUTH004", "지원하지 않는 JWT입니다."), INVALID_ID_TOKEN(HttpStatus.BAD_REQUEST, "AUTH005", "유효하지 않은 ID TOKEN입니다."), INVALID_ACCESS_TOKEN(HttpStatus.BAD_REQUEST, "AUTH006", "유효하지 않은 ACCESS TOKEN입니다."), - FAILED_SOCIAL_LOGIN(HttpStatus.INTERNAL_SERVER_ERROR, "AUTH007", "소셜 로그인에 실패하였습니다."); + FAILED_SOCIAL_LOGIN(HttpStatus.INTERNAL_SERVER_ERROR, "AUTH007", "소셜 로그인에 실패하였습니다."), + + // University + EMPTY_UNIVERSITY(HttpStatus.BAD_REQUEST, "UNIVERSITY001", "존재하지 않는 대학교입니다."); private final HttpStatus httpStatus; private final String code; From 21696ad7a194616d2d368cd77ee832371e457220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 02:21:52 +0900 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20BranchUniversity=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20isActive=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/branch/entity/BranchUniversity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java b/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java index cc0d95bc..77419486 100644 --- a/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java +++ b/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java @@ -21,6 +21,10 @@ public class BranchUniversity extends BaseEntity { @Column(name = "branch_university_id") private UUID id; + // 현재 기수인지 여부 + @Column(nullable = false) + private Boolean isActive; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn private Branch branch; From af3e65c01d66d18c82c30a56c23635af8c208282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 02:34:54 +0900 Subject: [PATCH 07/15] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../networkingService/global/common/base/EntityLoader.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/com/umc/networkingService/global/common/base/EntityLoader.java diff --git a/src/main/java/com/umc/networkingService/global/common/base/EntityLoader.java b/src/main/java/com/umc/networkingService/global/common/base/EntityLoader.java new file mode 100644 index 00000000..4965e002 --- /dev/null +++ b/src/main/java/com/umc/networkingService/global/common/base/EntityLoader.java @@ -0,0 +1,5 @@ +package com.umc.networkingService.global.common.base; + +public interface EntityLoader { + T loadEntity(ID id); +} From 5058b4bd0b4eb7c07d4183f1572d6ed0269f57ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 02:58:04 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20=EB=8C=80=ED=95=99=EA=B5=90?= =?UTF-8?q?=EB=A1=9C=20=ED=98=84=EC=9E=AC=20=EC=A7=80=EB=B6=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../branch/repository/BranchRepository.java | 9 +++++++ .../BranchUniversityRepository.java | 13 ++++++++++ .../domain/branch/service/BranchService.java | 9 +++++++ .../branch/service/BranchServiceImpl.java | 23 +++++++++++++++++ .../service/BranchUniversityService.java | 8 ++++++ .../service/BranchUniversityServiceImpl.java | 25 +++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 src/main/java/com/umc/networkingService/domain/branch/repository/BranchRepository.java create mode 100644 src/main/java/com/umc/networkingService/domain/branch/repository/BranchUniversityRepository.java create mode 100644 src/main/java/com/umc/networkingService/domain/branch/service/BranchService.java create mode 100644 src/main/java/com/umc/networkingService/domain/branch/service/BranchServiceImpl.java create mode 100644 src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityService.java create mode 100644 src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityServiceImpl.java diff --git a/src/main/java/com/umc/networkingService/domain/branch/repository/BranchRepository.java b/src/main/java/com/umc/networkingService/domain/branch/repository/BranchRepository.java new file mode 100644 index 00000000..f7e91a77 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/branch/repository/BranchRepository.java @@ -0,0 +1,9 @@ +package com.umc.networkingService.domain.branch.repository; + +import com.umc.networkingService.domain.branch.entity.Branch; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface BranchRepository extends JpaRepository { +} diff --git a/src/main/java/com/umc/networkingService/domain/branch/repository/BranchUniversityRepository.java b/src/main/java/com/umc/networkingService/domain/branch/repository/BranchUniversityRepository.java new file mode 100644 index 00000000..ee8fe0db --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/branch/repository/BranchUniversityRepository.java @@ -0,0 +1,13 @@ +package com.umc.networkingService.domain.branch.repository; + +import com.umc.networkingService.domain.branch.entity.BranchUniversity; +import com.umc.networkingService.domain.university.entity.University; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; +import java.util.UUID; + +public interface BranchUniversityRepository extends JpaRepository { + + Optional findByUniversityAndIsActive(University university, Boolean isActive); +} diff --git a/src/main/java/com/umc/networkingService/domain/branch/service/BranchService.java b/src/main/java/com/umc/networkingService/domain/branch/service/BranchService.java new file mode 100644 index 00000000..4708c39e --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/branch/service/BranchService.java @@ -0,0 +1,9 @@ +package com.umc.networkingService.domain.branch.service; + +import com.umc.networkingService.domain.branch.entity.Branch; +import com.umc.networkingService.global.common.base.EntityLoader; + +import java.util.UUID; + +public interface BranchService extends EntityLoader { +} diff --git a/src/main/java/com/umc/networkingService/domain/branch/service/BranchServiceImpl.java b/src/main/java/com/umc/networkingService/domain/branch/service/BranchServiceImpl.java new file mode 100644 index 00000000..ee67ebac --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/branch/service/BranchServiceImpl.java @@ -0,0 +1,23 @@ +package com.umc.networkingService.domain.branch.service; + +import com.umc.networkingService.domain.branch.entity.Branch; +import com.umc.networkingService.domain.branch.repository.BranchRepository; +import com.umc.networkingService.global.common.exception.ErrorCode; +import com.umc.networkingService.global.common.exception.RestApiException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BranchServiceImpl implements BranchService{ + + private final BranchRepository branchRepository; + + @Override + public Branch loadEntity(UUID id) { + return branchRepository.findById(id) + .orElseThrow(() -> new RestApiException(ErrorCode.EMPTY_BRANCH)); + } +} diff --git a/src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityService.java b/src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityService.java new file mode 100644 index 00000000..3a5599d1 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityService.java @@ -0,0 +1,8 @@ +package com.umc.networkingService.domain.branch.service; + +import com.umc.networkingService.domain.branch.entity.Branch; +import com.umc.networkingService.domain.university.entity.University; + +public interface BranchUniversityService { + Branch findBranchByUniversity(University university); +} diff --git a/src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityServiceImpl.java b/src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityServiceImpl.java new file mode 100644 index 00000000..1bb71c7e --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/branch/service/BranchUniversityServiceImpl.java @@ -0,0 +1,25 @@ +package com.umc.networkingService.domain.branch.service; + +import com.umc.networkingService.domain.branch.entity.Branch; +import com.umc.networkingService.domain.branch.repository.BranchUniversityRepository; +import com.umc.networkingService.domain.university.entity.University; +import com.umc.networkingService.global.common.exception.ErrorCode; +import com.umc.networkingService.global.common.exception.RestApiException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class BranchUniversityServiceImpl implements BranchUniversityService { + + private final BranchUniversityRepository branchUniversityRepository; + + @Override + public Branch findBranchByUniversity(University university) { + + return branchUniversityRepository.findByUniversityAndIsActive(university, Boolean.TRUE) + .orElseThrow(() -> new RestApiException(ErrorCode.EMPTY_BRANCH)) + .getBranch(); + + } +} From 1574819f7e4dea63629c7caf55b364925f91a172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 16:07:20 +0900 Subject: [PATCH 09/15] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20API=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/entity/Member.java | 9 ++ .../domain/member/entity/MemberPosition.java | 6 +- .../domain/member/mapper/MemberMapper.java | 18 +++ .../repository/MemberPositionRepository.java | 9 ++ .../domain/member/service/MemberService.java | 9 ++ .../member/service/MemberServiceImpl.java | 106 ++++++++++++++++++ .../global/common/exception/ErrorCode.java | 5 +- 7 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/umc/networkingService/domain/member/mapper/MemberMapper.java create mode 100644 src/main/java/com/umc/networkingService/domain/member/repository/MemberPositionRepository.java create mode 100644 src/main/java/com/umc/networkingService/domain/member/service/MemberService.java create mode 100644 src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java index 0c6c17d5..a6f99eff 100644 --- a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java +++ b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java @@ -1,6 +1,7 @@ package com.umc.networkingService.domain.member.entity; import com.umc.networkingService.domain.branch.entity.Branch; +import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; import com.umc.networkingService.domain.university.entity.University; import com.umc.networkingService.global.common.base.BaseEntity; import com.umc.networkingService.global.common.enums.Part; @@ -72,4 +73,12 @@ public class Member extends BaseEntity { private String gitNickname; private String notionLink; + + public void setMemberInfo(MemberSignUpRequest request, Role role, University university, Branch branch) { + this.name = request.getName(); + this.nickname = request.getNickname(); + this.role = role; + this.university = university; + this.branch = branch; + } } diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java b/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java index a0f2e9e6..b7947389 100644 --- a/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java +++ b/src/main/java/com/umc/networkingService/domain/member/entity/MemberPosition.java @@ -2,9 +2,7 @@ import com.umc.networkingService.global.common.base.BaseEntity; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.SQLRestriction; import org.hibernate.annotations.UuidGenerator; @@ -12,6 +10,8 @@ @Getter @Entity +@Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLRestriction("deleted_at is null") public class MemberPosition extends BaseEntity { diff --git a/src/main/java/com/umc/networkingService/domain/member/mapper/MemberMapper.java b/src/main/java/com/umc/networkingService/domain/member/mapper/MemberMapper.java new file mode 100644 index 00000000..1e12cd88 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/mapper/MemberMapper.java @@ -0,0 +1,18 @@ +package com.umc.networkingService.domain.member.mapper; + +import com.umc.networkingService.domain.member.entity.Member; +import com.umc.networkingService.domain.member.entity.MemberPosition; +import com.umc.networkingService.domain.member.entity.PositionType; +import org.springframework.stereotype.Component; + +@Component +public class MemberMapper { + + public MemberPosition toMemberPosition(Member member, PositionType type, String position) { + return MemberPosition.builder() + .name(position) + .member(member) + .type(type) + .build(); + } +} diff --git a/src/main/java/com/umc/networkingService/domain/member/repository/MemberPositionRepository.java b/src/main/java/com/umc/networkingService/domain/member/repository/MemberPositionRepository.java new file mode 100644 index 00000000..28715b13 --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/repository/MemberPositionRepository.java @@ -0,0 +1,9 @@ +package com.umc.networkingService.domain.member.repository; + +import com.umc.networkingService.domain.member.entity.MemberPosition; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface MemberPositionRepository extends JpaRepository { +} diff --git a/src/main/java/com/umc/networkingService/domain/member/service/MemberService.java b/src/main/java/com/umc/networkingService/domain/member/service/MemberService.java new file mode 100644 index 00000000..f95d7e3e --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/service/MemberService.java @@ -0,0 +1,9 @@ +package com.umc.networkingService.domain.member.service; + +import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; +import com.umc.networkingService.domain.member.dto.response.MemberSignUpResponse; +import com.umc.networkingService.domain.member.entity.Member; + +public interface MemberService { + MemberSignUpResponse signUp(Member member, MemberSignUpRequest request); +} diff --git a/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java b/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java new file mode 100644 index 00000000..556b780e --- /dev/null +++ b/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java @@ -0,0 +1,106 @@ +package com.umc.networkingService.domain.member.service; + +import com.umc.networkingService.domain.branch.service.BranchUniversityService; +import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; +import com.umc.networkingService.domain.member.dto.response.MemberSignUpResponse; +import com.umc.networkingService.domain.member.entity.Member; +import com.umc.networkingService.domain.member.entity.MemberPosition; +import com.umc.networkingService.domain.member.entity.PositionType; +import com.umc.networkingService.domain.member.mapper.MemberMapper; +import com.umc.networkingService.domain.member.repository.MemberPositionRepository; +import com.umc.networkingService.domain.member.repository.MemberRepository; +import com.umc.networkingService.domain.university.entity.University; +import com.umc.networkingService.domain.university.service.UniversityService; +import com.umc.networkingService.global.common.enums.Role; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class MemberServiceImpl implements MemberService { + + private final MemberRepository memberRepository; + private final MemberMapper memberMapper; + private final MemberPositionRepository memberPositionRepository; + + private final UniversityService universityService; + private final BranchUniversityService branchUniversityService; + + @Override + @Transactional + public MemberSignUpResponse signUp(Member member, MemberSignUpRequest request) { + + // 소속 대학교 탐색 + University university = universityService.findUniversityByName(request.getUniversityName()); + + // 멤버 기본 정보 저장 + setMemberInfo(member, request, university); + + // 멤버 직책 저장 + saveMemberPositions(member, request); + + return null; + } + + // 멤버 기본 정보 저장 함수 + private void setMemberInfo(Member member, MemberSignUpRequest request, University university) { + member.setMemberInfo( + request, + findMemberRole(request), + university, + branchUniversityService.findBranchByUniversity(university) + ); + } + + // 멤버 직책 정보 저장 함수 + private void saveMemberPositions(Member member, MemberSignUpRequest request) { + saveMemberPosition(member, request.getCenterPositions(), PositionType.CENTER); + saveMemberPosition(member, request.getCampusPositions(), PositionType.CAMPUS); + } + + private void saveMemberPosition(Member member, List positions, PositionType positionType) { + List memberPositions = positions.stream() + .map(position -> memberMapper.toMemberPosition(member, positionType, position)) + .toList(); + + memberPositionRepository.saveAll(memberPositions); + } + + // 멤버 Role 생성 함수 + private Role findMemberRole(MemberSignUpRequest request) { + if (request.getCenterPositions().isEmpty()) { + return findCampusRole(request.getCampusPositions()); + } + + return findCenterRole(request.getCenterPositions()); + } + + private Role findCampusRole(List campusPositions) { + if (campusPositions.isEmpty()) { + return Role.MEMBER; + } + + if (isExecutive(campusPositions)) { + return Role.BRANCH_STAFF; + } + + return Role.CAMPUS_STAFF; + } + + private Role findCenterRole(List centerPositions) { + if (isExecutive(centerPositions)) { + return Role.TOTAL_STAFF; + } + + return Role.CENTER_STAFF; + } + + // 회장, 부회장 판별 함수 + private boolean isExecutive(List positions) { + return positions.stream() + .anyMatch(position -> position.equals("회장") || position.equals("부회장")); + } +} diff --git a/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java b/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java index 7cb4a3d9..30387c26 100644 --- a/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java +++ b/src/main/java/com/umc/networkingService/global/common/exception/ErrorCode.java @@ -35,7 +35,10 @@ public enum ErrorCode { FAILED_SOCIAL_LOGIN(HttpStatus.INTERNAL_SERVER_ERROR, "AUTH007", "소셜 로그인에 실패하였습니다."), // University - EMPTY_UNIVERSITY(HttpStatus.BAD_REQUEST, "UNIVERSITY001", "존재하지 않는 대학교입니다."); + EMPTY_UNIVERSITY(HttpStatus.BAD_REQUEST, "UNIVERSITY001", "존재하지 않는 대학교입니다."), + + // Branch + EMPTY_BRANCH(HttpStatus.BAD_REQUEST, "BRANCH001", "존재하지 않는 지부입니다."); private final HttpStatus httpStatus; private final String code; From 739e0bd6037753355525a194b9a798446404d5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 16:24:58 +0900 Subject: [PATCH 10/15] =?UTF-8?q?fix:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20API=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 26 +++++++++++++++++-- .../domain/member/entity/Member.java | 14 ++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java index d3daa5c0..8e68c23e 100644 --- a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java +++ b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java @@ -1,7 +1,13 @@ package com.umc.networkingService.domain.member.controller; +import com.umc.networkingService.config.security.auth.CurrentMember; +import com.umc.networkingService.config.security.jwt.JwtTokenProvider; import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; import com.umc.networkingService.domain.member.dto.response.MemberSignUpResponse; +import com.umc.networkingService.domain.member.entity.Member; +import com.umc.networkingService.domain.member.entity.SocialType; +import com.umc.networkingService.domain.member.repository.MemberRepository; +import com.umc.networkingService.domain.member.service.MemberService; import com.umc.networkingService.global.common.base.BaseResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -18,9 +24,25 @@ @RequestMapping("/members") public class MemberController { + private final MemberService memberService; + private final MemberRepository memberRepository; + private final JwtTokenProvider jwtTokenProvider; @Operation(summary = "회원가입 API", description = "최초 멤버 정보를 등록하는 API입니다.") @PostMapping - public BaseResponse signUp(@Valid @RequestBody MemberSignUpRequest request) { - return null; + public BaseResponse signUp(@CurrentMember Member member, + @Valid @RequestBody MemberSignUpRequest request) { + return BaseResponse.onSuccess(memberService.signUp(member, request)); + } + + @PostMapping("/temp") + public String getToken() { + Member member = Member.builder() + .clientId("123456") + .socialType(SocialType.KAKAO) + .build(); + + Member newMember = memberRepository.save(member); + + return jwtTokenProvider.generateToken(newMember.getId()).getAccessToken(); } } diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java index a6f99eff..ed289d3b 100644 --- a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java +++ b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java @@ -8,9 +8,7 @@ import com.umc.networkingService.global.common.enums.Role; import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.SQLRestriction; import org.hibernate.annotations.UuidGenerator; @@ -21,6 +19,8 @@ @Getter @Entity +@Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLRestriction("deleted_at is null") public class Member extends BaseEntity { @@ -32,23 +32,20 @@ public class Member extends BaseEntity { private String clientId; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(nullable = false, name = "university_id") + @JoinColumn(name = "university_id") private University university; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(nullable = false, name = "branch_id") + @JoinColumn(name = "branch_id") private Branch branch; private String profileImage; - @Column(nullable = false) @ColumnDefault("0") private Long remainPoint; - @Column(nullable = false) private String nickname; - @Column(nullable = false) private String name; private String statusMessage; @@ -67,7 +64,6 @@ public class Member extends BaseEntity { private List semester=new ArrayList<>(); @Enumerated(EnumType.STRING) - @Column(nullable = false) private Role role; private String gitNickname; From 9ea110ef8a62f433bc4fb3e98975a9a7695a27be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 19:44:49 +0900 Subject: [PATCH 11/15] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20API=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/PrincipalDetailsService.java | 1 - .../domain/branch/entity/Branch.java | 6 +- .../branch/entity/BranchUniversity.java | 6 +- .../member/controller/MemberController.java | 2 + .../dto/request/MemberSignUpRequest.java | 4 + .../domain/member/entity/Member.java | 8 +- .../member/repository/MemberRepository.java | 6 +- .../member/service/MemberServiceImpl.java | 4 +- .../domain/university/entity/University.java | 6 +- src/main/resources/application-test.yml | 19 +++ .../member/MemberServiceIntegrationTest.java | 123 ++++++++++++++++++ 11 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/application-test.yml create mode 100644 src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java diff --git a/src/main/java/com/umc/networkingService/config/security/auth/PrincipalDetailsService.java b/src/main/java/com/umc/networkingService/config/security/auth/PrincipalDetailsService.java index db807375..0df102c3 100644 --- a/src/main/java/com/umc/networkingService/config/security/auth/PrincipalDetailsService.java +++ b/src/main/java/com/umc/networkingService/config/security/auth/PrincipalDetailsService.java @@ -6,7 +6,6 @@ import com.umc.networkingService.global.common.exception.RestApiException; import java.util.UUID; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java b/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java index e71a481b..fb29b57b 100644 --- a/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java +++ b/src/main/java/com/umc/networkingService/domain/branch/entity/Branch.java @@ -3,9 +3,7 @@ import com.umc.networkingService.global.common.base.BaseEntity; import com.umc.networkingService.global.common.enums.Semester; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.SQLRestriction; import org.hibernate.annotations.UuidGenerator; @@ -14,6 +12,8 @@ @Getter @Entity +@Builder +@AllArgsConstructor @NoArgsConstructor(access= AccessLevel.PROTECTED) @SQLRestriction("deleted_at is null") public class Branch extends BaseEntity { diff --git a/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java b/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java index 77419486..02e46718 100644 --- a/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java +++ b/src/main/java/com/umc/networkingService/domain/branch/entity/BranchUniversity.java @@ -3,9 +3,7 @@ import com.umc.networkingService.domain.university.entity.University; import com.umc.networkingService.global.common.base.BaseEntity; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.SQLRestriction; import org.hibernate.annotations.UuidGenerator; @@ -13,6 +11,8 @@ @Entity @Getter +@Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLRestriction("deleted_at is null") public class BranchUniversity extends BaseEntity { diff --git a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java index 8e68c23e..f859ee71 100644 --- a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java +++ b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java @@ -9,6 +9,7 @@ import com.umc.networkingService.domain.member.repository.MemberRepository; import com.umc.networkingService.domain.member.service.MemberService; import com.umc.networkingService.global.common.base.BaseResponse; +import com.umc.networkingService.global.common.enums.Role; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -39,6 +40,7 @@ public String getToken() { Member member = Member.builder() .clientId("123456") .socialType(SocialType.KAKAO) + .role(Role.MEMBER) .build(); Member newMember = memberRepository.save(member); diff --git a/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java b/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java index 754fe8ad..3061fbdd 100644 --- a/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java +++ b/src/main/java/com/umc/networkingService/domain/member/dto/request/MemberSignUpRequest.java @@ -4,13 +4,17 @@ import com.umc.networkingService.global.common.enums.Semester; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.List; @Getter @Builder +@AllArgsConstructor +@NoArgsConstructor public class MemberSignUpRequest { @NotBlank(message = "이름은 필수 입력값입니다.") private String name; diff --git a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java index ed289d3b..fafac682 100644 --- a/src/main/java/com/umc/networkingService/domain/member/entity/Member.java +++ b/src/main/java/com/umc/networkingService/domain/member/entity/Member.java @@ -10,6 +10,7 @@ import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.SQLRestriction; import org.hibernate.annotations.UuidGenerator; @@ -23,6 +24,7 @@ @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLRestriction("deleted_at is null") +@DynamicInsert public class Member extends BaseEntity { @Id @UuidGenerator @@ -54,14 +56,16 @@ public class Member extends BaseEntity { private SocialType socialType; @Enumerated(EnumType.STRING) + @Builder.Default @CollectionTable(name = "member_part", joinColumns = @JoinColumn(name = "member_id")) @ElementCollection(fetch = FetchType.LAZY) private List part = new ArrayList<>(); @Enumerated(EnumType.STRING) + @Builder.Default @CollectionTable(name = "member_semester", joinColumns = @JoinColumn(name = "member_id")) @ElementCollection(fetch = FetchType.LAZY) - private List semester=new ArrayList<>(); + private List semester = new ArrayList<>(); @Enumerated(EnumType.STRING) private Role role; @@ -76,5 +80,7 @@ public void setMemberInfo(MemberSignUpRequest request, Role role, University uni this.role = role; this.university = university; this.branch = branch; + this.part.addAll(request.getParts()); + this.semester.addAll(request.getSemesters()); } } diff --git a/src/main/java/com/umc/networkingService/domain/member/repository/MemberRepository.java b/src/main/java/com/umc/networkingService/domain/member/repository/MemberRepository.java index 73b09b19..42b40145 100644 --- a/src/main/java/com/umc/networkingService/domain/member/repository/MemberRepository.java +++ b/src/main/java/com/umc/networkingService/domain/member/repository/MemberRepository.java @@ -3,13 +3,15 @@ import com.umc.networkingService.domain.member.entity.Member; import java.util.Optional; import java.util.UUID; + +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; public interface MemberRepository extends JpaRepository { - @Query(value = "select m from Member m where m.id = :memberId and m.deletedAt = null") + + @Query(value = "select m from Member m where m.id = :memberId and m.deletedAt is null") Optional findById(@Param("memberId") UUID memberId); Boolean existsByNickname(String nickname); diff --git a/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java b/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java index 556b780e..93871ae9 100644 --- a/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/umc/networkingService/domain/member/service/MemberServiceImpl.java @@ -12,9 +12,9 @@ import com.umc.networkingService.domain.university.entity.University; import com.umc.networkingService.domain.university.service.UniversityService; import com.umc.networkingService.global.common.enums.Role; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -42,7 +42,7 @@ public MemberSignUpResponse signUp(Member member, MemberSignUpRequest request) { // 멤버 직책 저장 saveMemberPositions(member, request); - return null; + return new MemberSignUpResponse(memberRepository.save(member).getId()); } // 멤버 기본 정보 저장 함수 diff --git a/src/main/java/com/umc/networkingService/domain/university/entity/University.java b/src/main/java/com/umc/networkingService/domain/university/entity/University.java index a883006c..9cea8a76 100644 --- a/src/main/java/com/umc/networkingService/domain/university/entity/University.java +++ b/src/main/java/com/umc/networkingService/domain/university/entity/University.java @@ -3,9 +3,7 @@ import com.umc.networkingService.domain.mascot.entity.Mascot; import com.umc.networkingService.global.common.base.BaseEntity; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.SQLRestriction; @@ -15,6 +13,8 @@ @Getter @Entity +@Builder +@AllArgsConstructor @NoArgsConstructor(access= AccessLevel.PROTECTED) @SQLRestriction("deleted_at is null") @DynamicInsert diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 00000000..e708d088 --- /dev/null +++ b/src/main/resources/application-test.yml @@ -0,0 +1,19 @@ +server: + port: 8080 + +spring: + application: + name: umc-service-test + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + + config: + import: classpath:application.yml + + jpa: + show-sql: true + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true \ No newline at end of file diff --git a/src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java b/src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java new file mode 100644 index 00000000..ba6dbabf --- /dev/null +++ b/src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java @@ -0,0 +1,123 @@ +package com.umc.networkingService.domain.member; + + +import com.umc.networkingService.domain.branch.entity.Branch; +import com.umc.networkingService.domain.branch.entity.BranchUniversity; +import com.umc.networkingService.domain.branch.repository.BranchRepository; +import com.umc.networkingService.domain.branch.repository.BranchUniversityRepository; +import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; +import com.umc.networkingService.domain.member.entity.Member; +import com.umc.networkingService.domain.member.entity.SocialType; +import com.umc.networkingService.domain.member.repository.MemberRepository; +import com.umc.networkingService.domain.member.service.MemberService; +import com.umc.networkingService.domain.university.entity.University; +import com.umc.networkingService.domain.university.repository.UniversityRepository; +import com.umc.networkingService.global.common.enums.Part; +import com.umc.networkingService.global.common.enums.Role; +import com.umc.networkingService.global.common.enums.Semester; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@DisplayName("Member 서비스의 ") +@SpringBootTest +public class MemberServiceIntegrationTest { + + @Autowired private MemberService memberService; + + @Autowired private MemberRepository memberRepository; + @Autowired private UniversityRepository universityRepository; + @Autowired private BranchRepository branchRepository; + @Autowired private BranchUniversityRepository branchUniversityRepository; + + private Member member; + private University university; + private Branch branch; + private BranchUniversity branchUniversity; + + @BeforeEach + public void setUp() { + member = createMember(); + university = createUniversity(); + branch = createBranch(); + branchUniversity = createBranchUniversity(); + } + + private Member createMember() { + return memberRepository.save( + Member.builder() + .clientId("123456") + .socialType(SocialType.KAKAO) + .role(Role.MEMBER) + .build() + ); + } + + private University createUniversity() { + return universityRepository.save( + University.builder() + .name("인하대학교") + .build() + ); + } + + private Branch createBranch() { + return branchRepository.save( + Branch.builder() + .name("GACI") + .description("가치 지부입니다.") + .semester(Semester.FIFTH) + .build() + ); + } + + private BranchUniversity createBranchUniversity() { + return branchUniversityRepository.save( + BranchUniversity.builder() + .branch(branch) + .university(university) + .isActive(Boolean.TRUE) + .build() + ); + } + + @Test + @DisplayName("회원 가입 테스트") + @Transactional + public void signUpTest() { + // given + MemberSignUpRequest request = MemberSignUpRequest.builder() + .name("김준석") + .nickname("벡스") + .universityName("인하대학교") + .parts(List.of(Part.SPRING)) + .semesters(List.of(Semester.THIRD, Semester.FOURTH, Semester.FIFTH)) + .campusPositions(List.of("회장")) + .centerPositions(List.of("Server 파트장")) + .build(); + + // when + memberService.signUp(member, request); + + // then + Optional optionalMember = memberRepository.findById(member.getId()); + assertTrue(optionalMember.isPresent()); + Member savedMember = optionalMember.get(); + + assertEquals("김준석", savedMember.getName()); + assertEquals("벡스", savedMember.getNickname()); + assertEquals("GACI", savedMember.getBranch().getName()); + assertEquals("인하대학교", savedMember.getUniversity().getName()); + assertEquals(1, savedMember.getPart().size()); + assertEquals(3, savedMember.getSemester().size()); + } +} From b17972587098ab59d93d20d23ab885c9f71ff7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 19:45:12 +0900 Subject: [PATCH 12/15] =?UTF-8?q?fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20api=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java index f859ee71..6b3bfff3 100644 --- a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java +++ b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java @@ -34,17 +34,4 @@ public BaseResponse signUp(@CurrentMember Member member, @Valid @RequestBody MemberSignUpRequest request) { return BaseResponse.onSuccess(memberService.signUp(member, request)); } - - @PostMapping("/temp") - public String getToken() { - Member member = Member.builder() - .clientId("123456") - .socialType(SocialType.KAKAO) - .role(Role.MEMBER) - .build(); - - Member newMember = memberRepository.save(member); - - return jwtTokenProvider.generateToken(newMember.getId()).getAccessToken(); - } } From c6941aee6dfee2543034dbaf6dcf17c28ff816ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 20:30:42 +0900 Subject: [PATCH 13/15] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20API=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 2 - .../domain/member/MemberControllerTest.java | 103 ++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java diff --git a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java index 6b3bfff3..3dd0f057 100644 --- a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java +++ b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java @@ -26,8 +26,6 @@ public class MemberController { private final MemberService memberService; - private final MemberRepository memberRepository; - private final JwtTokenProvider jwtTokenProvider; @Operation(summary = "회원가입 API", description = "최초 멤버 정보를 등록하는 API입니다.") @PostMapping public BaseResponse signUp(@CurrentMember Member member, diff --git a/src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java b/src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java new file mode 100644 index 00000000..64fbda9c --- /dev/null +++ b/src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java @@ -0,0 +1,103 @@ +package com.umc.networkingService.domain.member; + +import com.umc.networkingService.config.security.jwt.JwtTokenProvider; +import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; +import com.umc.networkingService.domain.member.dto.response.MemberSignUpResponse; +import com.umc.networkingService.domain.member.entity.Member; +import com.umc.networkingService.domain.member.entity.SocialType; +import com.umc.networkingService.domain.member.repository.MemberRepository; +import com.umc.networkingService.domain.member.service.MemberService; +import com.umc.networkingService.global.common.enums.Part; +import com.umc.networkingService.global.common.enums.Role; +import com.umc.networkingService.global.common.enums.Semester; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.mockito.Mockito.*; + + + +@DisplayName("Member 컨트롤러의") +@SpringBootTest +@AutoConfigureMockMvc +public class MemberControllerTest { + + @Autowired private MockMvc mockMvc; + + @Autowired private ObjectMapper objectMapper; + + @Autowired private JwtTokenProvider jwtTokenProvider; + + @MockBean private MemberService memberService; + + @MockBean private MemberRepository memberRepository; + + private Member member; + private String accessToken; + + @BeforeEach + public void setUp() { + member = createMember(); + accessToken = jwtTokenProvider.generateToken(member.getId()).getAccessToken(); + } + + private Member createMember() { + return Member.builder() + .id(UUID.randomUUID()) + .clientId("123456") + .socialType(SocialType.KAKAO) + .role(Role.MEMBER) + .build(); + } + + @Test + @DisplayName("회원가입 API 테스트") + public void signUpTest() throws Exception { + // given + MemberSignUpRequest request = MemberSignUpRequest.builder() + .name("김준석") + .nickname("벡스") + .universityName("인하대학교") + .parts(List.of(Part.SPRING)) + .semesters(List.of(Semester.THIRD, Semester.FOURTH, Semester.FIFTH)) + .campusPositions(List.of("회장")) + .centerPositions(List.of("Server 파트장")) + .build(); + + MemberSignUpResponse response = new MemberSignUpResponse(member.getId()); + + // when + when(memberService.signUp(eq(member), any(MemberSignUpRequest.class))).thenReturn(response); + when(memberRepository.findById(any(UUID.class))).thenReturn(Optional.of(member)); + + + // then + this.mockMvc.perform(post("/members") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", accessToken) // accessToken 설정 + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) // 응답 출력 + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("COMMON200")) + .andExpect(jsonPath("$.message").value("요청에 성공하였습니다.")) + .andExpect(jsonPath("$.result").exists()); // result 필드가 존재하는지 검사 + + + } +} \ No newline at end of file From b50b6c0c47744c098db87282f34c4df367f4e371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 20:33:35 +0900 Subject: [PATCH 14/15] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=ED=8C=8C=EC=9D=BC=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/{ => controller}/MemberControllerTest.java | 2 +- .../member/{ => service}/MemberServiceIntegrationTest.java | 2 +- .../member/service}/RefreshTokenServiceIntegrationTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/test/java/com/umc/networkingService/domain/member/{ => controller}/MemberControllerTest.java (98%) rename src/test/java/com/umc/networkingService/domain/member/{ => service}/MemberServiceIntegrationTest.java (98%) rename src/test/java/com/umc/networkingService/{ => domain/member/service}/RefreshTokenServiceIntegrationTest.java (98%) diff --git a/src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java b/src/test/java/com/umc/networkingService/domain/member/controller/MemberControllerTest.java similarity index 98% rename from src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java rename to src/test/java/com/umc/networkingService/domain/member/controller/MemberControllerTest.java index 64fbda9c..29c36bb5 100644 --- a/src/test/java/com/umc/networkingService/domain/member/MemberControllerTest.java +++ b/src/test/java/com/umc/networkingService/domain/member/controller/MemberControllerTest.java @@ -1,4 +1,4 @@ -package com.umc.networkingService.domain.member; +package com.umc.networkingService.domain.member.controller; import com.umc.networkingService.config.security.jwt.JwtTokenProvider; import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest; diff --git a/src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java b/src/test/java/com/umc/networkingService/domain/member/service/MemberServiceIntegrationTest.java similarity index 98% rename from src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java rename to src/test/java/com/umc/networkingService/domain/member/service/MemberServiceIntegrationTest.java index ba6dbabf..623ad3a9 100644 --- a/src/test/java/com/umc/networkingService/domain/member/MemberServiceIntegrationTest.java +++ b/src/test/java/com/umc/networkingService/domain/member/service/MemberServiceIntegrationTest.java @@ -1,4 +1,4 @@ -package com.umc.networkingService.domain.member; +package com.umc.networkingService.domain.member.service; import com.umc.networkingService.domain.branch.entity.Branch; diff --git a/src/test/java/com/umc/networkingService/RefreshTokenServiceIntegrationTest.java b/src/test/java/com/umc/networkingService/domain/member/service/RefreshTokenServiceIntegrationTest.java similarity index 98% rename from src/test/java/com/umc/networkingService/RefreshTokenServiceIntegrationTest.java rename to src/test/java/com/umc/networkingService/domain/member/service/RefreshTokenServiceIntegrationTest.java index d347a7e5..03367f01 100644 --- a/src/test/java/com/umc/networkingService/RefreshTokenServiceIntegrationTest.java +++ b/src/test/java/com/umc/networkingService/domain/member/service/RefreshTokenServiceIntegrationTest.java @@ -1,4 +1,4 @@ -package com.umc.networkingService; +package com.umc.networkingService.domain.member.service; import com.umc.networkingService.config.security.jwt.JwtTokenProvider; import com.umc.networkingService.domain.member.entity.RefreshToken; From 2576ab702643aca4f4c35adebe0f605a56b97b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=8D=A8=ED=81=AC?= Date: Wed, 17 Jan 2024 21:27:47 +0900 Subject: [PATCH 15/15] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=97=90=EB=9F=AC=20=EA=B2=B0=EA=B3=BC=20=EC=98=88?= =?UTF-8?q?=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java index 3dd0f057..ca1c4f75 100644 --- a/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java +++ b/src/main/java/com/umc/networkingService/domain/member/controller/MemberController.java @@ -11,6 +11,8 @@ import com.umc.networkingService.global.common.base.BaseResponse; import com.umc.networkingService.global.common.enums.Role; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -27,6 +29,11 @@ public class MemberController { private final MemberService memberService; @Operation(summary = "회원가입 API", description = "최초 멤버 정보를 등록하는 API입니다.") + @ApiResponses( value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + @ApiResponse(responseCode = "UNIVERSITY001", description = "대학교명을 잘못 입력하였을 경우 발생"), + @ApiResponse(responseCode = "BRANCH001", description = "대학교가 지부랑 연결되어 있지 않을 경우 발생") + }) @PostMapping public BaseResponse signUp(@CurrentMember Member member, @Valid @RequestBody MemberSignUpRequest request) {