Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

135 user accept api #136

Merged
merged 17 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
bdfa4f2
:sparkles: :: accept user request
esperar Apr 6, 2023
bbb2641
:sparkles: :: AcceptUserService
esperar Apr 6, 2023
77a09a7
:sparkles: :: accept user api
esperar Apr 6, 2023
92fcd4d
:art: :: security config accept-user path μΆ”κ°€
esperar Apr 6, 2023
89e843d
:recycle: :: getUser Role 인자둜 λ°›κΈ°
esperar Apr 6, 2023
47219d3
:recycle: :: BadUserRoleRequestException 으둜 λ˜μ§€κΈ°
esperar Apr 6, 2023
e4d5afa
:art: :: path둜 user id λ°›κ²Œ μˆ˜μ •
esperar Apr 6, 2023
2b086d3
:fire: :: accept user request id μ‚­μ œ
esperar Apr 6, 2023
fbb0bee
:recycle: :: Signup -> SignUp
esperar Apr 6, 2023
bfa24f3
:recycle: :: user accept μœ μ € κΆŒν•œ λΆ€μ—¬ μˆ˜μ •
esperar Apr 6, 2023
ba9f39c
:art: :: validation μΆ”κ°€
esperar Apr 6, 2023
1082003
:recycle: :: private fun μœ„λ‘œ μ˜¬λ €μ•Όν•˜λŠ”κ΅°μš”
esperar Apr 6, 2023
8e8ba97
:art: user role μ—…λ°μ΄νŠΈ
esperar Apr 6, 2023
36c2b4f
:recycle: :: 이름 λ°”κΎΈλ‹ˆκΉŒ redeclaration λ– μ„œ λ‹€μ‹œ λŒλ €λ†“κΈ°
esperar Apr 6, 2023
c9b7fe2
:art: :: update μ—μ„œ Teacher을 λΆ€μ—¬ν•˜λ„λ‘ λ³€κ²½
esperar Apr 6, 2023
110f617
:recycle: :: μœ μ €λ₯Ό μ—…λ°μ΄νŠΈν•˜λŠ” λΆ€λΆ„ μ½”λ“œ κ°œμ„ 
esperar Apr 6, 2023
74f5baf
:art: :: Accept student, teacher service도 let을 μ‚¬μš©
esperar Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/kotlin/com/msg/gauth/domain/user/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.msg.gauth.domain.user.enums.Gender
import com.msg.gauth.domain.user.enums.UserRole
import com.msg.gauth.domain.user.enums.UserState
import com.msg.gauth.domain.user.presentation.dto.request.AcceptStudentReqDto
import com.msg.gauth.domain.user.presentation.dto.request.AcceptUserReqDto
import com.msg.gauth.global.entity.BaseIdEntity
import javax.persistence.*
import javax.validation.constraints.Size
Expand Down Expand Up @@ -110,6 +111,23 @@ class User(
return user
}

fun update(acceptUserReqDto: AcceptUserReqDto): User{
val user = User(
name = acceptUserReqDto.name,
email = this.email,
grade = acceptUserReqDto.grade,
classNum = acceptUserReqDto.classNum,
num = acceptUserReqDto.num,
gender = acceptUserReqDto.gender,
password = this.password,
roles = this.roles,
state = UserState.CREATED,
profileUrl = this.profileUrl
)
user.id = this.id
return user
}

