-
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 #209 from wafflestudio/develop
Release
- Loading branch information
Showing
30 changed files
with
940 additions
and
139 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
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}/default", 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 |
Oops, something went wrong.