generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #39 from GSM-MSG/34-feat/student-activity-informat…
…ion-add 34 학생 활동 정보 추가
- Loading branch information
Showing
17 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
bitgouel-api/src/main/kotlin/team/msg/common/util/UserUtil.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,29 @@ | ||
package team.msg.common.util | ||
|
||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.security.core.context.SecurityContextHolder | ||
import org.springframework.stereotype.Component | ||
import team.msg.domain.user.exception.UserNotFoundException | ||
import team.msg.domain.user.model.User | ||
import team.msg.domain.user.repository.UserRepository | ||
import team.msg.global.security.principal.AuthDetails | ||
import java.util.* | ||
|
||
@Component | ||
class UserUtil( | ||
private val userRepository: UserRepository | ||
) { | ||
fun queryCurrentUser(): User { | ||
val principal = SecurityContextHolder.getContext().authentication.principal | ||
|
||
val userId = UUID.fromString(if(principal is AuthDetails) | ||
principal.username | ||
else | ||
principal.toString()) | ||
|
||
val user = userRepository.findByIdOrNull(userId) | ||
?: throw UserNotFoundException("존재하지 않는 유저입니다. : [ id = $userId ]") | ||
|
||
return user | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/StudentNotFoundException.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,8 @@ | ||
package team.msg.domain.student.exception | ||
|
||
import team.msg.domain.student.exception.constant.StudentErrorCode | ||
import team.msg.global.error.exception.BitgouelException | ||
|
||
class StudentNotFoundException( | ||
message: String | ||
) : BitgouelException(message, StudentErrorCode.STUDENT_NOT_FOUND.status) |
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentErrorCode.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,8 @@ | ||
package team.msg.domain.student.exception.constant | ||
|
||
enum class StudentErrorCode( | ||
val message: String, | ||
val status: Int | ||
) { | ||
STUDENT_NOT_FOUND("학생을 찾을 수 없습니다.", 404) | ||
} |
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/student/mapper/StudentActivityMapper.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,8 @@ | ||
package team.msg.domain.student.mapper | ||
|
||
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest | ||
import team.msg.domain.student.presentation.data.web.CreateStudentActivityWebRequest | ||
|
||
interface StudentActivityMapper { | ||
fun createStudentActivityWebRequestToDto(webRequest: CreateStudentActivityWebRequest): CreateStudentActivityRequest | ||
} |
20 changes: 20 additions & 0 deletions
20
bitgouel-api/src/main/kotlin/team/msg/domain/student/mapper/StudentActivityMapperImpl.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,20 @@ | ||
package team.msg.domain.student.mapper | ||
|
||
import org.springframework.stereotype.Component | ||
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest | ||
import team.msg.domain.student.presentation.data.web.CreateStudentActivityWebRequest | ||
|
||
@Component | ||
class StudentActivityMapperImpl : StudentActivityMapper { | ||
|
||
/** | ||
* StudentActivity 생성 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다. | ||
*/ | ||
override fun createStudentActivityWebRequestToDto(webRequest: CreateStudentActivityWebRequest): CreateStudentActivityRequest = | ||
CreateStudentActivityRequest( | ||
title = webRequest.title, | ||
content = webRequest.content, | ||
credit = webRequest.credit, | ||
activityDate = webRequest.activityDate | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
...uel-api/src/main/kotlin/team/msg/domain/student/presentation/StudentActivityController.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,25 @@ | ||
package team.msg.domain.student.presentation | ||
|
||
import javax.validation.Valid | ||
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.domain.student.mapper.StudentActivityMapper | ||
import team.msg.domain.student.presentation.data.web.CreateStudentActivityWebRequest | ||
import team.msg.domain.student.service.StudentActivityService | ||
|
||
@RestController | ||
@RequestMapping("/activity") | ||
class StudentActivityController( | ||
private val studentActivityService: StudentActivityService, | ||
private val studentActivityMapper: StudentActivityMapper | ||
) { | ||
@PostMapping | ||
fun createStudentActivity(@RequestBody @Valid request: CreateStudentActivityWebRequest): ResponseEntity<Void> { | ||
studentActivityService.createStudentActivity(studentActivityMapper.createStudentActivityWebRequestToDto(request)) | ||
return ResponseEntity.status(HttpStatus.CREATED).build() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../kotlin/team/msg/domain/student/presentation/data/request/CreateStudentActivityRequest.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,10 @@ | ||
package team.msg.domain.student.presentation.data.request | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class CreateStudentActivityRequest( | ||
val title: String, | ||
val content: String, | ||
val credit: Int, | ||
val activityDate: LocalDateTime | ||
) |
22 changes: 22 additions & 0 deletions
22
...n/kotlin/team/msg/domain/student/presentation/data/web/CreateStudentActivityWebRequest.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,22 @@ | ||
package team.msg.domain.student.presentation.data.web | ||
|
||
import javax.validation.constraints.Max | ||
import javax.validation.constraints.NotBlank | ||
import javax.validation.constraints.NotNull | ||
import java.time.LocalDateTime | ||
|
||
data class CreateStudentActivityWebRequest( | ||
@field:NotBlank | ||
@field:Max(100) | ||
val title: String, | ||
|
||
@field:NotBlank | ||
@field:Max(1000) | ||
val content: String, | ||
|
||
@field:NotNull | ||
val credit: Int, | ||
|
||
@field:NotNull | ||
val activityDate: LocalDateTime | ||
) |
7 changes: 7 additions & 0 deletions
7
bitgouel-api/src/main/kotlin/team/msg/domain/student/service/StudentActivityService.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,7 @@ | ||
package team.msg.domain.student.service | ||
|
||
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest | ||
|
||
interface StudentActivityService { | ||
fun createStudentActivity(request: CreateStudentActivityRequest) | ||
} |
51 changes: 51 additions & 0 deletions
51
bitgouel-api/src/main/kotlin/team/msg/domain/student/service/StudentActivityServiceImpl.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,51 @@ | ||
package team.msg.domain.student.service | ||
|
||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import team.msg.common.enum.ApproveStatus | ||
import team.msg.common.util.UserUtil | ||
import team.msg.domain.student.exception.StudentNotFoundException | ||
import team.msg.domain.student.model.StudentActivity | ||
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest | ||
import team.msg.domain.student.repository.StudentActivityRepository | ||
import team.msg.domain.student.repository.StudentRepository | ||
import team.msg.domain.teacher.exception.TeacherNotFoundException | ||
import team.msg.domain.teacher.repository.TeacherRepository | ||
import java.util.* | ||
|
||
@Service | ||
class StudentActivityServiceImpl( | ||
private val userUtil: UserUtil, | ||
private val studentRepository: StudentRepository, | ||
private val teacherRepository: TeacherRepository, | ||
private val studentActivityRepository: StudentActivityRepository | ||
) : StudentActivityService { | ||
|
||
/** | ||
* 학생 활동을 생성하는 비지니스 로직입니다 | ||
* @param CreateStudentActivityRequest | ||
*/ | ||
@Transactional(rollbackFor = [Exception::class]) | ||
override fun createStudentActivity(request: CreateStudentActivityRequest) { | ||
val user = userUtil.queryCurrentUser() | ||
|
||
val student = studentRepository.findByUser(user) | ||
?: throw StudentNotFoundException("학생을 찾을 수 없습니다. info : [ name = ${user.name} ]") | ||
|
||
val teacher = teacherRepository.findByClub(student.club) | ||
?: throw TeacherNotFoundException("취업 동아리 선생님을 찾을 수 없습니다.") | ||
|
||
val studentActivity = StudentActivity( | ||
id = UUID.randomUUID(), | ||
title = request.title, | ||
content = request.content, | ||
credit = request.credit, | ||
activityDate = request.activityDate, | ||
student = student, | ||
teacher = teacher, | ||
approveStatus = ApproveStatus.PENDING | ||
) | ||
|
||
studentActivityRepository.save(studentActivity) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/TeacherNotFoundException.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,9 @@ | ||
package team.msg.domain.teacher.exception | ||
|
||
import team.msg.domain.teacher.exception.constant.TeacherErrorCode | ||
import team.msg.global.error.exception.BitgouelException | ||
|
||
class TeacherNotFoundException( | ||
message: String | ||
) : BitgouelException(message, TeacherErrorCode.TEACHER_NOT_FOUND.status) { | ||
} |
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/constant/TeacherErrorCode.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,8 @@ | ||
package team.msg.domain.teacher.exception.constant | ||
|
||
enum class TeacherErrorCode( | ||
val message: String, | ||
val status: Int | ||
) { | ||
TEACHER_NOT_FOUND("취업 동아리 선생님을 찾을 수 없습니다.", 404) | ||
} |
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
2 changes: 2 additions & 0 deletions
2
bitgouel-domain/src/main/kotlin/team/msg/domain/teacher/repository/TeacherRepository.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,8 +1,10 @@ | ||
package team.msg.domain.teacher.repository | ||
|
||
import org.springframework.data.repository.CrudRepository | ||
import team.msg.domain.club.model.Club | ||
import team.msg.domain.teacher.model.Teacher | ||
import java.util.UUID | ||
|
||
interface TeacherRepository : CrudRepository<Teacher, UUID> { | ||
fun findByClub(club: Club): Teacher? | ||
} |