Skip to content

Commit

Permalink
Merge pull request #103 from GSM-MSG/feat/accept-student
Browse files Browse the repository at this point in the history
Feat/accept student
  • Loading branch information
KimTaeO authored Mar 18, 2023
2 parents fd403f4 + d63135c commit 967aaf3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
17 changes: 17 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 @@ -3,6 +3,7 @@ package com.msg.gauth.domain.user
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.global.entity.BaseIdEntity
import javax.persistence.*
import javax.validation.constraints.Size
Expand Down Expand Up @@ -92,6 +93,22 @@ class User(
user.id = this.id
return user
}
fun update(acceptedStudentReqDto: AcceptStudentReqDto): User{
val user = User(
name = acceptedStudentReqDto.name,
email = this.email,
grade = acceptedStudentReqDto.grade,
classNum = acceptedStudentReqDto.classNum,
num = acceptedStudentReqDto.num,
gender = acceptedStudentReqDto.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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.gauth.domain.user.presentation

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.PasswordChangeReqDto
import com.msg.gauth.domain.user.presentation.dto.response.MyProfileResDto
Expand All @@ -19,7 +20,8 @@ class UserController(
private val myProfileService: MyProfileService,
private val acceptedUserService: AcceptedUserService,
private val acceptTeacherSignUpService: AcceptTeacherSignUpService,
private val pendingListService: PendingListService
private val pendingListService: PendingListService,
private val acceptStudentSignUpService: AcceptStudentSignUpService
) {
@GetMapping
fun myProfile(): ResponseEntity<MyProfileResDto> {
Expand Down Expand Up @@ -56,4 +58,10 @@ class UserController(
val result = pendingListService.execute()
return ResponseEntity.ok(result)
}

@PatchMapping("/accept-student")
fun acceptStudent(@RequestBody @Valid acceptedStudentReqDto: AcceptStudentReqDto): ResponseEntity<Void> {
acceptStudentSignUpService.execute(acceptedStudentReqDto)
return ResponseEntity.noContent().build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.msg.gauth.domain.user.presentation.dto.request

import com.msg.gauth.domain.user.enums.Gender
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull

data class AcceptStudentReqDto(
@field: NotNull
val id: Long,
@field: NotBlank
val name: String,
val gender: Gender,
@field: NotNull
val grade: Int,
@field: NotNull
val classNum: Int,
@field: NotNull
val num: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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.AcceptStudentReqDto
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.TransactionalService

@TransactionalService
class AcceptStudentSignUpService(
val userRepository: UserRepository
) {
fun execute(acceptedStudentReqDto: AcceptStudentReqDto) {
val user = userRepository.findByIdAndStateAndRoles(acceptedStudentReqDto.id, UserState.PENDING, mutableListOf(UserRole.ROLE_STUDENT))
?: throw UserNotFoundException()

userRepository.save(user.update(acceptedStudentReqDto))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SecurityConfig(
.antMatchers("/user/**").authenticated()
.antMatchers(HttpMethod.PATCH, "/user/accept-teacher").hasRole("ADMIN")
.antMatchers(HttpMethod.GET, "/user/pending").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/user/accept-student").hasRole("ADMIN")

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

0 comments on commit 967aaf3

Please sign in to comment.