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

관심강좌에 강의 평점 추가 #253

Merged
merged 3 commits into from
Jul 28, 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
9 changes: 8 additions & 1 deletion api/src/main/kotlin/handler/BookmarkHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ 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)
val bookmark = bookmarkService.getBookmark(userId, year, semester)
val bookmarkLectureDtos = bookmarkService.convertBookmarkLecturesToBookmarkLectureDtos(bookmark.lectures)

BookmarkResponse(
year = bookmark.year,
semester = bookmark.semester.value,
lectures = bookmarkLectureDtos
)
}

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

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

class BookmarkResponse(
val year: Int,
val semester: Int,
val lectures: List<BookmarkLectureDto>,
)

fun BookmarkResponse(bookmark: Bookmark): BookmarkResponse = BookmarkResponse(
year = bookmark.year,
semester = bookmark.semester.value,
lectures = bookmark.lectures.map { BookmarkLectureDto(it) },
)
18 changes: 15 additions & 3 deletions core/src/main/kotlin/bookmark/service/BookmarkService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.wafflestudio.snu4t.bookmark.data.Bookmark
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.dto.BookmarkLectureDto
import com.wafflestudio.snu4t.lectures.service.LectureService
import org.springframework.stereotype.Service

Expand All @@ -13,20 +15,21 @@ interface BookmarkService {
suspend fun existsBookmarkLecture(userId: String, lectureId: String): Boolean
suspend fun addLecture(userId: String, lectureId: String): Bookmark
suspend fun deleteLecture(userId: String, lectureId: String): Bookmark
suspend fun convertBookmarkLecturesToBookmarkLectureDtos(bookmarkLectures: List<BookmarkLecture>): List<BookmarkLectureDto>
}

@Service
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)
?: Bookmark(userId = userId, year = year, semester = semester)
): Bookmark = bookmarkRepository.findFirstByUserIdAndYearAndSemester(userId, year, semester)
?: Bookmark(userId = userId, year = year, semester = semester)

override suspend fun existsBookmarkLecture(userId: String, lectureId: String): Boolean {
val lecture = lectureService.getByIdOrNull(lectureId) ?: throw LectureNotFoundException
Expand All @@ -53,4 +56,13 @@ class BookmarkServiceImpl(
lectureId
)
}

override suspend fun convertBookmarkLecturesToBookmarkLectureDtos(bookmarkLectures: List<BookmarkLecture>): List<BookmarkLectureDto> {
val snuttIdtoLectureMap =
snuttEvRepository.getSummariesByIds(bookmarkLectures.map { it.id!! }).associateBy { it.snuttId }
return bookmarkLectures.map { bookmarkLecture ->
val snuttEvLecture = snuttIdtoLectureMap[bookmarkLecture.id]
BookmarkLectureDto(bookmarkLecture, snuttEvLecture)
}
}
}
5 changes: 4 additions & 1 deletion core/src/main/kotlin/lectures/dto/BookmarkLectureDto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wafflestudio.snu4t.lectures.dto

import com.fasterxml.jackson.annotation.JsonProperty
import com.wafflestudio.snu4t.evaluation.dto.SnuttEvLectureSummaryDto
import com.wafflestudio.snu4t.lectures.data.BookmarkLecture
import com.wafflestudio.snu4t.lectures.utils.ClassTimeUtils

Expand All @@ -25,13 +26,14 @@ data class BookmarkLectureDto(
var courseNumber: String,
@JsonProperty("course_title")
var courseTitle: String,
val snuttEvLecture: SnuttEvLectureSummaryDto? = null,

// FIXME: 안드로이드 구버전 대응용 필드 1년 후 2024년에 삭제 (2023/06/26)
@JsonProperty("class_time_mask")
val classTimeMask: List<Int> = emptyList(),
)

fun BookmarkLectureDto(lecture: BookmarkLecture): BookmarkLectureDto = BookmarkLectureDto(
fun BookmarkLectureDto(lecture: BookmarkLecture, snuttEvLecture: SnuttEvLectureSummaryDto? = null): BookmarkLectureDto = BookmarkLectureDto(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snuttEvLecture가 null 인 건 어떤 경우지? 발생해도 상관 없는 건가?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LectureDto 로 변환할 때랑 비슷한데 snuttEvLecture가 null이 되는 경우는 ev에 보냈던 요청 자체가 실패하거나 해당 강의가 강의평 db에 없어서 map에 해당 강의의 id를 key로 갖는 항목이 없는 경우이고 그렇더라도 요청 자체는 처리되어야 해서 이렇게 만들었어요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 글쿠만... 그래도 지속되면 좀 문제 있는 거라면, log.warn 같은 거라도 찍어둬도 좋을 거 같네여

id = lecture.id,
academicYear = lecture.academicYear,
category = lecture.category,
Expand All @@ -46,5 +48,6 @@ fun BookmarkLectureDto(lecture: BookmarkLecture): BookmarkLectureDto = BookmarkL
lectureNumber = lecture.lectureNumber,
courseNumber = lecture.courseNumber,
courseTitle = lecture.courseTitle,
snuttEvLecture = snuttEvLecture,
classTimeMask = ClassTimeUtils.classTimeToBitmask(lecture.classPlaceAndTimes),
)
Loading