fun updateProfile(profileUrl: String): User{
val user = User(
name = this.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.msg.gauth.domain.user.presentation
import com.msg.gauth.domain.user.presentation.dto.response.GetMyRolesResDto
import com.msg.gauth.domain.user.presentation.dto.request.AcceptStudentReqDto
import com.msg.gauth.domain.user.presentation.dto.request.AcceptTeacherReqDto
import com.msg.gauth.domain.user.presentation.dto.request.AcceptUserReqDto
import com.msg.gauth.domain.user.presentation.dto.request.PasswordChangeReqDto
import com.msg.gauth.domain.user.presentation.dto.response.MyProfileResDto
import com.msg.gauth.domain.user.presentation.dto.response.SingleAcceptedUserResDto
Expand All @@ -24,7 +25,8 @@ class UserController(
private val acceptTeacherSignUpService: AcceptTeacherSignUpService,
private val getPendingUsersService: GetPendingUsersService,
private val acceptStudentSignUpService: AcceptStudentSignUpService,
private val getMyRolesService: GetMyRolesService
private val getMyRolesService: GetMyRolesService,
private val acceptUserSignUpService: AcceptUserSignUpService
) {
@GetMapping("/role")
fun getMyRoles(): ResponseEntity<GetMyRolesResDto> {
Expand Down Expand Up @@ -66,6 +68,12 @@ class UserController(
return ResponseEntity.ok(result)
}

@PatchMapping("/accept-user")
fun acceptUser(@RequestBody @Valid acceptUserReqDto: AcceptUserReqDto): ResponseEntity<Void>{
acceptUserSignUpService.execute(acceptUserReqDto)
return ResponseEntity.noContent().build()
}

esperar marked this conversation as resolved.
Show resolved Hide resolved
@Deprecated("This api is deprecated. Use acceptUser instead")
@PatchMapping("/accept-teacher")
fun acceptTeacher(@RequestBody @Valid acceptTeacherReqDto: AcceptTeacherReqDto): ResponseEntity<Void>{
Expand Down
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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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

data class AcceptUserReqDto(
val id: Long,
esperar marked this conversation as resolved.
Show resolved Hide resolved
val userRole: UserRole,
val name: String,
val gender: Gender,
val grade: Int?,
val classNum: Int?,
val num: Int?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.msg.gauth.domain.user.services

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
import com.msg.gauth.global.exception.exceptions.BadRequestException

@TransactionalService
class AcceptUserSignUpService(
private val userRepository: UserRepository
) {

private fun getUser(id: Long) =
userRepository.findByIdAndStateAndRoles(id, UserState.PENDING, mutableListOf(UserRole.ROLE_STUDENT))
?: throw UserNotFoundException()

private fun acceptStudent(acceptUserReqDto: AcceptUserReqDto) =
userRepository.save(getUser(acceptUserReqDto.id).update(acceptUserReqDto))


private fun acceptTeacher(acceptUserReqDto: AcceptUserReqDto) =
userRepository.save(getUser(acceptUserReqDto.id).update(acceptUserReqDto.name, acceptUserReqDto.gender))

fun execute(acceptUserReqDto: AcceptUserReqDto) =
when(acceptUserReqDto.userRole){
UserRole.ROLE_STUDENT -> acceptStudent(acceptUserReqDto)
UserRole.ROLE_TEACHER -> acceptTeacher(acceptUserReqDto)
else -> throw BadRequestException()
}

esperar marked this conversation as resolved.
Show resolved Hide resolved
esperar marked this conversation as resolved.
Show resolved Hide resolved

}
esperar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ enum class ErrorCode(
MANY_REQUEST_EMAIL_AUTH("15뢄에 μ΅œλŒ€ 3번 이메일 인증을 μš”μ²­ν•  수 μžˆμŠ΅λ‹ˆλ‹€.", 429),

MAIL_SEND_FAIL("메일을 λ³΄λ‚΄λŠ”λ° μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.", 500),
INTERNAL_SERVER_ERROR("μ„œλ²„ λ‚΄λΆ€ μ—λŸ¬", 500)

;
INTERNAL_SERVER_ERROR("μ„œλ²„ λ‚΄λΆ€ μ—λŸ¬", 500);
}
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)
esperar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class SecurityConfig(
.antMatchers(HttpMethod.PATCH, "/user/accept-teacher").hasRole("ADMIN")
.antMatchers(HttpMethod.GET, "/user/pending").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/user/accept-student").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/user/accept-user").hasRole("ADMIN")

.anyRequest().denyAll()
.and()
Expand Down