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 #130 from GSM-MSG/129-feat/create-certification
# 129 자격증 등록 기능 개발
- Loading branch information
Showing
16 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...el-api/src/main/kotlin/team/msg/domain/certification/mapper/CertificationRequestMapper.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.certification.mapper | ||
|
||
import team.msg.domain.certification.presentation.data.request.CreateCertificationRequest | ||
import team.msg.domain.certification.presentation.data.web.CreateCertificationWebRequest | ||
|
||
interface CertificationRequestMapper { | ||
fun createCertificationWebRequestToDto(webRequest: CreateCertificationWebRequest): CreateCertificationRequest | ||
} |
17 changes: 17 additions & 0 deletions
17
...pi/src/main/kotlin/team/msg/domain/certification/mapper/CertificationRequestMapperImpl.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,17 @@ | ||
package team.msg.domain.certification.mapper | ||
|
||
import org.springframework.stereotype.Component | ||
import team.msg.domain.certification.presentation.data.request.CreateCertificationRequest | ||
import team.msg.domain.certification.presentation.data.web.CreateCertificationWebRequest | ||
|
||
@Component | ||
class CertificationRequestMapperImpl : CertificationRequestMapper { | ||
/** | ||
* 자격증 등록 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다. | ||
*/ | ||
override fun createCertificationWebRequestToDto(webRequest: CreateCertificationWebRequest) = CreateCertificationRequest( | ||
name = webRequest.name, | ||
acquisitionDate = webRequest.acquisitionDate | ||
) | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...api/src/main/kotlin/team/msg/domain/certification/presentation/CertificationController.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,26 @@ | ||
package team.msg.domain.certification.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.certification.mapper.CertificationRequestMapper | ||
import team.msg.domain.certification.presentation.data.web.CreateCertificationWebRequest | ||
import team.msg.domain.certification.service.CertificationService | ||
|
||
@RestController | ||
@RequestMapping("/certification") | ||
class CertificationController( | ||
private val certificationService: CertificationService, | ||
private val certificationRequestMapper: CertificationRequestMapper | ||
) { | ||
@PostMapping | ||
fun createCertification(@RequestBody @Valid webRequest: CreateCertificationWebRequest): ResponseEntity<Void> { | ||
val request = certificationRequestMapper.createCertificationWebRequestToDto(webRequest) | ||
certificationService.createCertification(request) | ||
return ResponseEntity.status(HttpStatus.CREATED).build() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...lin/team/msg/domain/certification/presentation/data/request/CreateCertificationRequest.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.certification.presentation.data.request | ||
|
||
import java.time.LocalDate | ||
|
||
data class CreateCertificationRequest( | ||
val name: String, | ||
val acquisitionDate: LocalDate | ||
) |
13 changes: 13 additions & 0 deletions
13
...tlin/team/msg/domain/certification/presentation/data/web/CreateCertificationWebRequest.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,13 @@ | ||
package team.msg.domain.certification.presentation.data.web | ||
|
||
import javax.validation.constraints.NotBlank | ||
import javax.validation.constraints.NotNull | ||
import java.time.LocalDate | ||
|
||
data class CreateCertificationWebRequest( | ||
@field:NotBlank | ||
val name: String, | ||
|
||
@field:NotNull | ||
val acquisitionDate: LocalDate | ||
) |
7 changes: 7 additions & 0 deletions
7
bitgouel-api/src/main/kotlin/team/msg/domain/certification/service/CertificationService.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.certification.service | ||
|
||
import team.msg.domain.certification.presentation.data.request.CreateCertificationRequest | ||
|
||
interface CertificationService { | ||
fun createCertification(createCertificationRequest: CreateCertificationRequest) | ||
} |
44 changes: 44 additions & 0 deletions
44
...uel-api/src/main/kotlin/team/msg/domain/certification/service/CertificationServiceImpl.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,44 @@ | ||
package team.msg.domain.certification.service | ||
|
||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import team.msg.common.util.UserUtil | ||
import team.msg.domain.certifiacation.model.Certification | ||
import team.msg.domain.certifiacation.repository.CertificationRepository | ||
import team.msg.domain.certification.presentation.data.request.CreateCertificationRequest | ||
import team.msg.domain.student.exception.StudentNotFoundException | ||
import team.msg.domain.student.model.Student | ||
import team.msg.domain.student.repository.StudentRepository | ||
import team.msg.domain.user.model.User | ||
import java.util.* | ||
|
||
@Service | ||
class CertificationServiceImpl( | ||
private val certificationRepository: CertificationRepository, | ||
private val studentRepository: StudentRepository, | ||
private val userUtil: UserUtil | ||
) : CertificationService { | ||
|
||
/** | ||
* 자격증에 대한 정보를 작성하는 비지니스 로직입니다. | ||
* @param 자격증을 소지한 학생 id | ||
*/ | ||
@Transactional(rollbackFor = [Exception::class]) | ||
override fun createCertification(request: CreateCertificationRequest) { | ||
val user = userUtil.queryCurrentUser() | ||
val student = studentRepository findByUer user | ||
|
||
val certification = Certification( | ||
id = UUID.randomUUID(), | ||
studentId = student.id, | ||
name = request.name, | ||
acquisitionDate = request.acquisitionDate | ||
) | ||
|
||
certificationRepository.save(certification) | ||
} | ||
|
||
private infix fun StudentRepository.findByUer(user: User): Student = | ||
this.findByUser(user) | ||
?: throw StudentNotFoundException("존재하지 않는 유저입니다. info : [ userId = ${user.id} ]") | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.