Skip to content

Commit

Permalink
[#2] Merge (#25)
Browse files Browse the repository at this point in the history
* Merge pull request #2

* Conflict 수정
  • Loading branch information
swdevsw98 authored Aug 10, 2023
1 parent 2099874 commit aa14083
Show file tree
Hide file tree
Showing 24 changed files with 514 additions and 14 deletions.
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/example/CommonApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class CommonApplication

fun main(args: Array<String>) {
runApplication<CommonApplication>(*args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import org.springframework.context.annotation.Configuration
class ReflectionConfiguration {
@Bean(BeanName.BASE_PACKAGE)
fun basePackage(): String = BASE_PACKAGE

object BeanName {
const val BASE_PACKAGE = "basePackage"
}

companion object {
const val BASE_PACKAGE = "com.example"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class RequestLoggingFilterConfiguration {
it.setMaxPayloadLength(64000)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SwaggerConfiguration {
.`in`(SecurityScheme.In.HEADER)
.name("Authorization")
private val securityRequirementName = "bearerAuth"

init {
SpringDocUtils
.getConfig()
Expand Down Expand Up @@ -72,10 +72,10 @@ class SwaggerConfiguration {
),
)
}

@Bean
fun openApi(): OpenAPI {

return OpenAPI()
.servers(listOf(Server().apply { url = "/" }))
.security(
Expand All @@ -102,18 +102,18 @@ class SwaggerConfiguration {
.description("Spring Boot API"),
)
}

private val apiRootUrl = "http://localhost:8080"
private val description = """
<h3>요청 헤더</h3>
필요한 요청 헤더 2개는 다음과 같습니다. <br />
이때 "{토큰}" 대신 발급된 토큰을 넣어주세요. <br />
* "Authorization: Bearer {토큰}"
* "Content-Type: application/json"
<h3>cURL 예시</h3>
<h3>cURL 예시</h3>
<code>
curl -X 'POST' <br />
&nbsp; '$apiRootUrl/reservation-api/register' <br />
Expand All @@ -129,4 +129,4 @@ class SwaggerConfiguration {
&nbsp; }' <br />
</code>
""".trimIndent()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.common.enums

enum class CalendarType {
ASSIGNMENT, VIDEO
}
10 changes: 8 additions & 2 deletions common/src/main/kotlin/com/example/common/enums/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ private const val MAIN_NUMBERING = 1000
private const val NOTICE_NUMBERING = 2000
private const val COURSE_NUMBERING = 3000
private const val SERVER_NUMBERING = 4000
private const val CALENDAR_NUMBERING = 5000

enum class ErrorCode(val code: Int, val message: String) {
USER_NOT_FOUND(MAIN_NUMBERING + 1, "유저를 찾을 수 없습니다"),
DEPARTMENT_NOT_FOUND(MAIN_NUMBERING + 2, "학과를 찾을 수 없습니다"),


COURSE_NOT_FOUND(COURSE_NUMBERING + 1, "과목을 찾을 수 없습니다."),

INVALID_DATE_FORMAT(CALENDAR_NUMBERING + 1, "잘못된 날짜 형식입니다. yyyy-MM-dd HH:mm:ss 형식으로 요청바랍니다."),
INVALID_DATE(CALENDAR_NUMBERING + 2, "잘못된 날짜입니다."),

BAD_REQUEST(SERVER_NUMBERING + 1, "잘못된 요청입니다."),
INVALID_FORMAT(SERVER_NUMBERING + 2, "잘못된 형식입니다."),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.example.domain.course.controller

import com.example.common.dto.Response
import com.example.domain.course.dto.request.AssignmentRequest
import com.example.domain.course.dto.request.CalendarRequest
import com.example.domain.course.dto.request.CourseRequest
import com.example.domain.course.dto.request.VideoRequest
import com.example.domain.course.dto.response.AssignmentResponse
import com.example.domain.course.dto.response.CalendarResponse
import com.example.domain.course.dto.response.CourseResponse
import com.example.domain.course.dto.response.VideoResponse
import com.example.domain.course.service.CourseService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
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

@RestController
@RequestMapping("/course")
@Tag(name = "Course", description = "강의, 일정 API")
class CourseController (
private val courseService: CourseService,
) {
@Operation(
summary = "강의 리스트형식 출력",
responses = [
ApiResponse(
responseCode = "200",
description = "OK"
)
],
)
@GetMapping()
fun getCourseList() : Response<List<CourseResponse>> =
Response(data = courseService.getCourseList())


@Operation(
summary = "강의 단일 조회",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@GetMapping("{courseId}")
fun getCourse(
@PathVariable courseId: Long
) : Response<CourseResponse> =
Response(data = courseService.getCourse(courseId = courseId))


@Operation(
summary = "월 단위로 일정 가져오기",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@GetMapping("/calendar/{date}")
fun getCalendar(
@PathVariable("date") date: String
) : Response<Map<String, List<CalendarResponse>>> =
Response(data = courseService.getCalendar(dateRequest = date))


@Operation(
summary = "일정 추가하기",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@PostMapping("/calendar")
fun postCreateCalendar(
@RequestBody calendarRequest: CalendarRequest
) : Response<CalendarResponse> =
Response(data = courseService.postCalendar(calendarRequest = calendarRequest))


@Operation(
summary = "강의 추가하기",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@PostMapping("/video")
fun postCreateVideo(
@RequestBody videoRequest: VideoRequest
) : Response<VideoResponse> =
Response(data = courseService.postVideo(videoRequest))


@Operation(
summary = "과제 추가하기",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@PostMapping("/assignment")
fun postCreateAssignment(
@RequestBody assignmentRequest: AssignmentRequest
) : Response<AssignmentResponse> =
Response(data = courseService.postAssignment(assignmentRequest = assignmentRequest))


@Operation(
summary = "과목 추가하기",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@PostMapping("/course")
fun postCreateCourse(
@RequestBody courseRequest: CourseRequest
) : Response<CourseResponse> =
Response(data = courseService.postCourse(courseRequest = courseRequest))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.domain.course.dto.request

import io.swagger.v3.oas.annotations.media.Schema


@Schema(name = "과제 등록 API Request Body")
class AssignmentRequest (
@Schema(description = "강의 id")
val courseId: Long,
@Schema(description = "과제 이름")
val name: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.domain.course.dto.request

import com.example.common.enums.CalendarType
import io.swagger.v3.oas.annotations.media.Schema

@Schema(name = "일정 추가 API Request Body")
class CalendarRequest (
@Schema(description = "일정의 종류")
val type: CalendarType,
@Schema(description = "일정의 분류")
val course: String,
@Schema(description = "일정의 마감기한")
val dueAt: String,
@Schema(description = "일정의 제목")
val name: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.domain.course.dto.request

import org.jetbrains.annotations.NotNull

class CourseRequest (
@NotNull
val name: String,

@NotNull
val term: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.domain.course.dto.request

import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "강의 등록 API Request Body입니다. ")
class VideoRequest (
@Schema(description = "강의 id")
val courseId: Long,
@Schema(description = "강의 이름")
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.domain.course.dto.response

import java.time.LocalDateTime

class AssignmentResponse(
val id: Long,
val name: String,
val dueAt: LocalDateTime,
val startAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.domain.course.dto.response

import com.example.common.enums.CalendarType
import java.time.LocalDateTime

class CalendarResponse (

val type: CalendarType,
val dueAt: LocalDateTime,
val name: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.domain.course.dto.response

class CourseResponse (
val name: String,
val videos: List<VideoResponse> = emptyList(),
val assignments: List<AssignmentResponse> = emptyList(),
val term: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.domain.course.dto.response

import java.time.LocalDate
import java.time.LocalDateTime

class VideoResponse (
val id: Long,
val name: String,
val dueAt: LocalDateTime,
val startAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.domain.course.model.entity

import com.example.common.domain.BaseEntity
import com.fasterxml.jackson.annotation.JsonIgnore
import jakarta.persistence.*
import java.time.LocalDateTime

@Entity
class Assignment (
val dueAt : LocalDateTime,

val startAt : LocalDateTime,

val name: String,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "course_id")
var course : Course? = null,
) : BaseEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.domain.course.model.entity

import com.example.common.domain.BaseEntity
import com.example.common.enums.CalendarType
import jakarta.persistence.*
import java.time.LocalDateTime

@Entity
class Calendar (
val type: CalendarType,

val course: String,

val dueAt: LocalDateTime,

val name: String
) : BaseEntity()
Loading

0 comments on commit aa14083

Please sign in to comment.