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 #345

Merged
merged 4 commits into from
Feb 15, 2025
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
7 changes: 4 additions & 3 deletions api/src/main/kotlin/filter/ErrorWebFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.wafflestudio.snutt.common.exception.ErrorType
import com.wafflestudio.snutt.common.exception.EvServiceProxyException
import com.wafflestudio.snutt.common.exception.SnuttException
import kotlinx.coroutines.CancellationException
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatusCode
Expand Down Expand Up @@ -46,9 +47,9 @@ class ErrorWebFilter(
SnuttException(errorMessage = throwable.body.title ?: ErrorType.DEFAULT_ERROR.errorMessage),
)
}
is AbortedException -> {
httpStatusCode = HttpStatus.GATEWAY_TIMEOUT
errorBody = makeErrorBody(SnuttException())
is AbortedException, is CancellationException -> {
httpStatusCode = HttpStatus.NO_CONTENT
errorBody = emptyMap<String, Any>()
}
else -> {
log.error(throwable.message, throwable)
Expand Down
11 changes: 0 additions & 11 deletions api/src/main/kotlin/handler/DeviceHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.wafflestudio.snutt.handler
import com.wafflestudio.snutt.common.dto.OkResponse
import com.wafflestudio.snutt.middleware.SnuttRestApiDefaultMiddleware
import com.wafflestudio.snutt.notification.service.DeviceService
import com.wafflestudio.snutt.users.data.User
import com.wafflestudio.snutt.users.service.UserNicknameService
import com.wafflestudio.snutt.users.service.UserService
import org.springframework.stereotype.Component
Expand All @@ -24,19 +23,9 @@ class DeviceHandler(
val registrationId = req.pathVariable("id")
deviceService.addRegistrationId(userId, registrationId, clientInfo)

updateIfUserNicknameNull(req.getContext().user!!)
OkResponse()
}

// TODO 회원가입 API (SNUTT -> SNU4T) 마이그레이션 완료 이후 삭제
// context: https://wafflestudio.slack.com/archives/C0PAVPS5T/p1690711859658779
private suspend fun updateIfUserNicknameNull(user: User) {
if (user.nickname.isNullOrEmpty()) {
val nickname = userNicknameService.generateUniqueRandomNickname()
userService.update(user.copy(nickname = nickname))
}
}

suspend fun removeRegistrationId(req: ServerRequest) =
handle(req) {
val userId = req.userId
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/kotlin/handler/FriendHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FriendHandler(
id = friend.id!!,
userId = partner.id!!,
displayName = partnerDisplayName,
nickname = userNicknameService.getNicknameDto(partner.nickname!!),
nickname = userNicknameService.getNicknameDto(partner.nickname),
createdAt = friend.createdAt,
)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class FriendHandler(
id = friend.id!!,
userId = partner.id!!,
displayName = friend.getPartnerDisplayName(userId),
nickname = userNicknameService.getNicknameDto(partner.nickname!!),
nickname = userNicknameService.getNicknameDto(partner.nickname),
createdAt = friend.createdAt,
)
}
Expand Down
36 changes: 1 addition & 35 deletions api/src/main/kotlin/handler/LectureSearchHandler.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wafflestudio.snutt.handler

import com.fasterxml.jackson.annotation.JsonProperty
import com.wafflestudio.snutt.common.enum.DayOfWeek
import com.wafflestudio.snutt.common.enum.Semester
import com.wafflestudio.snutt.lectures.dto.SearchDto
import com.wafflestudio.snutt.lectures.dto.SearchTimeDto
Expand Down Expand Up @@ -39,8 +38,6 @@ data class SearchQueryLegacy(
val academicYear: List<String>? = null,
val department: List<String>? = null,
val category: List<String>? = null,
@JsonProperty("time_mask")
val timeMask: List<Int>? = null,
val times: List<SearchTimeDto>? = null,
val timesToExclude: List<SearchTimeDto>? = null,
val etc: List<String>? = null,
Expand All @@ -62,7 +59,7 @@ data class SearchQueryLegacy(
department = department,
category = category,
etcTags = etc,
times = times?.takeIf { it.isNotEmpty() } ?: bitmaskToClassTime(timeMask),
times = times,
timesToExclude = timesToExclude,
page = page,
offset = offset,
Expand All @@ -71,35 +68,4 @@ data class SearchQueryLegacy(
categoryPre2025 = categoryPre2025,
)
}

/*
기존 timeMask 스펙을 대응하기 위한 코드
8시부터 23시까지 30분 단위로 강의가 존재하는 경우 1, 존재하지 않는 경우 0인 2진수가 전달된다.
이를 searchTimeDto로 변환
ex) 111000... -> 8:00~9:30 수업 -> startMinute = 480, endMinute: 570
*/
private fun bitmaskToClassTime(timeMask: List<Int>?): List<SearchTimeDto>? =
timeMask?.flatMapIndexed { dayValue, mask ->
mask.toTimeMask().zip((mask shr 1).toTimeMask())
.foldIndexed(emptyList()) { index, acc, (bit, bitBefore) ->
if (bit && !bitBefore) {
acc +
SearchTimeDto(
day = DayOfWeek.getOfValue(dayValue)!!,
startMinute = index * 30 + 8 * 60,
endMinute = index * 30 + 8 * 60 + 30,
)
} else if (bit && bitBefore) {
val updated = acc.last().copy(endMinute = index * 30 + 8 * 60 + 30)
acc.dropLast(1) + updated
} else {
acc
}
}
}

/*
ex) 258048 -> 2진수 00000000000000111111000000000000 -> [..., true, true, true, true, true, true, false, false, ...]
*/
private fun Int.toTimeMask(): List<Boolean> = this.toString(2).padStart(30, '0').map { it == '1' }
}
2 changes: 1 addition & 1 deletion api/src/main/kotlin/handler/UserHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ class UserHandler(
email = user.email,
localId = user.credential.localId,
fbName = user.credential.fbName,
nickname = userNicknameService.getNicknameDto(user.nickname!!),
nickname = userNicknameService.getNicknameDto(user.nickname),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ package com.wafflestudio.snutt.pre2025category.service

import com.wafflestudio.snutt.pre2025category.repository.CategoryPre2025Repository
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.springframework.core.io.buffer.PooledDataBuffer
import org.springframework.stereotype.Service

@Service
class CategoryPre2025FetchService(
private val categoryPre2025Repository: CategoryPre2025Repository,
) {
suspend fun getCategoriesPre2025(): Map<String, String> {
val oldCategoriesXlsx = categoryPre2025Repository.fetchCategoriesPre2025()
val workbook = WorkbookFactory.create(oldCategoriesXlsx.asInputStream())
return workbook.sheetIterator().asSequence()
.flatMap { sheet ->
sheet.rowIterator().asSequence()
.drop(4)
.map { row ->
try {
val currentCourseNumber = row.getCell(7).stringCellValue
val oldCategory = row.getCell(1).stringCellValue
if (currentCourseNumber.isBlank() || oldCategory.isBlank()) {
return@map null
}
currentCourseNumber to oldCategory
} catch (e: Exception) {
null
val oldCategoriesXlsx: PooledDataBuffer = categoryPre2025Repository.fetchCategoriesPre2025()

try {
val workbook = WorkbookFactory.create(oldCategoriesXlsx.asInputStream())
return workbook.sheetIterator().asSequence()
.flatMap { sheet ->
sheet.rowIterator().asSequence()
.drop(4)
.mapNotNull { row ->
runCatching {
val currentCourseNumber = row.getCell(7).stringCellValue
val oldCategory = row.getCell(1).stringCellValue
check(currentCourseNumber.isNotBlank() && oldCategory.isNotBlank())
currentCourseNumber to oldCategory
}.getOrNull()
}
}
.filterNotNull()
}
.toMap()
}
.toMap()
} finally {
oldCategoriesXlsx.release()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wafflestudio.snutt.sugangsnu.common.service

import com.wafflestudio.snutt.common.enum.Semester
import com.wafflestudio.snutt.lectures.data.Lecture
import com.wafflestudio.snutt.pre2025category.service.CategoryPre2025FetchService
import com.wafflestudio.snutt.sugangsnu.common.SugangSnuRepository
import com.wafflestudio.snutt.sugangsnu.common.utils.SugangSnuClassTimeUtils
import org.apache.poi.hssf.usermodel.HSSFWorkbook
Expand All @@ -19,6 +20,7 @@ interface SugangSnuFetchService {
@Service
class SugangSnuFetchServiceImpl(
private val sugangSnuRepository: SugangSnuRepository,
private val categoryPre2025FetchService: CategoryPre2025FetchService,
) : SugangSnuFetchService {
private val log = LoggerFactory.getLogger(javaClass)
private val quotaRegex = """(?<quota>\d+)(\s*\((?<quotaForCurrentStudent>\d+)\))?""".toRegex()
Expand All @@ -27,6 +29,7 @@ class SugangSnuFetchServiceImpl(
year: Int,
semester: Semester,
): List<Lecture> {
val courseNumberCategoryPre2025Map = categoryPre2025FetchService.getCategoriesPre2025()
val koreanLectureXlsx = sugangSnuRepository.getSugangSnuLectures(year, semester, "ko")
val englishLectureXlsx = sugangSnuRepository.getSugangSnuLectures(year, semester, "en")
val koreanSheet = HSSFWorkbook(koreanLectureXlsx.asInputStream()).getSheetAt(0)
Expand Down Expand Up @@ -69,6 +72,7 @@ class SugangSnuFetchServiceImpl(
department = extraDepartment ?: department
quota = extraLectureInfo.subInfo.quota ?: quota
remark = extraLectureInfo.subInfo.remark ?: remark
categoryPre2025 = courseNumberCategoryPre2025Map[lecture.courseNumber]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.wafflestudio.snutt.lecturebuildings.service.LectureBuildingService
import com.wafflestudio.snutt.lectures.data.Lecture
import com.wafflestudio.snutt.lectures.service.LectureService
import com.wafflestudio.snutt.lectures.utils.ClassTimeUtils
import com.wafflestudio.snutt.pre2025category.service.CategoryPre2025FetchService
import com.wafflestudio.snutt.sugangsnu.common.SugangSnuRepository
import com.wafflestudio.snutt.sugangsnu.common.data.SugangSnuCoursebookCondition
import com.wafflestudio.snutt.sugangsnu.common.service.SugangSnuFetchService
Expand Down Expand Up @@ -47,7 +46,6 @@ interface SugangSnuSyncService {
@Service
class SugangSnuSyncServiceImpl(
private val sugangSnuFetchService: SugangSnuFetchService,
private val categoryPre2025FetchService: CategoryPre2025FetchService,
private val lectureService: LectureService,
private val timeTableRepository: TimetableRepository,
private val sugangSnuRepository: SugangSnuRepository,
Expand All @@ -59,14 +57,8 @@ class SugangSnuSyncServiceImpl(
private val log = LoggerFactory.getLogger(javaClass)

override suspend fun updateCoursebook(coursebook: Coursebook): List<UserLectureSyncResult> {
val courseNumberCategoryPre2025Map = categoryPre2025FetchService.getCategoriesPre2025()
val newLectures =
sugangSnuFetchService.getSugangSnuLectures(coursebook.year, coursebook.semester)
.map { lecture ->
lecture.apply {
categoryPre2025 = courseNumberCategoryPre2025Map[lecture.courseNumber]
}
}
val oldLectures =
lectureService.getLecturesByYearAndSemesterAsFlow(coursebook.year, coursebook.semester).toList()
val compareResult = compareLectures(newLectures, oldLectures)
Expand All @@ -81,14 +73,8 @@ class SugangSnuSyncServiceImpl(
}

override suspend fun addCoursebook(coursebook: Coursebook) {
val courseNumberCategoryPre2025Map = categoryPre2025FetchService.getCategoriesPre2025()
val newLectures =
sugangSnuFetchService.getSugangSnuLectures(coursebook.year, coursebook.semester)
.map { lecture ->
lecture.apply {
categoryPre2025 = courseNumberCategoryPre2025Map[lecture.courseNumber]
}
}
lectureService.upsertLectures(newLectures)
syncTagList(coursebook, newLectures)

Expand Down
103 changes: 0 additions & 103 deletions batch/src/main/kotlin/users/job/UserNicknameCreateJobConfig.kt

This file was deleted.

1 change: 0 additions & 1 deletion core/src/main/kotlin/evaluation/service/EvService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class EvService(
val result: MutableMap<String, Any?>? =
snuttEvWebClient.method(method)
.uri { builder -> builder.path(requestPath).queryParams(requestQueryParams).build() }
.contentType(MediaType.APPLICATION_JSON)
.header("Snutt-User-Id", userId)
.header(HttpHeaders.CONTENT_ENCODING, "UTF-8")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/friend/service/FriendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class FriendServiceImpl(
fromUser: User,
toUserId: String,
) {
val fromUserNickname = userNicknameService.getNicknameDto(fromUser.nickname!!).nickname
val fromUserNickname = userNicknameService.getNicknameDto(fromUser.nickname).nickname
val pushMessage =
PushMessage(
title = "친구 요청",
Expand Down Expand Up @@ -164,7 +164,7 @@ class FriendServiceImpl(
fromUserId: String,
toUser: User,
) {
val toUserNickname = userNicknameService.getNicknameDto(toUser.nickname!!).nickname
val toUserNickname = userNicknameService.getNicknameDto(toUser.nickname).nickname
val pushMessage =
PushMessage(
title = "친구 요청 수락",
Expand Down
Loading
Loading