Skip to content

Commit

Permalink
BookmarkResponse 변환 시 SnuttEvLectureSummaryDto 추가하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
asp345 committed Jul 24, 2024
1 parent c380c40 commit 8d8c48b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions api/src/main/kotlin/handler/BookmarkHandler.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wafflestudio.snu4t.handler

import com.wafflestudio.snu4t.bookmark.dto.BookmarkLectureModifyRequest
import com.wafflestudio.snu4t.bookmark.dto.BookmarkResponse
import com.wafflestudio.snu4t.bookmark.service.BookmarkService
import com.wafflestudio.snu4t.common.dto.ExistenceResponse
import com.wafflestudio.snu4t.common.enum.Semester
Expand All @@ -20,7 +19,7 @@ class BookmarkHandler(
val userId: String = req.userId
val year: Int = req.parseRequiredQueryParam("year")
val semester: Semester = req.parseRequiredQueryParam("semester") { Semester.getOfValue(it.toInt()) }
bookmarkService.getBookmark(userId, year, semester).let(::BookmarkResponse)
bookmarkService.getBookmark(userId, year, semester)
}

suspend fun existsBookmarkLecture(req: ServerRequest) = handle(req) {
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/kotlin/bookmark/dto/BookmarkResponse.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wafflestudio.snu4t.bookmark.dto

import com.wafflestudio.snu4t.bookmark.data.Bookmark
import com.wafflestudio.snu4t.evaluation.dto.SnuttEvLectureSummaryDto
import com.wafflestudio.snu4t.lectures.dto.BookmarkLectureDto

class BookmarkResponse(
Expand All @@ -9,8 +10,8 @@ class BookmarkResponse(
val lectures: List<BookmarkLectureDto>,
)

fun BookmarkResponse(bookmark: Bookmark): BookmarkResponse = BookmarkResponse(
fun BookmarkResponse(bookmark: Bookmark, snuttIdToEvLectureMap: Map<String, SnuttEvLectureSummaryDto> = mapOf()): BookmarkResponse = BookmarkResponse(
year = bookmark.year,
semester = bookmark.semester.value,
lectures = bookmark.lectures.map { BookmarkLectureDto(it) },
lectures = bookmark.lectures.map { BookmarkLectureDto(it, snuttIdToEvLectureMap[it.id]) },
)
13 changes: 10 additions & 3 deletions core/src/main/kotlin/bookmark/service/BookmarkService.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.wafflestudio.snu4t.bookmark.service

import com.wafflestudio.snu4t.bookmark.data.Bookmark
import com.wafflestudio.snu4t.bookmark.dto.BookmarkResponse
import com.wafflestudio.snu4t.bookmark.repository.BookmarkRepository
import com.wafflestudio.snu4t.common.enum.Semester
import com.wafflestudio.snu4t.common.exception.LectureNotFoundException
import com.wafflestudio.snu4t.evaluation.repository.SnuttEvRepository
import com.wafflestudio.snu4t.lectures.data.BookmarkLecture
import com.wafflestudio.snu4t.lectures.service.LectureService
import org.springframework.stereotype.Service

interface BookmarkService {
suspend fun getBookmark(userId: String, year: Int, semester: Semester): Bookmark
suspend fun getBookmark(userId: String, year: Int, semester: Semester): BookmarkResponse
suspend fun existsBookmarkLecture(userId: String, lectureId: String): Boolean
suspend fun addLecture(userId: String, lectureId: String): Bookmark
suspend fun deleteLecture(userId: String, lectureId: String): Bookmark
Expand All @@ -19,14 +21,19 @@ interface BookmarkService {
class BookmarkServiceImpl(
private val bookmarkRepository: BookmarkRepository,
private val lectureService: LectureService,
private val snuttEvRepository: SnuttEvRepository,
) : BookmarkService {
override suspend fun getBookmark(
userId: String,
year: Int,
semester: Semester
): Bookmark =
bookmarkRepository.findFirstByUserIdAndYearAndSemester(userId, year, semester)
): BookmarkResponse {
val bookmark = bookmarkRepository.findFirstByUserIdAndYearAndSemester(userId, year, semester)
?: Bookmark(userId = userId, year = year, semester = semester)
val snuttIdToEvLectureMap =
snuttEvRepository.getSummariesByIds(bookmark.lectures.map { it.id!! }).associateBy { it.snuttId }
return BookmarkResponse(bookmark, snuttIdToEvLectureMap)
}

override suspend fun existsBookmarkLecture(userId: String, lectureId: String): Boolean {
val lecture = lectureService.getByIdOrNull(lectureId) ?: throw LectureNotFoundException
Expand Down

0 comments on commit 8d8c48b

Please sign in to comment.