Skip to content

Commit

Permalink
Merge pull request #175 from wafflestudio/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
davin111 authored Sep 15, 2023
2 parents 1888a84 + 6618d99 commit 8d59f41
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
23 changes: 17 additions & 6 deletions core/src/main/kotlin/clientconfig/service/ClientConfigService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import com.wafflestudio.snu4t.clientconfig.repository.findByNameAndVersions
import com.wafflestudio.snu4t.common.cache.Cache
import com.wafflestudio.snu4t.common.cache.CacheKey
import com.wafflestudio.snu4t.common.cache.get
import com.wafflestudio.snu4t.common.client.AppVersion
import com.wafflestudio.snu4t.common.client.ClientInfo
import com.wafflestudio.snu4t.common.client.OsType
import com.wafflestudio.snu4t.common.exception.ConfigNotFoundException
import com.wafflestudio.snu4t.config.Phase
import kotlinx.coroutines.flow.toList
import org.springframework.stereotype.Service
import java.time.LocalDateTime
Expand All @@ -20,16 +23,24 @@ class ClientConfigService(
private val clientConfigRepository: ClientConfigRepository,
private val objectMapper: ObjectMapper,
private val cache: Cache,
private val phase: Phase
) {
suspend fun getConfigs(clientInfo: ClientInfo): List<ClientConfig> {
val (osType, appVersion) = clientInfo.osType to requireNotNull(clientInfo.appVersion)

return CacheKey.CLIENT_CONFIGS.build(osType, appVersion).let { cacheKey ->
cache.get(cacheKey) {
clientConfigRepository.findAll().toList()
.filter { it.isAdaptable(osType, appVersion) }.distinctBy { it.name }
}
} ?: emptyList()
if (!phase.isProd) {
return getAdaptableConfigs(osType, appVersion)
}

val cacheKey = CacheKey.CLIENT_CONFIGS.build(osType, appVersion)
return cache.get(cacheKey) { getAdaptableConfigs(osType, appVersion) } ?: emptyList()
}

private suspend fun getAdaptableConfigs(osType: OsType, appVersion: AppVersion): List<ClientConfig> {
return clientConfigRepository.findAll()
.toList()
.filter { it.isAdaptable(osType, appVersion) }
.distinctBy { it.name }
}

suspend fun getConfigsByName(name: String): List<ClientConfig> {
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/kotlin/common/exception/ErrorType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ enum class ErrorType(
PRIMARY_TIMETABLE_NOT_FOUND(HttpStatus.NOT_FOUND, 40401, "timetable_id가 유효하지 않습니다", "대표 시간표가 존재하지 않습니다."),
NO_USER_FCM_KEY(HttpStatus.NOT_FOUND, 40402, "유저 FCM 키가 존재하지 않습니다."),
CONFIG_NOT_FOUND(HttpStatus.NOT_FOUND, 40403, "config가 존재하지 않습니다."),
FRIEND_NOT_FOUND(HttpStatus.NOT_FOUND, 40404, "친구 관계가 존재하지 않습니다."),
FRIEND_NOT_FOUND(HttpStatus.NOT_FOUND, 40404, "친구 관계가 존재하지 않습니다.", "친구 관계가 존재하지 않습니다."),
USER_NOT_FOUND_BY_NICKNAME(HttpStatus.NOT_FOUND, 40405, "해당 닉네임의 유저를 찾을 수 없습니다.", "해당 닉네임의 유저를 찾을 수 없습니다."),

DUPLICATE_VACANCY_NOTIFICATION(HttpStatus.CONFLICT, 40900, "빈자리 알림 중복"),
DUPLICATE_EMAIL(HttpStatus.CONFLICT, 40901, "이미 사용 중인 이메일입니다."),
DUPLICATE_FRIEND(HttpStatus.CONFLICT, 40902, "이미 친구 관계이거나 친구 요청을 보냈습니다."),
INVALID_FRIEND(HttpStatus.CONFLICT, 40903, "친구 요청을 보낼 수 없는 유저입니다."),
DUPLICATE_FRIEND(HttpStatus.CONFLICT, 40902, "이미 친구 관계이거나 친구 요청을 보냈습니다.", "이미 친구 관계이거나 친구 요청을 보냈습니다."),
INVALID_FRIEND(HttpStatus.CONFLICT, 40903, "친구 요청을 보낼 수 없는 유저입니다.", "친구 요청을 보낼 수 없는 유저입니다."),

DYNAMIC_LINK_GENERATION_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, 50001, "링크 생성 실패", "링크 생성에 실패했습니다. 잠시 후 다시 시도해주세요."),
}
1 change: 1 addition & 0 deletions core/src/main/kotlin/common/exception/Snu4tException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ object PrimaryTimetableNotFoundException : Snu4tException(ErrorType.TIMETABLE_NO
object TimetableNotPrimaryException : Snu4tException(ErrorType.DEFAULT_ERROR)
object ConfigNotFoundException : Snu4tException(ErrorType.CONFIG_NOT_FOUND)
object FriendNotFoundException : Snu4tException(ErrorType.FRIEND_NOT_FOUND)
object UserNotFoundByNicknameException : Snu4tException(ErrorType.USER_NOT_FOUND_BY_NICKNAME)

object DuplicateVacancyNotificationException : Snu4tException(ErrorType.DUPLICATE_VACANCY_NOTIFICATION)
object DuplicateEmailException : Snu4tException(ErrorType.DUPLICATE_EMAIL)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/kotlin/common/push/UrlScheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum class UrlScheme(
) {
NOTIFICATIONS(Protocol.SNUTT, "notifications"),
VACANCY(Protocol.SNUTT, "vacancy"),
FRIENDS(Protocol.SNUTT, "friends"),
;

fun compileWith(
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/config/PhaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ enum class Phase {
LOCAL,
TEST
;

val isProd: Boolean
get() = this == PROD
}
7 changes: 5 additions & 2 deletions core/src/main/kotlin/friend/service/FriendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.wafflestudio.snu4t.common.exception.DuplicateFriendException
import com.wafflestudio.snu4t.common.exception.FriendNotFoundException
import com.wafflestudio.snu4t.common.exception.InvalidDisplayNameException
import com.wafflestudio.snu4t.common.exception.InvalidFriendException
import com.wafflestudio.snu4t.common.exception.UserNotFoundException
import com.wafflestudio.snu4t.common.exception.UserNotFoundByNicknameException
import com.wafflestudio.snu4t.common.push.UrlScheme
import com.wafflestudio.snu4t.common.push.dto.PushMessage
import com.wafflestudio.snu4t.friend.data.Friend
import com.wafflestudio.snu4t.friend.dto.FriendState
Expand Down Expand Up @@ -66,7 +67,7 @@ class FriendServiceImpl(
}

override suspend fun requestFriend(fromUserId: String, toUserNickname: String): Unit = coroutineScope {
val toUser = userRepository.findByNicknameAndActiveTrue(toUserNickname) ?: throw UserNotFoundException
val toUser = userRepository.findByNicknameAndActiveTrue(toUserNickname) ?: throw UserNotFoundByNicknameException
val toUserId = toUser.id!!

if (fromUserId == toUserId) throw InvalidFriendException
Expand All @@ -87,6 +88,7 @@ class FriendServiceImpl(
val pushMessage = PushMessage(
title = "친구 요청",
body = "'$fromUserNickname'님의 친구 요청을 수락하고 서로의 대표 시간표를 확인해보세요!",
urlScheme = UrlScheme.FRIENDS,
)
pushWithNotificationService.sendPushAndNotification(pushMessage, NotificationType.NORMAL, toUserId)
}
Expand All @@ -110,6 +112,7 @@ class FriendServiceImpl(
val pushMessage = PushMessage(
title = "친구 요청 수락",
body = "'$toUserNickname'님과 친구가 되었어요.",
urlScheme = UrlScheme.FRIENDS,
)
pushWithNotificationService.sendPushAndNotification(pushMessage, NotificationType.NORMAL, fromUserId)
}
Expand Down

0 comments on commit 8d59f41

Please sign in to comment.