-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from GSM-MSG/135-user-accept-api
135 user accept api
- Loading branch information
Showing
13 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/msg/gauth/domain/client/exception/BadUserRoleRequestException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.msg.gauth.domain.client.exception | ||
|
||
import com.msg.gauth.global.exception.ErrorCode | ||
import com.msg.gauth.global.exception.exceptions.BasicException | ||
|
||
class BadUserRoleRequestException : BasicException(ErrorCode.BAD_USER_ROLE_REQUEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/kotlin/com/msg/gauth/domain/user/presentation/dto/request/AcceptTeacherReqDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.msg.gauth.domain.user.presentation.dto.request | ||
|
||
import com.msg.gauth.domain.user.enums.Gender | ||
import javax.validation.constraints.NotBlank | ||
|
||
data class AcceptTeacherReqDto( | ||
val id: Long, | ||
@field:NotBlank | ||
val name: String, | ||
val gender: Gender | ||
) |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/msg/gauth/domain/user/presentation/dto/request/AcceptUserReqDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.msg.gauth.domain.user.presentation.dto.request | ||
|
||
import com.msg.gauth.domain.user.enums.Gender | ||
import com.msg.gauth.domain.user.enums.UserRole | ||
import javax.validation.constraints.NotBlank | ||
import javax.validation.constraints.NotNull | ||
|
||
data class AcceptUserReqDto( | ||
@field:NotNull | ||
val userRole: UserRole, | ||
@field:NotBlank | ||
val name: String, | ||
@field:NotNull | ||
val gender: Gender, | ||
val grade: Int?, | ||
val classNum: Int?, | ||
val num: Int? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/msg/gauth/domain/user/services/AcceptUserSignUpService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.msg.gauth.domain.user.services | ||
|
||
import com.msg.gauth.domain.client.exception.BadUserRoleRequestException | ||
import com.msg.gauth.domain.user.enums.UserRole | ||
import com.msg.gauth.domain.user.enums.UserState | ||
import com.msg.gauth.domain.user.exception.UserNotFoundException | ||
import com.msg.gauth.domain.user.presentation.dto.request.AcceptUserReqDto | ||
import com.msg.gauth.domain.user.repository.UserRepository | ||
import com.msg.gauth.global.annotation.service.TransactionalService | ||
|
||
@TransactionalService | ||
class AcceptUserSignUpService( | ||
private val userRepository: UserRepository | ||
) { | ||
|
||
fun execute(id: Long, acceptUserReqDto: AcceptUserReqDto) = | ||
when(acceptUserReqDto.userRole){ | ||
UserRole.ROLE_STUDENT -> acceptStudent(id, acceptUserReqDto) | ||
UserRole.ROLE_TEACHER -> acceptTeacher(id, acceptUserReqDto) | ||
else -> throw BadUserRoleRequestException() | ||
} | ||
|
||
private fun getUser(id: Long) = | ||
userRepository.findByIdAndState(id, UserState.PENDING) | ||
?: throw UserNotFoundException() | ||
|
||
private fun acceptStudent(id: Long, acceptUserReqDto: AcceptUserReqDto) = | ||
getUser(id).update(acceptUserReqDto) | ||
.let { userRepository.save(it) } | ||
|
||
|
||
private fun acceptTeacher(id: Long, acceptUserReqDto: AcceptUserReqDto) = | ||
getUser(id).update(acceptUserReqDto.name, acceptUserReqDto.gender) | ||
.let { userRepository.save(it) } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/msg/gauth/global/exception/exceptions/BadRequestException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.msg.gauth.global.exception.exceptions | ||
|
||
import com.msg.gauth.global.exception.ErrorCode | ||
|
||
class BadRequestException : BasicException(ErrorCode.BAD_REQUEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters