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

Release #107

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.wafflestudio.snuttev.core.common.dto.common.ListResponse
import com.wafflestudio.snuttev.core.common.dto.common.PaginationResponse
import com.wafflestudio.snuttev.core.common.error.ErrorResponse
import com.wafflestudio.snuttev.core.domain.lecture.dto.EvLectureSummaryForSnutt
import com.wafflestudio.snuttev.core.domain.lecture.dto.LectureAndSemesterLecturesResponse
import com.wafflestudio.snuttev.core.domain.lecture.dto.LectureDto
Expand All @@ -12,7 +13,12 @@ import com.wafflestudio.snuttev.core.domain.lecture.dto.LectureTakenByUserRespon
import com.wafflestudio.snuttev.core.domain.lecture.dto.SearchLectureRequest
import com.wafflestudio.snuttev.core.domain.lecture.dto.SnuttLectureInfo
import com.wafflestudio.snuttev.core.domain.lecture.service.LectureService
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.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PathVariable
Expand All @@ -39,14 +45,119 @@ class LectureController(
return lectureService.getSemesterLectures(lectureId, userId)
}

@GetMapping("/v1/lectures/id")
@Operation(
parameters = [
Parameter(
`in` = ParameterIn.QUERY,
name = "course_number",
description = "course number of the lecture",
required = true,
),
Parameter(
`in` = ParameterIn.QUERY,
name = "instructor",
description = "instructor of the lecture",
required = true,
),
],
responses = [
ApiResponse(
responseCode = "200",
content = [Content(schema = Schema(implementation = LectureIdResponse::class))],
),
ApiResponse(
responseCode = "409",
description = "24001 LECTURE_NOT_FOUND",
content = [Content(schema = Schema(implementation = ErrorResponse::class))],
),
],
)
@GetMapping("/v1/lectures/id", params = ["course_number", "instructor"])
fun getLectureId(
@RequestParam("course_number") courseNumber: String,
@RequestParam instructor: String,
): LectureIdResponse {
return lectureService.getLectureIdFromCourseNumber(courseNumber, instructor)
}

@Operation(
parameters = [
Parameter(
`in` = ParameterIn.QUERY,
name = "semesterLectureSnuttId",
description = "snuttId (mongoId) of the lecture",
required = true,
),
],
responses = [
ApiResponse(
responseCode = "200",
content = [Content(schema = Schema(implementation = LectureIdResponse::class))],
),
ApiResponse(
responseCode = "409",
description = "24001 LECTURE_NOT_FOUND",
content = [Content(schema = Schema(implementation = ErrorResponse::class))],
),
],
)
@GetMapping("/v1/lectures/id", params = ["semesterLectureSnuttId"])
fun getLectureId(
@RequestParam("semesterLectureSnuttId") semesterLectureSnuttId: String,
): LectureIdResponse {
return lectureService.getLectureIdFromSnuttId(semesterLectureSnuttId)
}

@Operation(
parameters = [
Parameter(
`in` = ParameterIn.QUERY,
name = "semesterLectureSnuttIds",
description = "snuttId (mongoId) of the lecture",
required = true,
),
],
responses = [
ApiResponse(
responseCode = "200",
content = [Content(schema = Schema(implementation = LectureIdListResponse::class))],
),
ApiResponse(
responseCode = "409",
description = "24001 LECTURE_NOT_FOUND",
content = [Content(schema = Schema(implementation = ErrorResponse::class))],
),
],
)
@GetMapping("/v1/lectures/ids", params = ["semesterLectureSnuttIds"])
fun getLectureId(
@RequestParam("semesterLectureSnuttIds") semesterLectureSnuttIds: List<String>,
): ListResponse<LectureIdResponse> {
val lectureIdResponses = lectureService.getLectureIdsFromSnuttIds(semesterLectureSnuttIds)
return ListResponse(lectureIdResponses)
}

