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 #49 from GSM-MSG/27-feature/lecture-create
#27 강의 개설 신청
- Loading branch information
Showing
12 changed files
with
219 additions
and
14 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
8 changes: 8 additions & 0 deletions
8
...ouel-api/src/main/kotlin/team/msg/domain/lecture/exception/InvalidLectureTypeException.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.lecture.exception | ||
|
||
import team.msg.domain.lecture.exception.constant.LectureErrorCode | ||
import team.msg.global.error.exception.BitgouelException | ||
|
||
class InvalidLectureTypeException( | ||
message: String | ||
) : BitgouelException(message, LectureErrorCode.INVALID_LECTURE_TYPE.status) |
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/lecture/exception/constant/LectureErrorCode.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.lecture.exception.constant | ||
|
||
enum class LectureErrorCode( | ||
val message: String, | ||
val status: Int | ||
){ | ||
INVALID_LECTURE_TYPE("유효하지 않은 강의 구분입니다.", 400) | ||
} |
8 changes: 8 additions & 0 deletions
8
bitgouel-api/src/main/kotlin/team/msg/domain/lecture/mapper/LectureRequestMapper.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.lecture.mapper | ||
|
||
import team.msg.domain.lecture.presentation.data.request.CreateLectureRequest | ||
import team.msg.domain.lecture.presentation.data.web.CreateLectureWebRequest | ||
|
||
interface LectureRequestMapper { | ||
fun createLectureWebRequestToDto(request: CreateLectureWebRequest) : CreateLectureRequest | ||
} |
23 changes: 23 additions & 0 deletions
23
bitgouel-api/src/main/kotlin/team/msg/domain/lecture/mapper/LectureRequestMapperImpl.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,23 @@ | ||
package team.msg.domain.lecture.mapper | ||
|
||
import org.springframework.stereotype.Component | ||
import team.msg.domain.lecture.presentation.data.request.CreateLectureRequest | ||
import team.msg.domain.lecture.presentation.data.web.CreateLectureWebRequest | ||
|
||
@Component | ||
class LectureRequestMapperImpl : LectureRequestMapper{ | ||
/** | ||
* Lecture 개설 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다. | ||
* @param CreateLectureWebRequest | ||
*/ | ||
override fun createLectureWebRequestToDto(webRequest: CreateLectureWebRequest) = CreateLectureRequest( | ||
name = webRequest.name, | ||
content = webRequest.content, | ||
startDate = webRequest.startDate, | ||
endDate = webRequest.endDate, | ||
completeDate = webRequest.completeDate, | ||
lectureType = webRequest.lectureType, | ||
credit = webRequest.credit, | ||
maxRegisteredUser = webRequest.maxRegisteredUser | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
bitgouel-api/src/main/kotlin/team/msg/domain/lecture/presentation/LectureController.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.lecture.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.lecture.mapper.LectureRequestMapper | ||
import team.msg.domain.lecture.presentation.data.web.CreateLectureWebRequest | ||
import team.msg.domain.lecture.service.LectureService | ||
|
||
@RestController | ||
@RequestMapping("/lecture") | ||
class LectureController( | ||
private val lectureRequestMapper: LectureRequestMapper, | ||
private val lectureService: LectureService | ||
) { | ||
@PostMapping | ||
fun createLecture(@Valid @RequestBody webRequest: CreateLectureWebRequest): ResponseEntity<Void> { | ||
val request = lectureRequestMapper.createLectureWebRequestToDto(webRequest) | ||
lectureService.createLecture(request) | ||
return ResponseEntity.status(HttpStatus.CREATED).build() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/main/kotlin/team/msg/domain/lecture/presentation/data/request/CreateLectureRequest.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,15 @@ | ||
package team.msg.domain.lecture.presentation.data.request | ||
|
||
import team.msg.domain.lecture.enum.LectureType | ||
import java.time.LocalDateTime | ||
|
||
data class CreateLectureRequest ( | ||
val name: String, | ||
val content: String, | ||
val startDate: LocalDateTime, | ||
val endDate: LocalDateTime, | ||
val completeDate: LocalDateTime, | ||
val lectureType: LectureType, | ||
val credit: Int, | ||
val maxRegisteredUser: Int | ||
) |
47 changes: 47 additions & 0 deletions
47
.../src/main/kotlin/team/msg/domain/lecture/presentation/data/web/CreateLectureWebRequest.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,47 @@ | ||
package team.msg.domain.lecture.presentation.data.web | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat | ||
import javax.persistence.EnumType | ||
import javax.persistence.Enumerated | ||
import javax.validation.constraints.Future | ||
import javax.validation.constraints.FutureOrPresent | ||
import javax.validation.constraints.Min | ||
import javax.validation.constraints.NotBlank | ||
import javax.validation.constraints.NotNull | ||
import team.msg.domain.lecture.enum.LectureType | ||
import java.time.LocalDateTime | ||
|
||
data class CreateLectureWebRequest( | ||
@field:NotBlank | ||
val name: String, | ||
|
||
@field:NotBlank | ||
val content: String, | ||
|
||
@field:NotNull | ||
@FutureOrPresent | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:s") | ||
val startDate: LocalDateTime, | ||
|
||
@field:NotNull | ||
@Future | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:s") | ||
val endDate: LocalDateTime, | ||
|
||
@field:NotNull | ||
@Future | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:s") | ||
val completeDate: LocalDateTime, | ||
|
||
@field:NotNull | ||
@Enumerated(EnumType.STRING) | ||
val lectureType: LectureType, | ||
|
||
@field:NotNull | ||
@field:Min(0) | ||
val credit: Int, | ||
|
||
@field:NotNull | ||
@field:Min(1) | ||
val maxRegisteredUser: Int | ||
) |
7 changes: 7 additions & 0 deletions
7
bitgouel-api/src/main/kotlin/team/msg/domain/lecture/service/LectureService.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.lecture.service | ||
|
||
import team.msg.domain.lecture.presentation.data.request.CreateLectureRequest | ||
|
||
interface LectureService { | ||
fun createLecture(request: CreateLectureRequest) | ||
} |
47 changes: 47 additions & 0 deletions
47
bitgouel-api/src/main/kotlin/team/msg/domain/lecture/service/LectureServiceImpl.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,47 @@ | ||
package team.msg.domain.lecture.service | ||
|
||
import org.springframework.stereotype.Service | ||
import team.msg.common.util.UserUtil | ||
import team.msg.domain.lecture.enum.LectureType | ||
import team.msg.domain.lecture.exception.InvalidLectureTypeException | ||
import team.msg.domain.lecture.model.Lecture | ||
import team.msg.domain.lecture.presentation.data.request.CreateLectureRequest | ||
import team.msg.domain.lecture.repository.LectureRepository | ||
import java.util.* | ||
|
||
@Service | ||
class LectureServiceImpl( | ||
private val lectureRepository: LectureRepository, | ||
private val userUtil: UserUtil | ||
) : LectureService{ | ||
|
||
/** | ||
* 강의 개설을 처리하는 비지니스 로직입니다. | ||
* @param CreateLectureRequest | ||
*/ | ||
override fun createLecture(request: CreateLectureRequest) { | ||
val user = userUtil.queryCurrentUser() | ||
|
||
val credit = when(request.lectureType){ | ||
LectureType.MUTUAL_CREDIT_RECOGNITION_PROGRAM -> request.credit | ||
LectureType.UNIVERSITY_EXPLORATION_PROGRAM -> 0 | ||
else -> throw InvalidLectureTypeException("유효하지 않은 강의 구분입니다. info : [ type = ${request.lectureType} ]") | ||
} | ||
|
||
val lecture = Lecture( | ||
id = UUID.randomUUID(), | ||
user = user, | ||
name = request.name, | ||
startDate = request.startDate, | ||
endDate = request.endDate, | ||
completeDate = request.completeDate, | ||
content = request.content, | ||
lectureType = request.lectureType, | ||
credit = credit, | ||
instructor = user.name, | ||
maxRegisteredUser = request.maxRegisteredUser | ||
) | ||
|
||
lectureRepository.save(lecture) | ||
} | ||
} |
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