-
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
16 changed files
with
191 additions
and
2 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,33 @@ | ||
package com.wafflestudio.snu4t.handler | ||
|
||
import com.wafflestudio.snu4t.common.enum.Semester | ||
import com.wafflestudio.snu4t.common.exception.InvalidPathParameterException | ||
import com.wafflestudio.snu4t.middleware.SnuttRestApiDefaultMiddleware | ||
import com.wafflestudio.snu4t.tag.TagListService | ||
import com.wafflestudio.snu4t.tag.data.TagListResponse | ||
import com.wafflestudio.snu4t.tag.data.TagListUpdateTimeResponse | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.reactive.function.server.ServerRequest | ||
import org.springframework.web.reactive.function.server.ServerResponse | ||
|
||
@Component | ||
class TagHandler( | ||
private val tagService: TagListService, | ||
snuttRestApiDefaultMiddleware: SnuttRestApiDefaultMiddleware | ||
) : ServiceHandler(snuttRestApiDefaultMiddleware) { | ||
suspend fun getTagList(req: ServerRequest): ServerResponse = handle(req) { | ||
val year = req.pathVariable("year").toInt() | ||
val semester = | ||
Semester.getOfValue(req.pathVariable("semester").toInt()) ?: throw InvalidPathParameterException("semester") | ||
val tagList = tagService.getTagList(year, semester) | ||
TagListResponse(tagList) | ||
} | ||
|
||
suspend fun getTagListUpdateTime(req: ServerRequest): ServerResponse = handle(req) { | ||
val year = req.pathVariable("year").toInt() | ||
val semester = | ||
Semester.getOfValue(req.pathVariable("semester").toInt()) ?: throw InvalidPathParameterException("semester") | ||
val tagList = tagService.getTagList(year, semester) | ||
TagListUpdateTimeResponse(tagList.updatedAt.toEpochMilli()) | ||
} | ||
} |
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,39 @@ | ||
package com.wafflestudio.snu4t.router.docs | ||
|
||
import com.wafflestudio.snu4t.tag.data.TagListResponse | ||
import com.wafflestudio.snu4t.tag.data.TagListUpdateTimeResponse | ||
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.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import org.springdoc.core.annotations.RouterOperation | ||
import org.springdoc.core.annotations.RouterOperations | ||
|
||
@RouterOperations( | ||
RouterOperation( | ||
path = "/v1/tags/{year}/{semester}", | ||
operation = Operation( | ||
operationId = "getTagList", | ||
parameters = [ | ||
Parameter(`in` = ParameterIn.PATH, name = "year", required = true), | ||
Parameter(`in` = ParameterIn.PATH, name = "semester", required = true) | ||
], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TagListResponse::class))])] | ||
), | ||
), | ||
RouterOperation( | ||
path = "/v1/tags/{year}/{semester}/update_time", | ||
operation = Operation( | ||
operationId = "getTagListUpdateTime", | ||
parameters = [ | ||
Parameter(`in` = ParameterIn.PATH, name = "year", required = true), | ||
Parameter(`in` = ParameterIn.PATH, name = "semester", required = true) | ||
], | ||
responses = [ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = TagListUpdateTimeResponse::class))])] | ||
) | ||
), | ||
|
||
) | ||
annotation class TagDocs |
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,33 @@ | ||
package com.wafflestudio.snu4t.common.enum | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue | ||
import com.wafflestudio.snu4t.common.extension.asc | ||
import com.wafflestudio.snu4t.common.extension.desc | ||
import com.wafflestudio.snu4t.lectures.data.EvInfo | ||
import com.wafflestudio.snu4t.lectures.data.Lecture | ||
import org.springframework.data.domain.Sort | ||
import org.springframework.data.mapping.div | ||
|
||
enum class SortCriteria( | ||
val value: Int, | ||
@JsonValue | ||
val fullName: String | ||
) { | ||
ID(1, "기본값"), | ||
RATING_DESC(2, "평점 높은 순"), | ||
RATING_ASC(3, "평점 낮은 순"), | ||
COUNT_DESC(4, "강의평 많은 순"), | ||
COUNT_ASC(5, "강의평 적은 순"); | ||
|
||
companion object { | ||
private val nameMap = values().associateBy { it.fullName } | ||
fun getOfName(sortCriteriaName: String?): SortCriteria? = nameMap[sortCriteriaName] | ||
fun getSort(sortCriteria: SortCriteria?): Sort = when (sortCriteria) { | ||
RATING_DESC -> (Lecture::evInfo / EvInfo::avgRating).desc() | ||
RATING_ASC -> (Lecture::evInfo / EvInfo::avgRating).asc() | ||
COUNT_DESC -> (Lecture::evInfo / EvInfo::count).desc() | ||
COUNT_ASC -> (Lecture::evInfo / EvInfo::count).asc() | ||
else -> Sort.unsorted() | ||
} | ||
} | ||
} |
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,7 @@ | ||
package com.wafflestudio.snu4t.lectures.data | ||
|
||
data class EvInfo( | ||
val evId: String? = null, | ||
val avgRating: Double?, | ||
val count: Int?, | ||
) |
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,19 @@ | ||
package com.wafflestudio.snu4t.tag | ||
|
||
import com.wafflestudio.snu4t.common.enum.Semester | ||
import com.wafflestudio.snu4t.common.exception.TagListNotFoundException | ||
import com.wafflestudio.snu4t.tag.data.TagList | ||
import com.wafflestudio.snu4t.tag.repository.TagListRepository | ||
import org.springframework.stereotype.Service | ||
|
||
interface TagListService { | ||
suspend fun getTagList(year: Int, semester: Semester): TagList | ||
} | ||
|
||
@Service | ||
class TagServiceImpl( | ||
private val tagListRepository: TagListRepository | ||
) : TagListService { | ||
override suspend fun getTagList(year: Int, semester: Semester): TagList = | ||
tagListRepository.findByYearAndSemester(year, semester) ?: throw TagListNotFoundException | ||
} |
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,26 @@ | ||
package com.wafflestudio.snu4t.tag.data | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class TagListResponse( | ||
val classification: List<String>, | ||
val department: List<String>, | ||
@JsonProperty("academic_year") | ||
val academicYear: List<String>, | ||
val credit: List<String>, | ||
val instructor: List<String>, | ||
val category: List<String>, | ||
val sortCriteria: List<String>, | ||
@JsonProperty("updated_at") | ||
val updatedAt: Long, | ||
) | ||
fun TagListResponse(tagList: TagList) = TagListResponse( | ||
classification = tagList.tagCollection.classification, | ||
department = tagList.tagCollection.department, | ||
academicYear = tagList.tagCollection.academicYear, | ||
credit = tagList.tagCollection.credit, | ||
instructor = tagList.tagCollection.instructor, | ||
category = tagList.tagCollection.category, | ||
sortCriteria = tagList.tagCollection.sortCriteria, | ||
updatedAt = tagList.updatedAt.toEpochMilli() | ||
) |
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 com.wafflestudio.snu4t.tag.data | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class TagListUpdateTimeResponse( | ||
@JsonProperty("updated_at") | ||
val updatedAt: Long | ||
) |