Skip to content

Commit

Permalink
Merge pull request #312 from GSM-MSG/feature/311-master-teacher-merge
Browse files Browse the repository at this point in the history
master에 develop 변경사항 반영
  • Loading branch information
ani2689 authored May 26, 2024
2 parents fa12e92 + bb6068c commit c3b5c5b
Show file tree
Hide file tree
Showing 48 changed files with 687 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("담임선생님")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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.user.exception.InternalServerErrorException
import team.msg.sms.domain.user.model.User
import team.msg.sms.domain.user.service.UserService
Expand All @@ -23,8 +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 userService: UserService
) {

fun execute(request: SignInRequestData): SignInResponseData =
Expand All @@ -49,15 +47,15 @@ class SignInUseCase(

refreshTokenPort.saveRefreshToken(RefreshToken(refreshToken, user.id))

val isStudent = studentService.checkNewStudent(user, role.name)
val isExist = userService.checkNewUser(user)

SignInResponseData(
accessToken = accessToken,
accessTokenExp = accessTokenExp,
refreshToken = refreshToken,
refreshTokenExp = refreshTokenExp,
role = role,
isExist = isStudent
isExist = isExist
)
}.getOrElse { error ->
when (error) {
Expand All @@ -75,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)
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ 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.user.service.UserService

@UseCase
class VerifyAccessUseCase(
private val userService: UserService,
private val studentService: StudentService
private val userService: UserService
) {
/**
* Role에 대한 반환 타입이 list가 아닌 단일 string이라 슬래시로 구분해두었습니다.
* 추후 response를 변경하게 되면 바꿔도 괜찮을 거 같아요!
*/
fun execute(): VerifyAccessResponseData =
userService.getCurrentUser()
.let {
VerifyAccessResponseData(
studentService.checkNewStudent(it, it.roles[0].name),
it.roles[0].name
userService.checkNewUser(it),
it.roles.joinToString("/")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.msg.sms.domain.teacher.dto.req

data class SignUpHomeroomTeacherRequestData(
val grade: Int,
val classNum: Int
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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, "선생님 정보가 존재하는 유저입니다."),
HOMEROOM_TEACHER_ALREADY(ErrorStatus.CONFLICT, "동일 정보의 담임선생님이 존재합니다."),
;

override fun status(): Int = status
override fun message(): String = message
}
Original file line number Diff line number Diff line change
@@ -0,0 +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 = 0,
val grade: Int,
val classNum: Int,
val teacherId: UUID,
)
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.sms.domain.teacher.service

interface CheckHomeroomTeacherService {
fun checkHomeroomTeacherExistsByGradeAndClassNum(grade: Int, classNum: Int)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package team.msg.sms.domain.teacher.service

import team.msg.sms.domain.user.model.User

interface CheckTeacherService{
fun checkTeacherExistsByUser(user: User)
fun checkNewTeacher(user: User): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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, user: User): HomeroomTeacher
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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(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
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.msg.sms.domain.teacher.service

import team.msg.sms.common.annotation.Service

@Service
class TeacherService (
checkTeacherService: CheckTeacherService,
commandTeacherService: CommandTeacherService
) : CheckTeacherService by checkTeacherService,
CommandTeacherService by commandTeacherService
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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

@Service
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)
}
Original file line number Diff line number Diff line change
@@ -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.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

@Service
class CommandHomeroomTeacherServiceImpl(
private val homeroomTeacherPort: HomeroomTeacherPort
) : CommandHomeroomTeacherService {
override fun saveHomeroomTeacher(homeroomTeacher: HomeroomTeacher, teacher: Teacher, user: User) =
homeroomTeacherPort.saveHomeroomTeacher(homeroomTeacher, teacher, user)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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

@Service
class CommandTeacherServiceImpl(
private val teacherPort: TeacherPort
) : CommandTeacherService {
override fun saveTeacher(teacher: Teacher, user: User) =
teacherPort.saveTeacher(teacher, user)

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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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, user: User): HomeroomTeacher
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.sms.domain.teacher.spi

interface HomeroomTeacherPort :
QueryHomeroomTeacherPort,
CommandHomeroomTeacherPort
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.sms.domain.teacher.spi

interface QueryHomeroomTeacherPort {
fun existsHomeroomTeacherByGradeAndClassNum(grade: Int, classNum: Int): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.sms.domain.teacher.spi

interface TeacherPort :
QueryTeacherPort,
CommandTeacherPort
Loading

0 comments on commit c3b5c5b

Please sign in to comment.