From c822385ad018c5a9a89fcf20d7071e3d3bc1f02b Mon Sep 17 00:00:00 2001 From: ani2689 Date: Thu, 18 Jan 2024 21:40:42 +0900 Subject: [PATCH 01/50] =?UTF-8?q?:sparkles:=20=EC=84=A0=EC=83=9D=EB=8B=98?= =?UTF-8?q?=20=EB=B3=84=20=EA=B6=8C=ED=95=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/team/msg/sms/domain/auth/model/Role.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/model/Role.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/model/Role.kt index 71bd921b..b572151e 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/model/Role.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/model/Role.kt @@ -2,5 +2,9 @@ package team.msg.sms.domain.auth.model enum class Role(description: String) { ROLE_STUDENT("학생"), - ROLE_TEACHER("선생님") + ROLE_TEACHER("선생님"), + ROLE_PRINCIPAL("교장선생님"), + ROLE_DEPUTY_PRINCIPAL("교감선생님"), + ROLE_DIRECTOR("부장선생님"), + ROLE_HOMEROOM("담임선생님") } \ No newline at end of file From e72dd758840e855950c303f1e6f3483c867a6cc0 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Thu, 18 Jan 2024 21:41:18 +0900 Subject: [PATCH 02/50] :recycle: companion obj ref --- .../msg/sms/global/security/SecurityConfig.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt index 134063db..bb9d7a3b 100644 --- a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt +++ b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt @@ -19,6 +19,15 @@ class SecurityConfig( private val customAuthenticationEntryPoint: CustomAuthenticationEntryPoint ) { + companion object { + const val STUDENT = "ROLE_STUDENT" // 학생 + const val TEACHER = "ROLE_TEACHER" // 선생님 + const val PRINCIPAL = "ROLE_PRINCIPAL" // 교장선생님 + const val DEPUTY_PRINCIPAL = "ROLE_DEPUTY_PRINCIPAL" // 교감선생님 + const val DIRECTOR = "ROLE_DIRECTOR" // 부장선생님 + const val HOMEROOM = "ROLE_HOMEROOM" // 담임선생님 + } + @Bean protected fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { http @@ -47,11 +56,11 @@ class SecurityConfig( .antMatchers(HttpMethod.DELETE, "/auth/withdrawal").authenticated() .antMatchers(HttpMethod.GET, "/user/profile/img").permitAll() - .antMatchers(HttpMethod.GET,"/user/profile").hasAuthority("ROLE_STUDENT") + .antMatchers(HttpMethod.GET,"/user/profile").hasAuthority(STUDENT) - .antMatchers(HttpMethod.POST, "/student").hasAuthority("ROLE_STUDENT") + .antMatchers(HttpMethod.POST, "/student").hasAuthority(STUDENT) .antMatchers(HttpMethod.GET, "/student").permitAll() - .antMatchers(HttpMethod.GET, "/student/{uuid}").hasAnyAuthority("ROLE_STUDENT", "ROLE_TEACHER") + .antMatchers(HttpMethod.GET, "/student/{uuid}").hasAnyAuthority(STUDENT, TEACHER) .antMatchers(HttpMethod.GET, "/student/anonymous/{uuid}").permitAll() .antMatchers(HttpMethod.POST, "/file").authenticated() From 8ff4a6d7de16efad8f93a56db41f3356e431a64a Mon Sep 17 00:00:00 2001 From: ani2689 Date: Thu, 18 Jan 2024 23:26:25 +0900 Subject: [PATCH 03/50] :sparkles: teacher entity & repository --- .../teacher/entity/TeacherJpaEntity.kt | 19 +++++++++++++++++++ .../repository/TeacherJpaRepository.kt | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/TeacherJpaEntity.kt create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/TeacherJpaEntity.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/TeacherJpaEntity.kt new file mode 100644 index 00000000..88060f1f --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/TeacherJpaEntity.kt @@ -0,0 +1,19 @@ +package team.msg.sms.persistence.teacher.entity + +import team.msg.sms.persistence.BaseUuidEntity +import team.msg.sms.persistence.user.entity.UserJpaEntity +import java.util.UUID +import javax.persistence.Entity +import javax.persistence.JoinColumn +import javax.persistence.OneToOne +import javax.persistence.Table + +@Entity +@Table(name = "teacher") +class TeacherJpaEntity ( + override val id: UUID, + + @OneToOne + @JoinColumn(name = "user_id") + val user: UserJpaEntity +) : BaseUuidEntity(id) \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt new file mode 100644 index 00000000..0dda2e8f --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt @@ -0,0 +1,9 @@ +package team.msg.sms.persistence.teacher.repository + +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import team.msg.sms.persistence.teacher.entity.TeacherJpaEntity +import java.util.* + +@Repository +interface TeacherJpaRepository : JpaRepository \ No newline at end of file From 9fbb088f80caa71038368bd2e06b7a1ab53dd126 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Thu, 18 Jan 2024 23:27:18 +0900 Subject: [PATCH 04/50] :sparkles: homeroom teacher entity & repository --- .../entity/HomeroomTeacherJpaEntity.kt | 20 +++++++++++++++++++ .../HomeroomTeacherJpaRepository.kt | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt new file mode 100644 index 00000000..2281238e --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt @@ -0,0 +1,20 @@ +package team.msg.sms.persistence.teacher.entity + +import team.msg.sms.persistence.BaseIdEntity +import javax.persistence.* + +@Entity +@Table(name = "homeroom_teacher") +class HomeroomTeacherJpaEntity ( + override val id: Long, + + @Column + val grade: Int, + + @Column(name = "class_name") + val classNum: Int, + + @OneToOne(cascade = [CascadeType.ALL]) + @JoinColumn(name = "teacher_id") + val teacher: TeacherJpaEntity +) : BaseIdEntity() \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt new file mode 100644 index 00000000..5cbd37ae --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt @@ -0,0 +1,8 @@ +package team.msg.sms.persistence.teacher.repository + +import org.springframework.data.repository.CrudRepository +import org.springframework.stereotype.Repository +import team.msg.sms.persistence.teacher.entity.HomeroomTeacherJpaEntity + +@Repository +interface HomeroomTeacherJpaRepository : CrudRepository \ No newline at end of file From b5c20c2c33ab5892f06acf9cf59958969d36d59e Mon Sep 17 00:00:00 2001 From: ani2689 Date: Thu, 18 Jan 2024 23:58:07 +0900 Subject: [PATCH 05/50] =?UTF-8?q?:pencil2:=20=EC=BB=AC=EB=9F=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt index 2281238e..cafba45a 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt @@ -11,7 +11,7 @@ class HomeroomTeacherJpaEntity ( @Column val grade: Int, - @Column(name = "class_name") + @Column(name = "class_num") val classNum: Int, @OneToOne(cascade = [CascadeType.ALL]) From 07262defd2a5c76f37e3adc2d7b44b2e15b3a0cf Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 19 Jan 2024 23:09:17 +0900 Subject: [PATCH 06/50] =?UTF-8?q?:sparkles:=20teacher=20port=20=EC=B6=94?= =?UTF-8?q?=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt | 7 +++++++ .../kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt | 4 ++++ 2 files changed, 11 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt new file mode 100644 index 00000000..68a044dd --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt @@ -0,0 +1,7 @@ +package team.msg.sms.domain.teacher.spi + +import java.util.* + +interface QueryTeacherPort { + fun existsTeacherById(uuid: UUID): Boolean +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt new file mode 100644 index 00000000..ab57381a --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt @@ -0,0 +1,4 @@ +package team.msg.sms.domain.teacher.spi + +interface TeacherPort : + QueryTeacherPort \ No newline at end of file From 235129794097815d3fef84d9b2dc634ef5dfcefb Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 19 Jan 2024 23:09:38 +0900 Subject: [PATCH 07/50] =?UTF-8?q?:sparkles:=20teacher=20adapter=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teacher/TeacherPersistenceAdapter.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt new file mode 100644 index 00000000..16f45525 --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt @@ -0,0 +1,14 @@ +package team.msg.sms.persistence.teacher + +import org.springframework.stereotype.Component +import team.msg.sms.domain.teacher.spi.TeacherPort +import team.msg.sms.persistence.teacher.repository.TeacherJpaRepository +import java.util.* + +@Component +class TeacherPersistenceAdapter( + private val teacherJpaRepository: TeacherJpaRepository +) : TeacherPort { + override fun existsTeacherById(uuid: UUID) = + teacherJpaRepository.existsById(uuid) +} \ No newline at end of file From b6251614fee2310fde1b46e6dd8e27d226c98d4a Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 14:34:17 +0900 Subject: [PATCH 08/50] :sparkles: teacher domain obj --- .../msg/sms/domain/teacher/model/HomeroomTeacher.kt | 11 +++++++++++ .../team/msg/sms/domain/teacher/model/Teacher.kt | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/Teacher.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt new file mode 100644 index 00000000..8ae5a870 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt @@ -0,0 +1,11 @@ +package team.msg.sms.domain.teacher.model + +import team.msg.sms.common.annotation.Aggregate + +@Aggregate +data class HomeroomTeacher ( + val id: Long, + val grade: Int, + val classNum: Int, + val teacherId: Long, +) \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/Teacher.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/Teacher.kt new file mode 100644 index 00000000..b7641d4a --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/Teacher.kt @@ -0,0 +1,10 @@ +package team.msg.sms.domain.teacher.model + +import team.msg.sms.common.annotation.Aggregate +import java.util.UUID + +@Aggregate +data class Teacher ( + val id: UUID, + val userId: UUID, +) \ No newline at end of file From 47aa955569532f6d1df30b45fe5d5da8b0e5ed66 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 14:34:32 +0900 Subject: [PATCH 09/50] :sparkles: teacher mapper --- .../persistence/teacher/mapper/TeacherMapper.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/TeacherMapper.kt diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/TeacherMapper.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/TeacherMapper.kt new file mode 100644 index 00000000..ce357c11 --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/TeacherMapper.kt @@ -0,0 +1,17 @@ +package team.msg.sms.persistence.teacher.mapper + +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.persistence.teacher.entity.TeacherJpaEntity +import team.msg.sms.persistence.user.entity.UserJpaEntity + +fun Teacher.toEntity(user: UserJpaEntity): TeacherJpaEntity = + TeacherJpaEntity( + id = id, + user = user + ) + +fun TeacherJpaEntity.toDomain(): Teacher = + Teacher( + id = id, + userId = user.id + ) \ No newline at end of file From 59e64ee6c81cfe43ec350a8eea9ba1ef14114ddb Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 16:47:03 +0900 Subject: [PATCH 10/50] :sparkles: exist teacher by user --- .../team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt | 2 ++ .../sms/persistence/teacher/TeacherPersistenceAdapter.kt | 6 ++++++ .../persistence/teacher/repository/TeacherJpaRepository.kt | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt index 68a044dd..29f67879 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryTeacherPort.kt @@ -1,7 +1,9 @@ package team.msg.sms.domain.teacher.spi +import team.msg.sms.domain.user.model.User import java.util.* interface QueryTeacherPort { fun existsTeacherById(uuid: UUID): Boolean + fun existsTeacherByUser(user: User): Boolean } \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt index 16f45525..26e8d835 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt @@ -2,7 +2,9 @@ package team.msg.sms.persistence.teacher import org.springframework.stereotype.Component import team.msg.sms.domain.teacher.spi.TeacherPort +import team.msg.sms.domain.user.model.User import team.msg.sms.persistence.teacher.repository.TeacherJpaRepository +import team.msg.sms.persistence.user.mapper.toEntity import java.util.* @Component @@ -11,4 +13,8 @@ class TeacherPersistenceAdapter( ) : TeacherPort { override fun existsTeacherById(uuid: UUID) = teacherJpaRepository.existsById(uuid) + + override fun existsTeacherByUser(user: User) = + teacherJpaRepository.existsByUser(user.toEntity()) + } \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt index 0dda2e8f..08b87189 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/TeacherJpaRepository.kt @@ -3,7 +3,10 @@ package team.msg.sms.persistence.teacher.repository import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository import team.msg.sms.persistence.teacher.entity.TeacherJpaEntity +import team.msg.sms.persistence.user.entity.UserJpaEntity import java.util.* @Repository -interface TeacherJpaRepository : JpaRepository \ No newline at end of file +interface TeacherJpaRepository : JpaRepository{ + fun existsByUser(user: UserJpaEntity): Boolean +} \ No newline at end of file From 7981854cb6dbea547c376cd4f5aa569951b12283 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 16:49:43 +0900 Subject: [PATCH 11/50] :sparkles: check student --- .../sms/domain/student/service/CheckStudentService.kt | 3 +-- .../student/service/impl/CheckStudentServiceImpl.kt | 10 ++-------- .../domain/auth/core/usecase/GAuthSignInUseCaseTest.kt | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/CheckStudentService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/CheckStudentService.kt index 686fc7ed..3ceea509 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/CheckStudentService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/CheckStudentService.kt @@ -6,7 +6,6 @@ import team.msg.sms.domain.user.model.User interface CheckStudentService { fun checkStudentExistsByUser(user: User) fun studentExistsByUser(user: User): Boolean - fun checkNewStudent(user: User, role: String): Boolean - + fun checkNewStudent(user: User): Boolean fun checkStudentDataMismatch(student: Student, modifyStudentData: Student): Boolean } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/impl/CheckStudentServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/impl/CheckStudentServiceImpl.kt index 2c78f4c2..a0b2c10e 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/impl/CheckStudentServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/student/service/impl/CheckStudentServiceImpl.kt @@ -5,7 +5,6 @@ import team.msg.sms.domain.student.exception.StudentAlreadyException import team.msg.sms.domain.student.model.Student import team.msg.sms.domain.student.service.CheckStudentService import team.msg.sms.domain.student.spi.StudentPort -import team.msg.sms.domain.user.exception.RoleNotExistsException import team.msg.sms.domain.user.model.User @Service @@ -19,13 +18,8 @@ class CheckStudentServiceImpl ( override fun studentExistsByUser(user: User): Boolean = studentPort.existsStudentByUser(user) - override fun checkNewStudent(user: User, role: String): Boolean { - return when (role) { - "ROLE_STUDENT" -> studentPort.existsStudentByUser(user) - "ROLE_TEACHER" -> true - else -> throw RoleNotExistsException - } - } + override fun checkNewStudent(user: User): Boolean = + studentPort.existsStudentByUser(user) override fun checkStudentDataMismatch(student: Student, modifyStudentData: Student): Boolean { return if(student.contactEmail != modifyStudentData.contactEmail) true diff --git a/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt b/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt index e7ba881a..abb355c7 100644 --- a/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt +++ b/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt @@ -158,7 +158,7 @@ class GAuthSignInUseCaseTest { given(refreshTokenPort.saveRefreshToken(any())) .willReturn(refreshTokenStub) - given(studentService.checkNewStudent(saveUserStub, role.name)) + given(studentService.checkNewStudent(saveUserStub)) .willReturn(false) // when From dfb44da01ebbda39f7acf7141fd0183b99eb19c0 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 16:51:13 +0900 Subject: [PATCH 12/50] :sparkles: check new teacher service --- .../domain/teacher/service/CheckTeacherService.kt | 7 +++++++ .../sms/domain/teacher/service/TeacherService.kt | 8 ++++++++ .../service/impl/CheckTeacherServiceImpl.kt | 14 ++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt new file mode 100644 index 00000000..66e49a3a --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt @@ -0,0 +1,7 @@ +package team.msg.sms.domain.teacher.service + +import team.msg.sms.domain.user.model.User + +interface CheckTeacherService { + fun checkNewTeacher(user: User): Boolean +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt new file mode 100644 index 00000000..39960271 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.service + +import team.msg.sms.common.annotation.Service + +@Service +class TeacherService ( + checkTeacherService: CheckTeacherService +) : CheckTeacherService by checkTeacherService \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt new file mode 100644 index 00000000..b970459d --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt @@ -0,0 +1,14 @@ +package team.msg.sms.domain.teacher.service.impl + +import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.teacher.service.CheckTeacherService +import team.msg.sms.domain.teacher.spi.TeacherPort +import team.msg.sms.domain.user.model.User + +@Service +class CheckTeacherServiceImpl( + private val teacherPort: TeacherPort +) : CheckTeacherService { + override fun checkNewTeacher(user: User) = + teacherPort.existsTeacherByUser(user) +} \ No newline at end of file From 0366346c7084c427188c2303dc7c8414b30c09e6 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 16:52:37 +0900 Subject: [PATCH 13/50] :recycle: check new teacher --- .../msg/sms/domain/auth/usecase/SignInUseCase.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt index a67f6563..416f3bf7 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt @@ -14,7 +14,9 @@ import team.msg.sms.domain.auth.model.Role import team.msg.sms.domain.auth.spi.JwtPort import team.msg.sms.domain.auth.spi.RefreshTokenPort import team.msg.sms.domain.student.service.StudentService +import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.exception.InternalServerErrorException +import team.msg.sms.domain.user.exception.RoleNotExistsException import team.msg.sms.domain.user.model.User import team.msg.sms.domain.user.service.UserService @@ -24,7 +26,8 @@ class SignInUseCase( private val jwtPort: JwtPort, private val refreshTokenPort: RefreshTokenPort, private val userService: UserService, - private val studentService: StudentService + private val studentService: StudentService, + private val teacherService: TeacherService ) { fun execute(request: SignInRequestData): SignInResponseData = @@ -49,7 +52,11 @@ class SignInUseCase( refreshTokenPort.saveRefreshToken(RefreshToken(refreshToken, user.id)) - val isStudent = studentService.checkNewStudent(user, role.name) + val isExist = when (role.name) { + "ROLE_STUDENT" -> studentService.checkNewStudent(user) + "ROLE_TEACHER" -> teacherService.checkNewTeacher(user) + else -> throw RoleNotExistsException + } SignInResponseData( accessToken = accessToken, @@ -57,7 +64,7 @@ class SignInUseCase( refreshToken = refreshToken, refreshTokenExp = refreshTokenExp, role = role, - isExist = isStudent + isExist = isExist ) }.getOrElse { error -> when (error) { From f43611ba7c6b157f80a4cb7be199a5316c249929 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 18:03:57 +0900 Subject: [PATCH 14/50] =?UTF-8?q?:bug:=20=EA=B6=8C=ED=95=9C=20=EB=B3=84=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/domain/auth/usecase/VerifyAccessUseCase.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt index ab68f98e..44233317 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt @@ -3,18 +3,25 @@ package team.msg.sms.domain.auth.usecase import team.msg.sms.common.annotation.UseCase import team.msg.sms.domain.auth.dto.res.VerifyAccessResponseData import team.msg.sms.domain.student.service.StudentService +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.exception.RoleNotExistsException import team.msg.sms.domain.user.service.UserService @UseCase class VerifyAccessUseCase( private val userService: UserService, - private val studentService: StudentService + private val studentService: StudentService, + private val teacherService: TeacherService ) { fun execute(): VerifyAccessResponseData = userService.getCurrentUser() .let { VerifyAccessResponseData( - studentService.checkNewStudent(it, it.roles[0].name), + when (it.roles[0].name) { + "ROLE_STUDENT" -> studentService.checkNewStudent(it) + "ROLE_TEACHER" -> teacherService.checkNewTeacher(it) + else -> throw RoleNotExistsException + }, it.roles[0].name ) } From 499c2af665256456d80a7359ffbd55cf6aa6dc85 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 20 Jan 2024 19:09:48 +0900 Subject: [PATCH 15/50] =?UTF-8?q?:sparkles:=20=EC=84=A0=EC=83=9D=EB=8B=98?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20=EC=A1=B4=EC=9E=AC=20=EC=98=88=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teacher/exception/TeacherAlreadyException.kt | 8 ++++++++ .../teacher/exception/error/TeacherErrorCode.kt | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/TeacherAlreadyException.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/TeacherAlreadyException.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/TeacherAlreadyException.kt new file mode 100644 index 00000000..53811319 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/TeacherAlreadyException.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.exception + +import team.msg.sms.common.error.SmsException +import team.msg.sms.domain.teacher.exception.error.TeacherErrorCode + +object TeacherAlreadyException: SmsException( + TeacherErrorCode.TEACHER_ALREADY +) \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt new file mode 100644 index 00000000..0f16d240 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt @@ -0,0 +1,16 @@ +package team.msg.sms.domain.teacher.exception.error + +import team.msg.sms.common.error.ErrorProperty +import team.msg.sms.common.error.ErrorStatus + +enum class TeacherErrorCode( + private val status: Int, + private val message: String +) : ErrorProperty { + + TEACHER_ALREADY(ErrorStatus.CONFLICT, "선생님 정보가 존재하는 유저입니다"), + ; + + override fun status(): Int = status + override fun message(): String = message +} \ No newline at end of file From 78d886664bbfeb194c4e99abe2f3f3c22458b14e Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 21 Jan 2024 20:17:44 +0900 Subject: [PATCH 16/50] =?UTF-8?q?:sparkles:=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=84=A0=EC=83=9D=EB=8B=98=20=EC=98=88=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/sms/domain/teacher/service/CheckTeacherService.kt | 3 ++- .../team/msg/sms/domain/teacher/service/TeacherService.kt | 6 ++++-- .../domain/teacher/service/impl/CheckTeacherServiceImpl.kt | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt index 66e49a3a..517da34d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckTeacherService.kt @@ -2,6 +2,7 @@ package team.msg.sms.domain.teacher.service import team.msg.sms.domain.user.model.User -interface CheckTeacherService { +interface CheckTeacherService{ + fun checkTeacherExistsByUser(user: User) fun checkNewTeacher(user: User): Boolean } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt index 39960271..79489a5a 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/TeacherService.kt @@ -4,5 +4,7 @@ import team.msg.sms.common.annotation.Service @Service class TeacherService ( - checkTeacherService: CheckTeacherService -) : CheckTeacherService by checkTeacherService \ No newline at end of file + checkTeacherService: CheckTeacherService, + commandTeacherService: CommandTeacherService +) : CheckTeacherService by checkTeacherService, + CommandTeacherService by commandTeacherService \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt index b970459d..86dd8cec 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckTeacherServiceImpl.kt @@ -1,6 +1,7 @@ package team.msg.sms.domain.teacher.service.impl import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.teacher.exception.TeacherAlreadyException import team.msg.sms.domain.teacher.service.CheckTeacherService import team.msg.sms.domain.teacher.spi.TeacherPort import team.msg.sms.domain.user.model.User @@ -9,6 +10,11 @@ import team.msg.sms.domain.user.model.User class CheckTeacherServiceImpl( private val teacherPort: TeacherPort ) : CheckTeacherService { + override fun checkTeacherExistsByUser(user: User) { + if (teacherPort.existsTeacherByUser(user)) + throw TeacherAlreadyException + } + override fun checkNewTeacher(user: User) = teacherPort.existsTeacherByUser(user) } \ No newline at end of file From 256d96118dfdc897c05a4f1b4aa08ead6d3c4f26 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 21 Jan 2024 20:22:49 +0900 Subject: [PATCH 17/50] :sparkles: teacher save --- .../team/msg/sms/domain/teacher/spi/CommandTeacherPort.kt | 8 ++++++++ .../kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt | 3 ++- .../sms/persistence/teacher/TeacherPersistenceAdapter.kt | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandTeacherPort.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandTeacherPort.kt new file mode 100644 index 00000000..7ea579e8 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandTeacherPort.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.spi + +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.user.model.User + +interface CommandTeacherPort { + fun saveTeacher(teacher: Teacher, user: User): Teacher +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt index ab57381a..c52a36fb 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/TeacherPort.kt @@ -1,4 +1,5 @@ package team.msg.sms.domain.teacher.spi interface TeacherPort : - QueryTeacherPort \ No newline at end of file + QueryTeacherPort, + CommandTeacherPort \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt index 26e8d835..01370a82 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/TeacherPersistenceAdapter.kt @@ -1,8 +1,11 @@ package team.msg.sms.persistence.teacher import org.springframework.stereotype.Component +import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.teacher.spi.TeacherPort import team.msg.sms.domain.user.model.User +import team.msg.sms.persistence.teacher.mapper.toDomain +import team.msg.sms.persistence.teacher.mapper.toEntity import team.msg.sms.persistence.teacher.repository.TeacherJpaRepository import team.msg.sms.persistence.user.mapper.toEntity import java.util.* @@ -17,4 +20,7 @@ class TeacherPersistenceAdapter( override fun existsTeacherByUser(user: User) = teacherJpaRepository.existsByUser(user.toEntity()) + override fun saveTeacher(teacher: Teacher, user: User) = + teacherJpaRepository.save(teacher.toEntity(user.toEntity())).toDomain() + } \ No newline at end of file From 347b90a2406f0c7f84a9a63819323319d43ae2ad Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 21 Jan 2024 22:13:13 +0900 Subject: [PATCH 18/50] :sparkles: save teacher service --- .../teacher/service/CommandTeacherService.kt | 8 +++++++ .../service/impl/CommandTeacherServiceImpl.kt | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt new file mode 100644 index 00000000..740c2c61 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.service + +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.user.model.User + +interface CommandTeacherService { + fun saveTeacher(user: User): Teacher +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt new file mode 100644 index 00000000..39803bd3 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt @@ -0,0 +1,22 @@ +package team.msg.sms.domain.teacher.service.impl + +import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.teacher.service.CommandTeacherService +import team.msg.sms.domain.teacher.spi.TeacherPort +import team.msg.sms.domain.user.model.User +import java.util.* + +@Service +class CommandTeacherServiceImpl( + private val teacherPort: TeacherPort +) : CommandTeacherService { + override fun saveTeacher(user: User): Teacher { + val teacher = Teacher( + id = UUID.randomUUID(), + userId = user.id, + ) + + return teacherPort.saveTeacher(teacher, user) + } +} \ No newline at end of file From e22072e742f012063242c66f8aee425ab0940cd7 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 21 Jan 2024 22:14:08 +0900 Subject: [PATCH 19/50] :sparkles: teacher signup usecase --- .../domain/teacher/usecase/SignUpUseCase.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt new file mode 100644 index 00000000..fd0a6c4a --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt @@ -0,0 +1,21 @@ +package team.msg.sms.domain.teacher.usecase + +import org.springframework.transaction.annotation.Transactional +import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.service.UserService + +@UseCase +class SignUpUseCase( + private val userService: UserService, + private val teacherService: TeacherService +) { + @Transactional(rollbackFor = [Exception::class]) + fun execute(){ + val user = userService.getCurrentUser() + + teacherService.checkTeacherExistsByUser(user) + + teacherService.saveTeacher(user) + } +} \ No newline at end of file From 23770a4111bdb17335b9f671e7340d2e0da3b37b Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 21 Jan 2024 22:24:27 +0900 Subject: [PATCH 20/50] :sparkles: teacher web adapter --- .../msg/sms/global/security/SecurityConfig.kt | 2 ++ .../sms/domain/teacher/TeacherWebAdapter.kt | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt diff --git a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt index bb9d7a3b..0b5bcabb 100644 --- a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt +++ b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt @@ -63,6 +63,8 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/student/{uuid}").hasAnyAuthority(STUDENT, TEACHER) .antMatchers(HttpMethod.GET, "/student/anonymous/{uuid}").permitAll() + .antMatchers(HttpMethod.POST, "/teacher/common").hasAuthority(TEACHER) + .antMatchers(HttpMethod.POST, "/file").authenticated() .antMatchers(HttpMethod.POST, "/file/image").authenticated() diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt new file mode 100644 index 00000000..5bf57f29 --- /dev/null +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt @@ -0,0 +1,19 @@ +package team.msg.sms.domain.teacher + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import team.msg.sms.domain.teacher.usecase.SignUpUseCase + +@RestController +@RequestMapping("/student") +class TeacherWebAdapter( + private val signUpUseCase: SignUpUseCase +) { + @PostMapping("/common") + fun signUpTeacher(): ResponseEntity = + signUpUseCase.execute() + .let { ResponseEntity.status(HttpStatus.CREATED).build() } +} From 5c7a62cb98a18db6a5448e34c1e64c46770b7364 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 21 Jan 2024 23:46:44 +0900 Subject: [PATCH 21/50] =?UTF-8?q?:bug:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/{SignUpUseCase.kt => SignUpTeacherUseCase.kt} | 2 +- .../kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/{SignUpUseCase.kt => SignUpTeacherUseCase.kt} (95%) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt similarity index 95% rename from sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt rename to sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt index fd0a6c4a..ed8dddb3 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt @@ -6,7 +6,7 @@ import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.service.UserService @UseCase -class SignUpUseCase( +class SignUpTeacherUseCase( private val userService: UserService, private val teacherService: TeacherService ) { diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt index 5bf57f29..bd8d9b8e 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt @@ -5,12 +5,12 @@ import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import team.msg.sms.domain.teacher.usecase.SignUpUseCase +import team.msg.sms.domain.teacher.usecase.SignUpTeacherUseCase @RestController -@RequestMapping("/student") +@RequestMapping("/teacher") class TeacherWebAdapter( - private val signUpUseCase: SignUpUseCase + private val signUpUseCase: SignUpTeacherUseCase ) { @PostMapping("/common") fun signUpTeacher(): ResponseEntity = From 168b333613c405ff4c34d50d86bd0d2d43eb8155 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Mon, 22 Jan 2024 00:08:33 +0900 Subject: [PATCH 22/50] =?UTF-8?q?:white=5Fcheck=5Fmark:=20Mock=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 --- .../sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt b/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt index abb355c7..3c83f917 100644 --- a/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt +++ b/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt @@ -19,6 +19,7 @@ import team.msg.sms.domain.auth.spi.JwtPort import team.msg.sms.domain.auth.spi.RefreshTokenPort import team.msg.sms.domain.auth.usecase.SignInUseCase import team.msg.sms.domain.student.service.StudentService +import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.model.User import team.msg.sms.domain.user.service.UserService import team.msg.sms.global.annotation.SmsTest @@ -42,6 +43,9 @@ class GAuthSignInUseCaseTest { @Mock private lateinit var studentService: StudentService + @Mock + private lateinit var teacherService: TeacherService + private lateinit var signInUseCase: SignInUseCase private val email = "test@gsm.hs.kr" @@ -129,7 +133,8 @@ class GAuthSignInUseCaseTest { jwtPort = jwtPort, refreshTokenPort = refreshTokenPort, userService = userService, - studentService = studentService + studentService = studentService, + teacherService = teacherService ) } From d611a98493434d40dd02b823291fa9ddbde66119 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 9 Feb 2024 21:37:42 +0900 Subject: [PATCH 23/50] =?UTF-8?q?:recycle:=20when=20=EB=AC=B8=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20=EB=B0=8F=20Role=20enum=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/sms/domain/auth/usecase/SignInUseCase.kt | 13 ++----------- .../domain/auth/usecase/VerifyAccessUseCase.kt | 13 ++----------- .../sms/domain/user/service/CheckUserService.kt | 3 +++ .../user/service/impl/CheckUserServiceImpl.kt | 16 +++++++++++++++- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt index 416f3bf7..ccda88d1 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt @@ -13,10 +13,7 @@ import team.msg.sms.domain.auth.model.RefreshToken import team.msg.sms.domain.auth.model.Role import team.msg.sms.domain.auth.spi.JwtPort import team.msg.sms.domain.auth.spi.RefreshTokenPort -import team.msg.sms.domain.student.service.StudentService -import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.exception.InternalServerErrorException -import team.msg.sms.domain.user.exception.RoleNotExistsException import team.msg.sms.domain.user.model.User import team.msg.sms.domain.user.service.UserService @@ -25,9 +22,7 @@ class SignInUseCase( private val gAuthPort: GAuthPort, private val jwtPort: JwtPort, private val refreshTokenPort: RefreshTokenPort, - private val userService: UserService, - private val studentService: StudentService, - private val teacherService: TeacherService + private val userService: UserService ) { fun execute(request: SignInRequestData): SignInResponseData = @@ -52,11 +47,7 @@ class SignInUseCase( refreshTokenPort.saveRefreshToken(RefreshToken(refreshToken, user.id)) - val isExist = when (role.name) { - "ROLE_STUDENT" -> studentService.checkNewStudent(user) - "ROLE_TEACHER" -> teacherService.checkNewTeacher(user) - else -> throw RoleNotExistsException - } + val isExist = userService.checkNewUser(user) SignInResponseData( accessToken = accessToken, diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt index 44233317..db4806d1 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt @@ -2,26 +2,17 @@ package team.msg.sms.domain.auth.usecase import team.msg.sms.common.annotation.UseCase import team.msg.sms.domain.auth.dto.res.VerifyAccessResponseData -import team.msg.sms.domain.student.service.StudentService -import team.msg.sms.domain.teacher.service.TeacherService -import team.msg.sms.domain.user.exception.RoleNotExistsException import team.msg.sms.domain.user.service.UserService @UseCase class VerifyAccessUseCase( - private val userService: UserService, - private val studentService: StudentService, - private val teacherService: TeacherService + private val userService: UserService ) { fun execute(): VerifyAccessResponseData = userService.getCurrentUser() .let { VerifyAccessResponseData( - when (it.roles[0].name) { - "ROLE_STUDENT" -> studentService.checkNewStudent(it) - "ROLE_TEACHER" -> teacherService.checkNewTeacher(it) - else -> throw RoleNotExistsException - }, + userService.checkNewUser(it), it.roles[0].name ) } diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CheckUserService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CheckUserService.kt index 3e7504b8..24bb5d5a 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CheckUserService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CheckUserService.kt @@ -1,5 +1,8 @@ package team.msg.sms.domain.user.service +import team.msg.sms.domain.user.model.User + interface CheckUserService { fun checkUserExistByEmail(email: String): Boolean + fun checkNewUser(user: User): Boolean } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CheckUserServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CheckUserServiceImpl.kt index 785bcbf4..640ac728 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CheckUserServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CheckUserServiceImpl.kt @@ -1,13 +1,27 @@ package team.msg.sms.domain.user.service.impl import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.auth.model.Role +import team.msg.sms.domain.student.service.StudentService +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.exception.RoleNotExistsException +import team.msg.sms.domain.user.model.User import team.msg.sms.domain.user.service.CheckUserService import team.msg.sms.domain.user.spi.QueryUserPort @Service class CheckUserServiceImpl( - private val queryUserPort: QueryUserPort + private val queryUserPort: QueryUserPort, + private val studentService: StudentService, + private val teacherService: TeacherService ) : CheckUserService { override fun checkUserExistByEmail(email: String): Boolean = queryUserPort.existsUserByEmail(email) + + override fun checkNewUser(user: User): Boolean = + when (user.roles[0]) { + Role.ROLE_STUDENT -> studentService.checkNewStudent(user) + Role.ROLE_TEACHER -> teacherService.checkNewTeacher(user) + else -> throw RoleNotExistsException + } } \ No newline at end of file From 23144213cf3c691885fb953802019cbbb540e243 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 9 Feb 2024 21:40:07 +0900 Subject: [PATCH 24/50] =?UTF-8?q?:recycle:=20Void=20->=20Unit=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt index bd8d9b8e..8b7c6574 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt @@ -13,7 +13,7 @@ class TeacherWebAdapter( private val signUpUseCase: SignUpTeacherUseCase ) { @PostMapping("/common") - fun signUpTeacher(): ResponseEntity = + fun signUpTeacher(): ResponseEntity = signUpUseCase.execute() .let { ResponseEntity.status(HttpStatus.CREATED).build() } } From ee86f01eb8fc479b1b4fa59290d5996ab303dfc2 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 9 Feb 2024 21:46:12 +0900 Subject: [PATCH 25/50] =?UTF-8?q?:recycle:=20return=EA=B0=92=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/sms/domain/teacher/service/CommandTeacherService.kt | 3 +-- .../domain/teacher/service/impl/CommandTeacherServiceImpl.kt | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt index 740c2c61..3768df81 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt @@ -1,8 +1,7 @@ package team.msg.sms.domain.teacher.service -import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.user.model.User interface CommandTeacherService { - fun saveTeacher(user: User): Teacher + fun saveTeacher(user: User) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt index 39803bd3..1d40a691 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt @@ -11,12 +11,12 @@ import java.util.* class CommandTeacherServiceImpl( private val teacherPort: TeacherPort ) : CommandTeacherService { - override fun saveTeacher(user: User): Teacher { + override fun saveTeacher(user: User) { val teacher = Teacher( id = UUID.randomUUID(), userId = user.id, ) - return teacherPort.saveTeacher(teacher, user) + teacherPort.saveTeacher(teacher, user) } } \ No newline at end of file From a404be5e0a72bc53b43d52c57c19dffcd0290cd0 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 9 Feb 2024 22:06:52 +0900 Subject: [PATCH 26/50] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=EB=A7=A4?= =?UTF-8?q?=EA=B0=9C=EB=B3=80=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt b/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt index 3c83f917..cf437a02 100644 --- a/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt +++ b/sms-core/src/test/kotlin/team/msg/sms/domain/auth/core/usecase/GAuthSignInUseCaseTest.kt @@ -132,9 +132,7 @@ class GAuthSignInUseCaseTest { gAuthPort = gAuthPort, jwtPort = jwtPort, refreshTokenPort = refreshTokenPort, - userService = userService, - studentService = studentService, - teacherService = teacherService + userService = userService ) } @@ -163,7 +161,7 @@ class GAuthSignInUseCaseTest { given(refreshTokenPort.saveRefreshToken(any())) .willReturn(refreshTokenStub) - given(studentService.checkNewStudent(saveUserStub)) + given(userService.checkNewUser(saveUserStub)) .willReturn(false) // when From 8c49f03d3629b18769e53cfc27d1fb4e224f9aef Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 10 Feb 2024 13:23:32 +0900 Subject: [PATCH 27/50] :bug: teacher id long -> uuid --- .../team/msg/sms/domain/teacher/model/HomeroomTeacher.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt index 8ae5a870..2098558b 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt @@ -1,11 +1,12 @@ package team.msg.sms.domain.teacher.model import team.msg.sms.common.annotation.Aggregate +import java.util.* @Aggregate data class HomeroomTeacher ( val id: Long, val grade: Int, val classNum: Int, - val teacherId: Long, + val teacherId: UUID, ) \ No newline at end of file From 8b86bd9ac3dcd2989f099744480018321b752c49 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 18:54:02 +0900 Subject: [PATCH 28/50] :sparkles: signup homeroom teacher web request --- .../dto/req/SignUpHomeroomTeacherWebRequest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt new file mode 100644 index 00000000..4239ef9a --- /dev/null +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt @@ -0,0 +1,17 @@ +package team.msg.sms.domain.teacher.dto.req + +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull + +data class SignUpHomeroomTeacherWebRequest( + @field:Min(1) + @field:Max(3) + @field:NotNull + val grade: Int, + + @field:Min(1) + @field:Max(4) + @field:NotNull + val classNum: Int +) From 882637e7f2dddd2af3be1a37fd9e4488345ddf05 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 20:29:34 +0900 Subject: [PATCH 29/50] :sparkles: homeroom teacher service --- .../teacher/service/CheckHomeroomTeacherService.kt | 7 +++++++ .../teacher/service/CommandHomeroomTeacherService.kt | 8 ++++++++ .../domain/teacher/service/HomeroomTeacherService.kt | 10 ++++++++++ 3 files changed, 25 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/HomeroomTeacherService.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt new file mode 100644 index 00000000..cfd85546 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt @@ -0,0 +1,7 @@ +package team.msg.sms.domain.teacher.service + +import team.msg.sms.domain.teacher.model.Teacher + +interface CheckHomeroomTeacherService { + fun checkTeacherExistsByTeacher(teacher: Teacher) +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt new file mode 100644 index 00000000..7e9dc4ea --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.service + +import team.msg.sms.domain.teacher.model.HomeroomTeacher +import team.msg.sms.domain.teacher.model.Teacher + +interface CommandHomeroomTeacherService { + fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher) +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/HomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/HomeroomTeacherService.kt new file mode 100644 index 00000000..24316aef --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/HomeroomTeacherService.kt @@ -0,0 +1,10 @@ +package team.msg.sms.domain.teacher.service + +import team.msg.sms.common.annotation.Service + +@Service +class HomeroomTeacherService ( + checkHomeroomTeacherService: CheckHomeroomTeacherService, + commandHomeroomTeacherService: CommandHomeroomTeacherService +) : CheckHomeroomTeacherService by checkHomeroomTeacherService, + CommandHomeroomTeacherService by commandHomeroomTeacherService \ No newline at end of file From 088ca995c1c7595e616beefe5573f310f44e0d7b Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 20:30:53 +0900 Subject: [PATCH 30/50] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/domain/teacher/service/CheckHomeroomTeacherService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt index cfd85546..9f308e14 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt @@ -3,5 +3,5 @@ package team.msg.sms.domain.teacher.service import team.msg.sms.domain.teacher.model.Teacher interface CheckHomeroomTeacherService { - fun checkTeacherExistsByTeacher(teacher: Teacher) + fun checkHomeroomTeacherExistsByTeacher(teacher: Teacher) } \ No newline at end of file From ab29cb8696e21e6d2451a4ed352d3bc9bce41bb0 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 21:04:46 +0900 Subject: [PATCH 31/50] =?UTF-8?q?:recycle:=20=EB=A7=A4=EA=B0=9C=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/domain/teacher/service/CheckHomeroomTeacherService.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt index 9f308e14..8ef60c0b 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt @@ -1,7 +1,5 @@ package team.msg.sms.domain.teacher.service -import team.msg.sms.domain.teacher.model.Teacher - interface CheckHomeroomTeacherService { - fun checkHomeroomTeacherExistsByTeacher(teacher: Teacher) + fun checkHomeroomTeacherExistsByTeacher(grade: Int, classNum: Int) } \ No newline at end of file From 920635a0d269dbbf5b461798903a3f24e1c57006 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 21:32:00 +0900 Subject: [PATCH 32/50] :sparkles: homeroom port --- .../domain/teacher/spi/HomeroomTeacherPort.kt | 5 ++++ .../teacher/spi/QueryHomeroomTeacherPort.kt | 5 ++++ .../usecase/SignUpHomeroomTeacherUseCase.kt | 23 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/HomeroomTeacherPort.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryHomeroomTeacherPort.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/HomeroomTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/HomeroomTeacherPort.kt new file mode 100644 index 00000000..71a4ea90 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/HomeroomTeacherPort.kt @@ -0,0 +1,5 @@ +package team.msg.sms.domain.teacher.spi + +interface HomeroomTeacherPort : + QueryHomeroomTeacherPort, + CommandHomeroomTeacherPort \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryHomeroomTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryHomeroomTeacherPort.kt new file mode 100644 index 00000000..0a3db192 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/QueryHomeroomTeacherPort.kt @@ -0,0 +1,5 @@ +package team.msg.sms.domain.teacher.spi + +interface QueryHomeroomTeacherPort { + fun existsHomeroomTeacherByGradeAndClassNum(grade: Int, classNum: Int): Boolean +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt new file mode 100644 index 00000000..975f44ef --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt @@ -0,0 +1,23 @@ +package team.msg.sms.domain.teacher.usecase + +import org.springframework.transaction.annotation.Transactional +import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.teacher.dto.req.SignUpHomeroomTeacherRequestData +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.service.UserService + +@UseCase +class SignUpHomeroomTeacherUseCase( + private val userService: UserService, + private val teacherService: TeacherService +) { + + @Transactional(rollbackFor = [Exception::class]) + fun execute(signUpHomeroomTeacherRequestData: SignUpHomeroomTeacherRequestData) { + val user = userService.getCurrentUser() + + teacherService.checkTeacherExistsByUser(user) + + teacherService.saveTeacher(user) + } +} \ No newline at end of file From d231c888713360cfae91ba8974e1f2ca36264ac0 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 21:33:48 +0900 Subject: [PATCH 33/50] :sparkles: web request --- .../dto/req/SignUpHomeroomTeacherRequestData.kt | 6 ++++++ .../teacher/spi/CommandHomeroomTeacherPort.kt | 8 ++++++++ .../msg/sms/domain/teacher/TeacherWebAdapter.kt | 14 ++++++++++++-- .../dto/req/SignUpHomeroomTeacherWebRequest.kt | 8 +++++++- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherRequestData.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherRequestData.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherRequestData.kt new file mode 100644 index 00000000..e665e507 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherRequestData.kt @@ -0,0 +1,6 @@ +package team.msg.sms.domain.teacher.dto.req + +data class SignUpHomeroomTeacherRequestData( + val grade: Int, + val classNum: Int +) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt new file mode 100644 index 00000000..83d2235c --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.spi + +import team.msg.sms.domain.teacher.model.HomeroomTeacher +import team.msg.sms.domain.teacher.model.Teacher + +interface CommandHomeroomTeacherPort { + fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher) +} \ No newline at end of file diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt index 8b7c6574..46d0cfc3 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt @@ -3,17 +3,27 @@ package team.msg.sms.domain.teacher import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity 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 +import team.msg.sms.domain.teacher.dto.req.SignUpHomeroomTeacherWebRequest +import team.msg.sms.domain.teacher.usecase.SignUpHomeroomTeacherUseCase import team.msg.sms.domain.teacher.usecase.SignUpTeacherUseCase +import javax.validation.Valid @RestController @RequestMapping("/teacher") class TeacherWebAdapter( - private val signUpUseCase: SignUpTeacherUseCase + private val signUpTeacherUseCase: SignUpTeacherUseCase, + private val signUpHomeroomTeacherUseCase: SignUpHomeroomTeacherUseCase ) { @PostMapping("/common") fun signUpTeacher(): ResponseEntity = - signUpUseCase.execute() + signUpTeacherUseCase.execute() + .let { ResponseEntity.status(HttpStatus.CREATED).build() } + + @PostMapping("/homeroom") + fun signUpHomeroomTeacher(@RequestBody @Valid signUpHomeroomTeacherWebRequest: SignUpHomeroomTeacherWebRequest): ResponseEntity = + signUpHomeroomTeacherUseCase.execute(signUpHomeroomTeacherWebRequest.toData()) .let { ResponseEntity.status(HttpStatus.CREATED).build() } } diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt index 4239ef9a..d87e97a9 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/dto/req/SignUpHomeroomTeacherWebRequest.kt @@ -14,4 +14,10 @@ data class SignUpHomeroomTeacherWebRequest( @field:Max(4) @field:NotNull val classNum: Int -) +) { + fun toData(): SignUpHomeroomTeacherRequestData = + SignUpHomeroomTeacherRequestData( + grade = grade, + classNum = classNum + ) +} From fa6e4a618fd3ce9e70cb095287e90fb9d9f95f53 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 22:13:11 +0900 Subject: [PATCH 34/50] :sparkles: homeroom persistence adapter --- .../teacher/spi/CommandHomeroomTeacherPort.kt | 3 ++- .../HomeroomTeacherPersistenceAdapter.kt | 22 +++++++++++++++++++ .../teacher/mapper/HomeroomTeacherMapper.kt | 21 ++++++++++++++++++ .../HomeroomTeacherJpaRepository.kt | 4 +++- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/HomeroomTeacherPersistenceAdapter.kt create mode 100644 sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/HomeroomTeacherMapper.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt index 83d2235c..c83f2a5c 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/spi/CommandHomeroomTeacherPort.kt @@ -2,7 +2,8 @@ package team.msg.sms.domain.teacher.spi import team.msg.sms.domain.teacher.model.HomeroomTeacher import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.user.model.User interface CommandHomeroomTeacherPort { - fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher) + fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User): HomeroomTeacher } \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/HomeroomTeacherPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/HomeroomTeacherPersistenceAdapter.kt new file mode 100644 index 00000000..a2a89b63 --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/HomeroomTeacherPersistenceAdapter.kt @@ -0,0 +1,22 @@ +package team.msg.sms.persistence.teacher + +import org.springframework.stereotype.Component +import team.msg.sms.domain.teacher.model.HomeroomTeacher +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.teacher.spi.HomeroomTeacherPort +import team.msg.sms.domain.user.model.User +import team.msg.sms.persistence.teacher.mapper.toDomain +import team.msg.sms.persistence.teacher.mapper.toEntity +import team.msg.sms.persistence.teacher.repository.HomeroomTeacherJpaRepository +import team.msg.sms.persistence.user.mapper.toEntity + +@Component +class HomeroomTeacherPersistenceAdapter( + private val homeroomTeacherJpaRepository: HomeroomTeacherJpaRepository +) : HomeroomTeacherPort { + override fun existsHomeroomTeacherByGradeAndClassNum(grade: Int, classNum: Int): Boolean = + homeroomTeacherJpaRepository.existsByGradeAndClassNum(grade, classNum) + + override fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User): HomeroomTeacher = + homeroomTeacherJpaRepository.save(homeroomTeacher.toEntity(teacher.toEntity(user.toEntity()))).toDomain() +} \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/HomeroomTeacherMapper.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/HomeroomTeacherMapper.kt new file mode 100644 index 00000000..a208197d --- /dev/null +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/mapper/HomeroomTeacherMapper.kt @@ -0,0 +1,21 @@ +package team.msg.sms.persistence.teacher.mapper + +import team.msg.sms.domain.teacher.model.HomeroomTeacher +import team.msg.sms.persistence.teacher.entity.HomeroomTeacherJpaEntity +import team.msg.sms.persistence.teacher.entity.TeacherJpaEntity + +fun HomeroomTeacher.toEntity(teacher: TeacherJpaEntity) = + HomeroomTeacherJpaEntity( + id = id, + grade = grade, + classNum = classNum, + teacher = teacher + ) + +fun HomeroomTeacherJpaEntity.toDomain() = + HomeroomTeacher( + id = id, + grade = grade, + classNum = classNum, + teacherId = teacher.id + ) \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt index 5cbd37ae..c637ccb7 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/repository/HomeroomTeacherJpaRepository.kt @@ -5,4 +5,6 @@ import org.springframework.stereotype.Repository import team.msg.sms.persistence.teacher.entity.HomeroomTeacherJpaEntity @Repository -interface HomeroomTeacherJpaRepository : CrudRepository \ No newline at end of file +interface HomeroomTeacherJpaRepository : CrudRepository { + fun existsByGradeAndClassNum(grade: Int, classNum: Int): Boolean +} \ No newline at end of file From b0c991bfb847d5c42ac7e80ba566cde42ac5572f Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 22:22:13 +0900 Subject: [PATCH 35/50] =?UTF-8?q?:sparkles:=20check=20homeroom=20teacher?= =?UTF-8?q?=20service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/HomeroomTeacherAlreadyException.kt | 8 ++++++++ .../teacher/exception/error/TeacherErrorCode.kt | 3 ++- .../service/CheckHomeroomTeacherService.kt | 2 +- .../impl/CheckHomeroomTeacherServiceImpl.kt | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/HomeroomTeacherAlreadyException.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckHomeroomTeacherServiceImpl.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/HomeroomTeacherAlreadyException.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/HomeroomTeacherAlreadyException.kt new file mode 100644 index 00000000..221e11bc --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/HomeroomTeacherAlreadyException.kt @@ -0,0 +1,8 @@ +package team.msg.sms.domain.teacher.exception + +import team.msg.sms.common.error.SmsException +import team.msg.sms.domain.teacher.exception.error.TeacherErrorCode + +object HomeroomTeacherAlreadyException : SmsException( + TeacherErrorCode.HOMEROOM_TEACHER_ALREADY +) \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt index 0f16d240..501b6fb8 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/exception/error/TeacherErrorCode.kt @@ -8,7 +8,8 @@ enum class TeacherErrorCode( private val message: String ) : ErrorProperty { - TEACHER_ALREADY(ErrorStatus.CONFLICT, "선생님 정보가 존재하는 유저입니다"), + TEACHER_ALREADY(ErrorStatus.CONFLICT, "선생님 정보가 존재하는 유저입니다."), + HOMEROOM_TEACHER_ALREADY(ErrorStatus.CONFLICT, "동일 정보의 담임선생님이 존재합니다."), ; override fun status(): Int = status diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt index 8ef60c0b..f0104d28 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CheckHomeroomTeacherService.kt @@ -1,5 +1,5 @@ package team.msg.sms.domain.teacher.service interface CheckHomeroomTeacherService { - fun checkHomeroomTeacherExistsByTeacher(grade: Int, classNum: Int) + fun checkHomeroomTeacherExistsByGradeAndClassNum(grade: Int, classNum: Int) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckHomeroomTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckHomeroomTeacherServiceImpl.kt new file mode 100644 index 00000000..5c59c697 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CheckHomeroomTeacherServiceImpl.kt @@ -0,0 +1,16 @@ +package team.msg.sms.domain.teacher.service.impl + +import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.teacher.exception.HomeroomTeacherAlreadyException +import team.msg.sms.domain.teacher.service.CheckHomeroomTeacherService +import team.msg.sms.domain.teacher.spi.HomeroomTeacherPort + +@Service +class CheckHomeroomTeacherServiceImpl( + private val homeroomTeacherPort: HomeroomTeacherPort +) : CheckHomeroomTeacherService { + override fun checkHomeroomTeacherExistsByGradeAndClassNum(grade: Int, classNum: Int) { + if (homeroomTeacherPort.existsHomeroomTeacherByGradeAndClassNum(grade, classNum)) + throw HomeroomTeacherAlreadyException + } +} \ No newline at end of file From 4482ed2e23a1e470ed3881237d2858e13eb2a80b Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 23:53:18 +0900 Subject: [PATCH 36/50] :sparkles: save homeroom teacher --- .../service/CommandHomeroomTeacherService.kt | 3 ++- .../impl/CommandHomeroomTeacherServiceImpl.kt | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt index 7e9dc4ea..530ee833 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt @@ -2,7 +2,8 @@ package team.msg.sms.domain.teacher.service import team.msg.sms.domain.teacher.model.HomeroomTeacher import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.user.model.User interface CommandHomeroomTeacherService { - fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher) + fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt new file mode 100644 index 00000000..2b576785 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt @@ -0,0 +1,23 @@ +package team.msg.sms.domain.teacher.service.impl + +import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.auth.model.Role +import team.msg.sms.domain.teacher.model.HomeroomTeacher +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.teacher.service.CommandHomeroomTeacherService +import team.msg.sms.domain.teacher.spi.HomeroomTeacherPort +import team.msg.sms.domain.user.model.User +import team.msg.sms.domain.user.spi.UserPort + +@Service +class CommandHomeroomTeacherServiceImpl( + private val homeroomTeacherPort: HomeroomTeacherPort, + private val userPort: UserPort +) : CommandHomeroomTeacherService { + override fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User) { + homeroomTeacherPort.saveHomeroomTeacher(homeroomTeacher, teacher, user) + + user.roles.add(Role.ROLE_HOMEROOM) + userPort.saveUser(user) + } +} \ No newline at end of file From eb0718fb8e23163fa742141dbcbdd1e87e410ff7 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Fri, 16 Feb 2024 23:59:53 +0900 Subject: [PATCH 37/50] :sparkles: save homeroom teacher usecase --- .../domain/teacher/model/HomeroomTeacher.kt | 2 +- .../teacher/service/CommandTeacherService.kt | 3 ++- .../service/impl/CommandTeacherServiceImpl.kt | 4 ++-- .../usecase/SignUpHomeroomTeacherUseCase.kt | 20 +++++++++++++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt index 2098558b..9a9b791b 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/model/HomeroomTeacher.kt @@ -5,7 +5,7 @@ import java.util.* @Aggregate data class HomeroomTeacher ( - val id: Long, + val id: Long = 0, val grade: Int, val classNum: Int, val teacherId: UUID, diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt index 3768df81..740c2c61 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt @@ -1,7 +1,8 @@ package team.msg.sms.domain.teacher.service +import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.user.model.User interface CommandTeacherService { - fun saveTeacher(user: User) + fun saveTeacher(user: User): Teacher } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt index 1d40a691..39803bd3 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt @@ -11,12 +11,12 @@ import java.util.* class CommandTeacherServiceImpl( private val teacherPort: TeacherPort ) : CommandTeacherService { - override fun saveTeacher(user: User) { + override fun saveTeacher(user: User): Teacher { val teacher = Teacher( id = UUID.randomUUID(), userId = user.id, ) - teacherPort.saveTeacher(teacher, user) + return teacherPort.saveTeacher(teacher, user) } } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt index 975f44ef..456c98e1 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt @@ -3,13 +3,17 @@ package team.msg.sms.domain.teacher.usecase import org.springframework.transaction.annotation.Transactional import team.msg.sms.common.annotation.UseCase import team.msg.sms.domain.teacher.dto.req.SignUpHomeroomTeacherRequestData +import team.msg.sms.domain.teacher.model.HomeroomTeacher +import team.msg.sms.domain.teacher.service.CommandHomeroomTeacherService +import team.msg.sms.domain.teacher.service.HomeroomTeacherService import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.service.UserService @UseCase class SignUpHomeroomTeacherUseCase( private val userService: UserService, - private val teacherService: TeacherService + private val teacherService: TeacherService, + private val homeroomTeacherService: HomeroomTeacherService ) { @Transactional(rollbackFor = [Exception::class]) @@ -18,6 +22,18 @@ class SignUpHomeroomTeacherUseCase( teacherService.checkTeacherExistsByUser(user) - teacherService.saveTeacher(user) + val teacher = teacherService.saveTeacher(user) + val grade = signUpHomeroomTeacherRequestData.grade + val classNum = signUpHomeroomTeacherRequestData.classNum + + homeroomTeacherService.checkHomeroomTeacherExistsByGradeAndClassNum(grade, classNum) + + val homeroomTeacher = HomeroomTeacher( + grade = grade, + classNum = classNum, + teacherId = teacher.id + ) + + homeroomTeacherService.saveHomeroomTeacher(homeroomTeacher, teacher, user) } } \ No newline at end of file From 98fba80303a35e8438d95d18878d1fe3b6f078ea Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 17 Feb 2024 03:23:04 +0900 Subject: [PATCH 38/50] =?UTF-8?q?:bug:=20cascade=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EB=90=98=EC=96=B4=20=EC=A0=80=EC=9E=A5=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt index cafba45a..d9d1f9b0 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/teacher/entity/HomeroomTeacherJpaEntity.kt @@ -14,7 +14,7 @@ class HomeroomTeacherJpaEntity ( @Column(name = "class_num") val classNum: Int, - @OneToOne(cascade = [CascadeType.ALL]) + @OneToOne @JoinColumn(name = "teacher_id") val teacher: TeacherJpaEntity ) : BaseIdEntity() \ No newline at end of file From 5b5cbfb53266bf62de19a3338075f77615237ffa Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sat, 17 Feb 2024 03:26:41 +0900 Subject: [PATCH 39/50] =?UTF-8?q?:recycle:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=97=AD=ED=95=A0=20=EC=8A=AC=EB=9E=98=EC=89=AC=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt index db4806d1..473cc536 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt @@ -13,7 +13,7 @@ class VerifyAccessUseCase( .let { VerifyAccessResponseData( userService.checkNewUser(it), - it.roles[0].name + it.roles.joinToString("/") ) } } \ No newline at end of file From 2bbba37fdcfb1c1a7d6ae4067fd17e1a079730cc Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 15:04:01 +0900 Subject: [PATCH 40/50] =?UTF-8?q?:recycle:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=97=AD=ED=95=A0=20=EC=8A=AC=EB=9E=98=EC=89=AC=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84=20=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt index 473cc536..13ccc416 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/VerifyAccessUseCase.kt @@ -8,6 +8,10 @@ import team.msg.sms.domain.user.service.UserService class VerifyAccessUseCase( private val userService: UserService ) { + /** + * Role에 대한 반환 타입이 list가 아닌 단일 string이라 슬래시로 구분해두었습니다. + * 추후 response를 변경하게 되면 바꿔도 괜찮을 거 같아요! + */ fun execute(): VerifyAccessResponseData = userService.getCurrentUser() .let { From 0e890385f3e0d65e857e0d434c60ea146b3686c2 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 17:01:51 +0900 Subject: [PATCH 41/50] =?UTF-8?q?:sparkles:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=A0=80=EC=9E=A5=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/sms/domain/user/service/CommandUserService.kt | 2 ++ .../domain/user/service/impl/CommandUserServiceImpl.kt | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CommandUserService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CommandUserService.kt index e8cbf0da..a4e53f2d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CommandUserService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/CommandUserService.kt @@ -1,9 +1,11 @@ package team.msg.sms.domain.user.service +import team.msg.sms.domain.auth.model.Role import team.msg.sms.domain.user.model.User import java.util.UUID interface CommandUserService { fun createUserWhenNotExistUser(existUser: Boolean, user: User): User + fun saveRoles(user: User, role: List): User fun deleteByUuid(userId: UUID) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CommandUserServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CommandUserServiceImpl.kt index b7c2b6fe..68030391 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CommandUserServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/user/service/impl/CommandUserServiceImpl.kt @@ -1,11 +1,10 @@ package team.msg.sms.domain.user.service.impl import team.msg.sms.common.annotation.Service +import team.msg.sms.domain.auth.model.Role import team.msg.sms.domain.user.exception.UserNotFoundException import team.msg.sms.domain.user.model.User import team.msg.sms.domain.user.service.CommandUserService -import team.msg.sms.domain.user.spi.CommandUserPort -import team.msg.sms.domain.user.spi.QueryUserPort import team.msg.sms.domain.user.spi.UserPort import java.util.* @@ -21,6 +20,11 @@ class CommandUserServiceImpl( } } + override fun saveRoles(user: User, role: List): User { + user.roles.addAll(role) + return userPort.saveUser(user) + } + override fun deleteByUuid(userId: UUID) = userPort.deleteByUuid(userId) } \ No newline at end of file From 5d3419721780a4fcf42539018f0d8b67681af803 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 17:02:40 +0900 Subject: [PATCH 42/50] =?UTF-8?q?:recycle:=20teacher=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teacher/service/CommandTeacherService.kt | 3 ++- .../service/impl/CommandTeacherServiceImpl.kt | 12 ++++------ .../usecase/SignUpHomeroomTeacherUseCase.kt | 22 +++++++++++++------ .../teacher/usecase/SignUpTeacherUseCase.kt | 9 +++++++- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt index 740c2c61..ed245629 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt @@ -4,5 +4,6 @@ import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.user.model.User interface CommandTeacherService { - fun saveTeacher(user: User): Teacher + fun saveTeacher(teacher: Teacher, user: User): Teacher + fun saveDirectorTeacher(teacher: Teacher, user: User): Teacher } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt index 39803bd3..a6c9217f 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt @@ -5,18 +5,14 @@ import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.teacher.service.CommandTeacherService import team.msg.sms.domain.teacher.spi.TeacherPort import team.msg.sms.domain.user.model.User -import java.util.* @Service class CommandTeacherServiceImpl( private val teacherPort: TeacherPort ) : CommandTeacherService { - override fun saveTeacher(user: User): Teacher { - val teacher = Teacher( - id = UUID.randomUUID(), - userId = user.id, - ) + override fun saveTeacher(teacher: Teacher, user: User) = + teacherPort.saveTeacher(teacher, user) - return teacherPort.saveTeacher(teacher, user) - } + override fun saveDirectorTeacher(teacher: Teacher, user: User) = + saveTeacher(teacher, user) } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt index 456c98e1..8c824762 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpHomeroomTeacherUseCase.kt @@ -2,12 +2,14 @@ package team.msg.sms.domain.teacher.usecase import org.springframework.transaction.annotation.Transactional import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.auth.model.Role import team.msg.sms.domain.teacher.dto.req.SignUpHomeroomTeacherRequestData import team.msg.sms.domain.teacher.model.HomeroomTeacher -import team.msg.sms.domain.teacher.service.CommandHomeroomTeacherService +import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.teacher.service.HomeroomTeacherService import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.service.UserService +import java.util.* @UseCase class SignUpHomeroomTeacherUseCase( @@ -19,21 +21,27 @@ class SignUpHomeroomTeacherUseCase( @Transactional(rollbackFor = [Exception::class]) fun execute(signUpHomeroomTeacherRequestData: SignUpHomeroomTeacherRequestData) { val user = userService.getCurrentUser() - - teacherService.checkTeacherExistsByUser(user) - - val teacher = teacherService.saveTeacher(user) val grade = signUpHomeroomTeacherRequestData.grade val classNum = signUpHomeroomTeacherRequestData.classNum + teacherService.checkTeacherExistsByUser(user) homeroomTeacherService.checkHomeroomTeacherExistsByGradeAndClassNum(grade, classNum) + val teacher = Teacher( + id = UUID.randomUUID(), + userId = user.id, + ) + + val savedTeacher = teacherService.saveTeacher(teacher, user) + val homeroomTeacher = HomeroomTeacher( grade = grade, classNum = classNum, - teacherId = teacher.id + teacherId = savedTeacher.id ) - homeroomTeacherService.saveHomeroomTeacher(homeroomTeacher, teacher, user) + homeroomTeacherService.saveHomeroomTeacher(homeroomTeacher, savedTeacher, user) + + userService.saveRoles(user, mutableListOf(Role.ROLE_HOMEROOM)) } } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt index ed8dddb3..12fb7d3b 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpTeacherUseCase.kt @@ -2,8 +2,10 @@ package team.msg.sms.domain.teacher.usecase import org.springframework.transaction.annotation.Transactional import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.teacher.service.TeacherService import team.msg.sms.domain.user.service.UserService +import java.util.* @UseCase class SignUpTeacherUseCase( @@ -16,6 +18,11 @@ class SignUpTeacherUseCase( teacherService.checkTeacherExistsByUser(user) - teacherService.saveTeacher(user) + val teacher = Teacher( + id = UUID.randomUUID(), + userId = user.id, + ) + + teacherService.saveTeacher(teacher, user) } } \ No newline at end of file From 196b64d56f8f2f3f6686325cd90520613b77ec0a Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 17:03:23 +0900 Subject: [PATCH 43/50] =?UTF-8?q?:recycle:=20homeroom=20teacher=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/domain/teacher/service/CommandHomeroomTeacherService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt index 530ee833..53ccc67d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandHomeroomTeacherService.kt @@ -5,5 +5,5 @@ import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.user.model.User interface CommandHomeroomTeacherService { - fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User) + fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User): HomeroomTeacher } \ No newline at end of file From 1e50ba8aa2b56923306d2150a2efee40aa46eb17 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 17:04:30 +0900 Subject: [PATCH 44/50] =?UTF-8?q?:sparkles:=20=EB=B6=80=EC=9E=A5=20?= =?UTF-8?q?=EC=84=A0=EC=83=9D=EB=8B=98=EC=9C=BC=EB=A1=9C=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20usecase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/CommandHomeroomTeacherServiceImpl.kt | 11 ++----- .../usecase/SignUpDirectorTeacherUseCase.kt | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDirectorTeacherUseCase.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt index 2b576785..0775412a 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandHomeroomTeacherServiceImpl.kt @@ -1,23 +1,16 @@ package team.msg.sms.domain.teacher.service.impl import team.msg.sms.common.annotation.Service -import team.msg.sms.domain.auth.model.Role import team.msg.sms.domain.teacher.model.HomeroomTeacher import team.msg.sms.domain.teacher.model.Teacher import team.msg.sms.domain.teacher.service.CommandHomeroomTeacherService import team.msg.sms.domain.teacher.spi.HomeroomTeacherPort import team.msg.sms.domain.user.model.User -import team.msg.sms.domain.user.spi.UserPort @Service class CommandHomeroomTeacherServiceImpl( - private val homeroomTeacherPort: HomeroomTeacherPort, - private val userPort: UserPort + private val homeroomTeacherPort: HomeroomTeacherPort ) : CommandHomeroomTeacherService { - override fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User) { + override fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User) = homeroomTeacherPort.saveHomeroomTeacher(homeroomTeacher, teacher, user) - - user.roles.add(Role.ROLE_HOMEROOM) - userPort.saveUser(user) - } } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDirectorTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDirectorTeacherUseCase.kt new file mode 100644 index 00000000..74e9aba9 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDirectorTeacherUseCase.kt @@ -0,0 +1,32 @@ +package team.msg.sms.domain.teacher.usecase + +import org.springframework.transaction.annotation.Transactional +import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.auth.model.Role +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.service.UserService +import java.util.* + +@UseCase +class SignUpDirectorTeacherUseCase( + private val userService: UserService, + private val teacherService: TeacherService +) { + + @Transactional(rollbackFor = [Exception::class]) + fun execute(){ + val user = userService.getCurrentUser() + + teacherService.checkTeacherExistsByUser(user) + + val teacher = Teacher( + id = UUID.randomUUID(), + userId = user.id, + ) + + teacherService.saveDirectorTeacher(teacher, user) + + userService.saveRoles(user, mutableListOf(Role.ROLE_DIRECTOR)) + } +} \ No newline at end of file From 26ce915199d63ab0f70670064ed9c8436031c0a2 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 17:07:07 +0900 Subject: [PATCH 45/50] =?UTF-8?q?:sparkles:=20=EB=B6=80=EC=9E=A5=20?= =?UTF-8?q?=EC=84=A0=EC=83=9D=EB=8B=98=EC=9C=BC=EB=A1=9C=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20endpoint=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/team/msg/sms/global/security/SecurityConfig.kt | 2 ++ .../team/msg/sms/domain/teacher/TeacherWebAdapter.kt | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt index 0b5bcabb..86270be2 100644 --- a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt +++ b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt @@ -64,6 +64,8 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/student/anonymous/{uuid}").permitAll() .antMatchers(HttpMethod.POST, "/teacher/common").hasAuthority(TEACHER) + .antMatchers(HttpMethod.POST, "/teacher/director").hasAuthority(TEACHER) + .antMatchers(HttpMethod.POST, "/teacher/homeroom").hasAuthority(TEACHER) .antMatchers(HttpMethod.POST, "/file").authenticated() .antMatchers(HttpMethod.POST, "/file/image").authenticated() diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt index 46d0cfc3..7a083ffd 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import team.msg.sms.domain.teacher.dto.req.SignUpHomeroomTeacherWebRequest +import team.msg.sms.domain.teacher.usecase.SignUpDirectorTeacherUseCase import team.msg.sms.domain.teacher.usecase.SignUpHomeroomTeacherUseCase import team.msg.sms.domain.teacher.usecase.SignUpTeacherUseCase import javax.validation.Valid @@ -15,6 +16,7 @@ import javax.validation.Valid @RequestMapping("/teacher") class TeacherWebAdapter( private val signUpTeacherUseCase: SignUpTeacherUseCase, + private val signUpDirectorTeacherUseCase: SignUpDirectorTeacherUseCase, private val signUpHomeroomTeacherUseCase: SignUpHomeroomTeacherUseCase ) { @PostMapping("/common") @@ -22,6 +24,11 @@ class TeacherWebAdapter( signUpTeacherUseCase.execute() .let { ResponseEntity.status(HttpStatus.CREATED).build() } + @PostMapping("/director") + fun signUpDirectorTeacher(): ResponseEntity = + signUpDirectorTeacherUseCase.execute() + .let { ResponseEntity.status(HttpStatus.CREATED).build() } + @PostMapping("/homeroom") fun signUpHomeroomTeacher(@RequestBody @Valid signUpHomeroomTeacherWebRequest: SignUpHomeroomTeacherWebRequest): ResponseEntity = signUpHomeroomTeacherUseCase.execute(signUpHomeroomTeacherWebRequest.toData()) From ec5eb91bd5bcf459fc39e21ce1ff81fdd1382d65 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 20:07:03 +0900 Subject: [PATCH 46/50] =?UTF-8?q?:sparkles:=20=EA=B5=90=EC=9E=A5,=20?= =?UTF-8?q?=EA=B5=90=EA=B0=90=20=EC=84=A0=EC=83=9D=EB=8B=98=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EC=9E=85=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/sms/domain/teacher/service/CommandTeacherService.kt | 2 ++ .../teacher/service/impl/CommandTeacherServiceImpl.kt | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt index ed245629..10398e4d 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/CommandTeacherService.kt @@ -6,4 +6,6 @@ import team.msg.sms.domain.user.model.User interface CommandTeacherService { fun saveTeacher(teacher: Teacher, user: User): Teacher fun saveDirectorTeacher(teacher: Teacher, user: User): Teacher + fun saveDeputyPrincipalTeacher(teacher: Teacher, user: User): Teacher + fun savePrincipalTeacher(teacher: Teacher, user: User): Teacher } \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt index a6c9217f..0216d54a 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/service/impl/CommandTeacherServiceImpl.kt @@ -15,4 +15,10 @@ class CommandTeacherServiceImpl( override fun saveDirectorTeacher(teacher: Teacher, user: User) = saveTeacher(teacher, user) + + override fun saveDeputyPrincipalTeacher(teacher: Teacher, user: User) = + saveTeacher(teacher, user) + + override fun savePrincipalTeacher(teacher: Teacher, user: User) = + saveTeacher(teacher, user) } \ No newline at end of file From 4a7bda5468b056e4c434429c919c97d7856035f8 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 20:07:13 +0900 Subject: [PATCH 47/50] =?UTF-8?q?:sparkles:=20=EA=B5=90=EC=9E=A5,=20?= =?UTF-8?q?=EA=B5=90=EA=B0=90=20=EC=84=A0=EC=83=9D=EB=8B=98=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EC=9E=85=20usecase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SignUpDeputyPrincipalTeacherUseCase.kt | 32 +++++++++++++++++++ .../usecase/SignUpPrincipalTeacherUseCase.kt | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDeputyPrincipalTeacherUseCase.kt create mode 100644 sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpPrincipalTeacherUseCase.kt diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDeputyPrincipalTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDeputyPrincipalTeacherUseCase.kt new file mode 100644 index 00000000..75ac4837 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpDeputyPrincipalTeacherUseCase.kt @@ -0,0 +1,32 @@ +package team.msg.sms.domain.teacher.usecase + +import org.springframework.transaction.annotation.Transactional +import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.auth.model.Role +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.service.UserService +import java.util.* + +@UseCase +class SignUpDeputyPrincipalTeacherUseCase( + private val userService: UserService, + private val teacherService: TeacherService +){ + + @Transactional(rollbackFor = [Exception::class]) + fun execute(){ + val user = userService.getCurrentUser() + + teacherService.checkTeacherExistsByUser(user) + + val teacher = Teacher( + id = UUID.randomUUID(), + userId = user.id, + ) + + teacherService.saveDeputyPrincipalTeacher(teacher, user) + + userService.saveRoles(user, mutableListOf(Role.ROLE_DEPUTY_PRINCIPAL)) + } +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpPrincipalTeacherUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpPrincipalTeacherUseCase.kt new file mode 100644 index 00000000..8afa9980 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/teacher/usecase/SignUpPrincipalTeacherUseCase.kt @@ -0,0 +1,32 @@ +package team.msg.sms.domain.teacher.usecase + +import org.springframework.transaction.annotation.Transactional +import team.msg.sms.common.annotation.UseCase +import team.msg.sms.domain.auth.model.Role +import team.msg.sms.domain.teacher.model.Teacher +import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.service.UserService +import java.util.* + +@UseCase +class SignUpPrincipalTeacherUseCase( + private val userService: UserService, + private val teacherService: TeacherService +){ + + @Transactional(rollbackFor = [Exception::class]) + fun execute(){ + val user = userService.getCurrentUser() + + teacherService.checkTeacherExistsByUser(user) + + val teacher = Teacher( + id = UUID.randomUUID(), + userId = user.id, + ) + + teacherService.savePrincipalTeacher(teacher, user) + + userService.saveRoles(user, mutableListOf(Role.ROLE_PRINCIPAL)) + } +} \ No newline at end of file From 60393bae1516897471cc32d472417b1b9b5e6b53 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Sun, 18 Feb 2024 20:07:26 +0900 Subject: [PATCH 48/50] =?UTF-8?q?:sparkles:=20=EA=B5=90=EC=9E=A5,=20?= =?UTF-8?q?=EA=B5=90=EA=B0=90=20=EC=84=A0=EC=83=9D=EB=8B=98=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EC=9E=85=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/sms/global/security/SecurityConfig.kt | 2 ++ .../msg/sms/domain/teacher/TeacherWebAdapter.kt | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt index 86270be2..b862cfc6 100644 --- a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt +++ b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt @@ -66,6 +66,8 @@ class SecurityConfig( .antMatchers(HttpMethod.POST, "/teacher/common").hasAuthority(TEACHER) .antMatchers(HttpMethod.POST, "/teacher/director").hasAuthority(TEACHER) .antMatchers(HttpMethod.POST, "/teacher/homeroom").hasAuthority(TEACHER) + .antMatchers(HttpMethod.POST, "/teacher/principal").hasAuthority(TEACHER) + .antMatchers(HttpMethod.POST, "/teacher/deputy-principal").hasAuthority(TEACHER) .antMatchers(HttpMethod.POST, "/file").authenticated() .antMatchers(HttpMethod.POST, "/file/image").authenticated() diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt index 7a083ffd..72db1129 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/teacher/TeacherWebAdapter.kt @@ -7,9 +7,7 @@ import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import team.msg.sms.domain.teacher.dto.req.SignUpHomeroomTeacherWebRequest -import team.msg.sms.domain.teacher.usecase.SignUpDirectorTeacherUseCase -import team.msg.sms.domain.teacher.usecase.SignUpHomeroomTeacherUseCase -import team.msg.sms.domain.teacher.usecase.SignUpTeacherUseCase +import team.msg.sms.domain.teacher.usecase.* import javax.validation.Valid @RestController @@ -17,6 +15,8 @@ import javax.validation.Valid class TeacherWebAdapter( private val signUpTeacherUseCase: SignUpTeacherUseCase, private val signUpDirectorTeacherUseCase: SignUpDirectorTeacherUseCase, + private val signUpDeputyPrincipalTeacherUseCase: SignUpDeputyPrincipalTeacherUseCase, + private val signUpPrincipalTeacherUseCase: SignUpPrincipalTeacherUseCase, private val signUpHomeroomTeacherUseCase: SignUpHomeroomTeacherUseCase ) { @PostMapping("/common") @@ -29,6 +29,16 @@ class TeacherWebAdapter( signUpDirectorTeacherUseCase.execute() .let { ResponseEntity.status(HttpStatus.CREATED).build() } + @PostMapping("/deputy-principal") + fun signUpDeputyPrincipalTeacher(): ResponseEntity = + signUpDeputyPrincipalTeacherUseCase.execute() + .let { ResponseEntity.status(HttpStatus.CREATED).build() } + + @PostMapping("/principal") + fun signUpPrincipalTeacher(): ResponseEntity = + signUpPrincipalTeacherUseCase.execute() + .let { ResponseEntity.status(HttpStatus.CREATED).build() } + @PostMapping("/homeroom") fun signUpHomeroomTeacher(@RequestBody @Valid signUpHomeroomTeacherWebRequest: SignUpHomeroomTeacherWebRequest): ResponseEntity = signUpHomeroomTeacherUseCase.execute(signUpHomeroomTeacherWebRequest.toData()) From 66edfc647ea8709589d9e1a5e1cb2dd5b0caef43 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Mon, 20 May 2024 18:10:30 +0900 Subject: [PATCH 49/50] =?UTF-8?q?update=20::=20=EC=A1=B8=EC=97=85=EC=83=9D?= =?UTF-8?q?=EB=8F=84=20=ED=95=99=EB=B2=88=EC=9D=84=20null=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt index ccda88d1..0c20e0ae 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/auth/usecase/SignInUseCase.kt @@ -73,6 +73,6 @@ class SignInUseCase( } private fun getStuNumValid(role: Role, gAuthUserInfo: GAuthUserInfo) = - if (role.name != "ROLE_TEACHER") "${gAuthUserInfo.grade}${gAuthUserInfo.classNum}${gAuthUserInfo.getNumber()}" else "" + if (role.name == "ROLE_STUDENT") "${gAuthUserInfo.grade}${gAuthUserInfo.classNum}${gAuthUserInfo.getNumber()}" else "" private fun GAuthUserInfo.getNumber() = String.format("%02d", this.num) \ No newline at end of file From ab95ed191f703d457d4048620137ff2a12f36644 Mon Sep 17 00:00:00 2001 From: ani2689 Date: Mon, 20 May 2024 18:10:30 +0900 Subject: [PATCH 50/50] =?UTF-8?q?update=20::=20=EC=A1=B8=EC=97=85=EC=83=9D?= =?UTF-8?q?=EB=8F=84=20=ED=95=99=EB=B2=88=EC=9D=84=20null=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit