-
Notifications
You must be signed in to change notification settings - Fork 0
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
빈자리 알림 로직 추가 #110
빈자리 알림 로직 추가 #110
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,31 +4,37 @@ import com.wafflestudio.snu4t.common.exception.DuplicateVacancyNotificationExcep | |
import com.wafflestudio.snu4t.common.exception.InvalidRegistrationForPreviousSemesterCourseException | ||
import com.wafflestudio.snu4t.common.exception.LectureNotFoundException | ||
import com.wafflestudio.snu4t.coursebook.service.CoursebookService | ||
import com.wafflestudio.snu4t.lectures.service.LectureService | ||
import com.wafflestudio.snu4t.lectures.data.Lecture | ||
import com.wafflestudio.snu4t.lectures.repository.LectureRepository | ||
import com.wafflestudio.snu4t.vacancynotification.data.VacancyNotification | ||
import com.wafflestudio.snu4t.vacancynotification.repository.VacancyNotificationRepository | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.toList | ||
import org.springframework.dao.DuplicateKeyException | ||
import org.springframework.stereotype.Service | ||
|
||
interface VacancyNotificationService { | ||
suspend fun getVacancyNotificationLectures(userId: String): List<Lecture> | ||
suspend fun addVacancyNotification(userId: String, lectureId: String): VacancyNotification | ||
suspend fun getVacancyNotifications(userId: String): List<VacancyNotification> | ||
suspend fun getVacancyNotification(userId: String, lectureId: String): VacancyNotification | ||
suspend fun deleteVacancyNotification(id: String) | ||
suspend fun deleteVacancyNotification(lectureId: String) | ||
suspend fun deleteAll() | ||
} | ||
|
||
@Service | ||
class VacancyNotificationServiceImpl( | ||
private val vacancyNotificationRepository: VacancyNotificationRepository, | ||
private val lectureService: LectureService, | ||
private val lectureRepository: LectureRepository, | ||
private val coursebookService: CoursebookService | ||
) : VacancyNotificationService { | ||
override suspend fun getVacancyNotificationLectures(userId: String): List<Lecture> = | ||
vacancyNotificationRepository.findAllByUserId(userId).map { it.lectureId } | ||
.let { lectureRepository.findAllById(it) }.toList() | ||
|
||
override suspend fun addVacancyNotification(userId: String, lectureId: String): VacancyNotification = | ||
coroutineScope { | ||
val deferredLecture = async { lectureService.getByIdOrNull(lectureId) } | ||
val deferredLecture = async { lectureRepository.findById(lectureId) } | ||
val deferredLatestCoursebook = async { coursebookService.getLatestCoursebook() } | ||
val (lecture, latestCoursebook) = deferredLecture.await() to deferredLatestCoursebook.await() | ||
|
||
|
@@ -37,17 +43,15 @@ class VacancyNotificationServiceImpl( | |
throw InvalidRegistrationForPreviousSemesterCourseException | ||
} | ||
|
||
trySave(VacancyNotification(userId = userId, lectureId = lectureId, coursebookId = latestCoursebook.id!!)) | ||
trySave(VacancyNotification(userId = userId, lectureId = lectureId)) | ||
} | ||
|
||
override suspend fun getVacancyNotifications(userId: String): List<VacancyNotification> = | ||
vacancyNotificationRepository.findAllByUserId(userId).toList() | ||
|
||
override suspend fun getVacancyNotification(userId: String, lectureId: String): VacancyNotification = | ||
vacancyNotificationRepository.findFirstByUserIdAndLectureId(userId, lectureId) | ||
override suspend fun deleteVacancyNotification(lectureId: String) { | ||
vacancyNotificationRepository.deleteByLectureId(lectureId) | ||
} | ||
|
||
override suspend fun deleteVacancyNotification(id: String) { | ||
vacancyNotificationRepository.deleteById(id) | ||
override suspend fun deleteAll() { | ||
vacancyNotificationRepository.deleteAll() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 mongodb 성능 괜찮으려나? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop table 할걸? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아니네.. 흠 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사실 데이터가 많다면 컬렉션 삭제, 재생성하고 인덱스 재생성하면 더 빠를텐데 DDL날리는것도 좀 그렇고 걍 써도 될듯 |
||
} | ||
|
||
private suspend fun trySave(vacancyNotification: VacancyNotification) = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우리 지난 번에 얘기한 건데 #70 (comment)
db entity 를 그대로 응답에 반환하지 않고 변환해서 전달하면 좋을 거 같아.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 안그래도 반영중이었음
너무 리뷰가 빨랐음ㅋㅋㅋ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davin111 후속 리뷰는?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
내 pr 도 리뷰 좀..!