@Operation(
parameters = [
Parameter(
`in` = ParameterIn.QUERY,
name = "snuttId",
description = "snuttId (mongoId) of the lecture",
required = true,
),
],
responses = [
ApiResponse(
responseCode = "200",
content = [Content(schema = Schema(implementation = LectureIdListResponse::class))],
),
ApiResponse(
responseCode = "409",
description = "24001 LECTURE_NOT_FOUND",
content = [Content(schema = Schema(implementation = ErrorResponse::class))],
),
],
)
@GetMapping("/v1/lectures/snutt-summary")
fun getEvLectureSummaryForSnutt(
@RequestParam semesterLectureSnuttIds: List<String>,
Expand Down Expand Up @@ -78,3 +189,5 @@ class LectureController(
)
}
}

private class LectureIdListResponse : ListResponse<LectureIdResponse>(listOf())
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wafflestudio.snuttev.core.common.dto.common

data class ListResponse<T> (
open class ListResponse<T> (
val content: List<T>,
val totalCount: Int = content.size,
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ data class LectureAndSemesterLecturesResponse(
)

data class LectureIdResponse(
// FIXME: evLectureId로 대체되므로 삭제 (evLectureId 생성: 2024-04-14)
val id: Long,
val snuttId: String? = null,
val evLectureId: Long = id,
)

data class LectureTakenByUserResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LectureRepositoryImpl(private val queryFactory: JPAQueryFactory) : Lecture
.leftJoin(lecture.semesterLectures, semesterLecture)
.leftJoin(semesterLecture.evaluations, lectureEvaluation)
.groupBy(lecture)
.where(*predicates, lectureEvaluation.isHidden.eq(false))
.where(*predicates, lectureEvaluation.isNull.or(lectureEvaluation.isHidden.eq(false)))
.offset(pageable.offset).limit(pageable.pageSize.toLong()).fetch()

val total = queryFactory.select(
Expand Down Expand Up @@ -101,7 +101,7 @@ class LectureRepositoryImpl(private val queryFactory: JPAQueryFactory) : Lecture
).from(lecture)
.innerJoin(lecture.semesterLectures, semesterLecture)
.leftJoin(semesterLecture.evaluations, lectureEvaluation)
.where(lecture.id.`in`(lectureSubQuery.map { it.id }), lectureEvaluation.isHidden.eq(false))
.where(lecture.id.`in`(lectureSubQuery.map { it.id }), lectureEvaluation.isNull.or(lectureEvaluation.isHidden.eq(false)))
.groupBy(lecture)
.fetch()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ import org.springframework.data.jpa.repository.Query
interface SnuttLectureIdMapRepository : JpaRepository<SnuttLectureIdMap, Long> {
@Query("SELECT ttm FROM SnuttLectureIdMap ttm JOIN FETCH ttm.semesterLecture WHERE ttm.snuttId IN :snuttIds")
fun findAllWithSemesterLectureBySnuttIds(snuttIds: List<String>): List<SnuttLectureIdMap>

fun findAllBySnuttIdIn(snuttIds: List<String>): List<SnuttLectureIdMap>
fun findBySnuttId(snuttId: String): SnuttLectureIdMap?
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class LectureService(
return LectureIdResponse(lecture.id!!)
}

fun getLectureIdFromSnuttId(snuttId: String): LectureIdResponse {
val snuttLectureIdMap = snuttLectureIdMapRepository.findBySnuttId(snuttId) ?: throw LectureNotFoundException
return LectureIdResponse(snuttLectureIdMap.semesterLecture.lecture.id!!, snuttLectureIdMap.snuttId)
}

fun getLectureIdsFromSnuttIds(snuttIds: List<String>): List<LectureIdResponse> {
val snuttLectureIdMaps = snuttLectureIdMapRepository.findAllBySnuttIdIn(snuttIds)
return snuttLectureIdMaps.map { LectureIdResponse(it.semesterLecture.lecture.id!!, it.snuttId) }
}

fun getEvLectureSummaryForSnutt(semesterLectureSnuttIds: List<String>): List<EvLectureSummaryForSnutt> {
val snuttIdLectureIdMap = snuttLectureIdMapRepository.findAllWithSemesterLectureBySnuttIds(semesterLectureSnuttIds)
.associate { it.semesterLecture.lecture.id!! to it.snuttId }
Expand Down
Loading