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

#27 강의 개설 신청 #49

Merged
merged 20 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
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)
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)
}
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.LectureCreateRequest
import team.msg.domain.lecture.presentation.data.web.LectureCreateWebRequest

interface LectureRequestMapper {
fun lectureCreateWebRequestToDto(request: LectureCreateWebRequest) : LectureCreateRequest
}
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.LectureCreateRequest
import team.msg.domain.lecture.presentation.data.web.LectureCreateWebRequest

@Component
class LectureRequestMapperImpl : LectureRequestMapper{
/**
* Lecture 개설 Web Request 를 애플리케이션 영역에서 사용될 Dto 로 매핑합니다.
* @param LectureCreateWebRequest
*/
override fun lectureCreateWebRequestToDto(request: LectureCreateWebRequest) = LectureCreateRequest(
ani2689 marked this conversation as resolved.
Show resolved Hide resolved
request.name,
request.content,
request.startDate,
request.endDate,
request.completeDate,
request.lectureType,
request.credit,
request.maxRegisteredUser
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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.LectureCreateWebRequest
import team.msg.domain.lecture.service.LectureService

@RestController
@RequestMapping("/lecture")
class LectureController(
private val lectureRequestMapper: LectureRequestMapper,
private val lectureService: LectureService
) {
@PostMapping
fun lectureCreate(@Valid @RequestBody webRequest: LectureCreateWebRequest) : ResponseEntity<Void> {
ani2689 marked this conversation as resolved.
Show resolved Hide resolved
ani2689 marked this conversation as resolved.
Show resolved Hide resolved
lectureService.lectureCreate(lectureRequestMapper.lectureCreateWebRequestToDto(webRequest))
return ResponseEntity.status(HttpStatus.CREATED).build()
}
}
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 LectureCreateRequest (
val name: String,
val content: String,
val startDate: LocalDateTime,
val endDate: LocalDateTime,
val completeDate: LocalDateTime,
val lectureType: LectureType,
val credit: Int,
val maxRegisteredUser: Int
)
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 LectureCreateWebRequest(
@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
)
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.LectureCreateRequest

interface LectureService {
fun lectureCreate(request: LectureCreateRequest)
}
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.LectureCreateRequest
import team.msg.domain.lecture.repository.LectureRepository
import java.util.*

@Service
class LectureServiceImpl(
private val lectureRepository: LectureRepository,
private val userUtil: UserUtil
) : LectureService{

/**
* 강의 개설을 처리하는 비지니스 로직입니다.
* @param LectureCreateRequest
*/
override fun lectureCreate(request: LectureCreateRequest) {
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(
UUID.randomUUID(),
user,
request.name,
request.startDate,
request.endDate,
request.completeDate,
request.content,
request.lectureType,
credit,
user.name,
request.maxRegisteredUser
)
ani2689 marked this conversation as resolved.
Show resolved Hide resolved

lectureRepository.save(lecture)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ class SecurityConfig(
private val jwtTokenParser: JwtTokenParser
) {
companion object {
const val USER = "USER"
const val ADMIN = "ADMIN"
const val STUDENT = "STUDENT"
const val TEACHER = "TEACHER"
const val BBOZZAK = "BBOZZAK"
const val PROFESSOR = "PROFESSOR"
const val COMPANY_INSTRUCTOR = "COMPANY_INSTRUCTOR"
const val GOVERNMENT = "GOVERNMENT"
}

@Bean
Expand Down Expand Up @@ -50,6 +56,9 @@ class SecurityConfig(
// activity
.mvcMatchers(HttpMethod.POST, "/activity").hasRole(STUDENT)

// lecture
.mvcMatchers(HttpMethod.POST, "/lecture").hasAnyRole(PROFESSOR, COMPANY_INSTRUCTOR, GOVERNMENT)

.anyRequest().authenticated()
.and()

Expand Down