-
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.
- Loading branch information
Showing
22 changed files
with
575 additions
and
58 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
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,74 @@ | ||
package com.wafflestudio.snu4t.handler | ||
|
||
import com.wafflestudio.snu4t.common.enum.BasicThemeType | ||
import com.wafflestudio.snu4t.common.exception.InvalidPathParameterException | ||
import com.wafflestudio.snu4t.middleware.SnuttRestApiDefaultMiddleware | ||
import com.wafflestudio.snu4t.timetables.dto.TimetableThemeDto | ||
import com.wafflestudio.snu4t.timetables.dto.request.TimetableThemeAddRequestDto | ||
import com.wafflestudio.snu4t.timetables.dto.request.TimetableThemeModifyRequestDto | ||
import com.wafflestudio.snu4t.timetables.service.TimetableThemeService | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.reactive.function.server.ServerRequest | ||
import org.springframework.web.reactive.function.server.awaitBody | ||
|
||
@Component | ||
class TimetableThemeHandler( | ||
private val timetableThemeService: TimetableThemeService, | ||
snuttRestApiDefaultMiddleware: SnuttRestApiDefaultMiddleware, | ||
) : ServiceHandler(snuttRestApiDefaultMiddleware) { | ||
suspend fun getThemes(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
|
||
timetableThemeService.getThemes(userId).map(::TimetableThemeDto) | ||
} | ||
|
||
suspend fun addTheme(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val body = req.awaitBody<TimetableThemeAddRequestDto>() | ||
|
||
timetableThemeService.addTheme(userId, body.name, body.colors).let(::TimetableThemeDto) | ||
} | ||
|
||
suspend fun modifyTheme(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val themeId = req.pathVariable("themeId") | ||
val body = req.awaitBody<TimetableThemeModifyRequestDto>() | ||
|
||
timetableThemeService.modifyTheme(userId, themeId, body.name, body.colors).let(::TimetableThemeDto) | ||
} | ||
|
||
suspend fun deleteTheme(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val themeId = req.pathVariable("themeId") | ||
|
||
timetableThemeService.deleteTheme(userId, themeId) | ||
} | ||
|
||
suspend fun copyTheme(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val themeId = req.pathVariable("themeId") | ||
|
||
timetableThemeService.copyTheme(userId, themeId).let(::TimetableThemeDto) | ||
} | ||
|
||
suspend fun setDefault(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val themeId = req.pathVariable("themeId") | ||
|
||
timetableThemeService.setDefault(userId, themeId).let(::TimetableThemeDto) | ||
} | ||
|
||
suspend fun setBasicThemeTypeDefault(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val basicThemeType = req.pathVariable("basicThemeTypeValue").toIntOrNull()?.let { BasicThemeType.from(it) } ?: throw InvalidPathParameterException("basicThemeTypeValue") | ||
|
||
timetableThemeService.setDefault(userId, basicThemeType = basicThemeType).let(::TimetableThemeDto) | ||
} | ||
|
||
suspend fun unsetDefault(req: ServerRequest) = handle(req) { | ||
val userId = req.userId | ||
val themeId = req.pathVariable("themeId") | ||
|
||
timetableThemeService.unsetDefault(userId, themeId).let(::TimetableThemeDto) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.wafflestudio.snu4t.router.docs | ||
|
||
import com.wafflestudio.snu4t.timetables.dto.TimetableThemeDto | ||
import com.wafflestudio.snu4t.timetables.dto.request.TimetableThemeAddRequestDto | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn | ||
import io.swagger.v3.oas.annotations.media.ArraySchema | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import org.springdoc.core.annotations.RouterOperation | ||
import org.springdoc.core.annotations.RouterOperations | ||
import org.springframework.http.MediaType | ||
import org.springframework.web.bind.annotation.RequestMethod | ||
|
||
@RouterOperations( | ||
RouterOperation( | ||
path = "/v1/themes", method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "getThemes", | ||
parameters = [Parameter(`in` = ParameterIn.QUERY, name = "state", required = true)], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(array = ArraySchema(schema = Schema(implementation = TimetableThemeDto::class)))])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes", method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "addTheme", | ||
requestBody = RequestBody( | ||
content = [Content(schema = Schema(implementation = TimetableThemeAddRequestDto::class))], | ||
required = true, | ||
), | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TimetableThemeDto::class))])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes/{themeId}", method = [RequestMethod.PATCH], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "modifyTheme", | ||
parameters = [Parameter(`in` = ParameterIn.PATH, name = "themeId", required = true)], | ||
requestBody = RequestBody( | ||
content = [Content(schema = Schema(implementation = TimetableThemeAddRequestDto::class))], | ||
required = true, | ||
), | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TimetableThemeDto::class))])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes/{themeId}", method = [RequestMethod.DELETE], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "deleteTheme", | ||
parameters = [Parameter(`in` = ParameterIn.PATH, name = "themeId", required = true)], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema())])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes/{themeId}/copy", method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "copyTheme", | ||
parameters = [Parameter(`in` = ParameterIn.PATH, name = "themeId", required = true)], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TimetableThemeDto::class))])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes/{themeId}/default", method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "setDefault", | ||
parameters = [Parameter(`in` = ParameterIn.PATH, name = "themeId", required = true)], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TimetableThemeDto::class))])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes/basic/{basicThemeTypeValue}/default", method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "setBasicThemeTypeDefault", | ||
parameters = [Parameter(`in` = ParameterIn.PATH, name = "basicThemeTypeValue", required = true)], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TimetableThemeDto::class))])], | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/themes/{themeId}/copy", method = [RequestMethod.DELETE], produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = Operation( | ||
operationId = "unsetDefault", | ||
parameters = [Parameter(`in` = ParameterIn.PATH, name = "themeId", required = true)], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TimetableThemeDto::class))])], | ||
), | ||
), | ||
) | ||
annotation class ThemeDocs |
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,37 @@ | ||
package com.wafflestudio.snu4t.common.enum | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue | ||
import org.springframework.core.convert.converter.Converter | ||
import org.springframework.data.convert.ReadingConverter | ||
import org.springframework.data.convert.WritingConverter | ||
import org.springframework.stereotype.Component | ||
|
||
enum class BasicThemeType(@get:JsonValue val value: Int, val displayName: String) { | ||
SNUTT(0, "SNUTT"), // 구 버전 호환을 위해 커스텀 테마의 경우 사용됨 | ||
FALL(1, "가을"), | ||
MODERN(2, "모던"), | ||
CHERRY_BLOSSOM(3, "벚꽃"), | ||
ICE(4, "얼음"), | ||
LAWN(5, "잔디"), | ||
; | ||
|
||
companion object { | ||
const val COLOR_COUNT = 9 | ||
fun from(value: Int) = values().find { it.value == value } | ||
fun from(displayName: String) = values().find { it.displayName == displayName } | ||
} | ||
} | ||
|
||
@ReadingConverter | ||
@Component | ||
class BasicThemeTypeReadConverter : Converter<Int, BasicThemeType> { | ||
override fun convert(source: Int): BasicThemeType { | ||
return requireNotNull(BasicThemeType.from(source)) | ||
} | ||
} | ||
|
||
@Component | ||
@WritingConverter | ||
class BasicThemeTypeWriteConverter : Converter<BasicThemeType, Int> { | ||
override fun convert(source: BasicThemeType): Int = source.value | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.