Skip to content

Commit

Permalink
Merge pull request #229 from LeeHaiLim/enhancement
Browse files Browse the repository at this point in the history
Enhancement: 시스템 앱 알림 화면 전환 외
  • Loading branch information
agfalcon authored Dec 13, 2023
2 parents 8b511ff + 8cae396 commit 5a3ee0a
Show file tree
Hide file tree
Showing 38 changed files with 327 additions and 526 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import kotlinx.coroutines.flow.map
import javax.inject.Inject

class LocalCalendarDataSource @Inject constructor(private val dao: EventDao) {
fun get(id: Int): Flow<Event> {
return dao.get(id)
}

fun getEvents(startDateTime: Long, endDateTime: Long): Flow<List<Event>> {
return flowOf(true).map { dao.getEvents(startDateTime, endDateTime) }
Expand Down Expand Up @@ -40,18 +37,4 @@ class LocalCalendarDataSource @Inject constructor(private val dao: EventDao) {
dao.deleteEvents(startDateTime, endDateTime)
}

suspend fun updateEventAttr(
id: Int,
title: String? = null,
startDateTime: Long? = null,
endDateTime: Long? = null,
color: String? = null,
notification: String? = null
) {
title?.let { title -> dao.updateTitle(id, title) }
startDateTime?.let { startDateLong -> dao.updateStartDateTime(id, startDateLong) }
endDateTime?.let { endDateLong -> dao.updateEndDateTime(id, endDateLong) }
color?.let { color -> dao.updateTitle(id, color) }
notification?.let { notification -> dao.updateTitle(id, notification) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,33 @@ import com.teameetmeet.meetmeet.data.network.api.CalendarApi
import com.teameetmeet.meetmeet.data.network.entity.AddEventRequest
import com.teameetmeet.meetmeet.data.network.entity.EventResponse
import com.teameetmeet.meetmeet.data.network.entity.UserEventResponse
import com.teameetmeet.meetmeet.data.toException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class RemoteCalendarDataSource @Inject constructor(private val api: CalendarApi) {
fun getEvents(startDate: String, endDate: String): Flow<List<EventResponse>> {
return flowOf(true)
.map {
val result = api.getEvents(startDate, endDate).events
result
}
.catch {
throw it
//todo: 예외 처리
}
return flowOf(true).map { api.getEvents(startDate, endDate).events }
}

fun getEventsByUserId(
userId: Int,
startDate: String,
endDate: String
): Flow<List<UserEventResponse>> {
return flowOf(true)
.map {
val result = api.getEventsByUserId(userId, startDate, endDate).events
result
}
.catch {
throw it.toException()
}
return flowOf(true).map { api.getEventsByUserId(userId, startDate, endDate).events }
}

fun searchEvents(
keyword: String?,
startDate: String,
endDate: String
): Flow<List<EventResponse>> {
return flowOf(true)
.map { api.searchEvents(keyword, startDate, endDate).events }
.catch {
throw it
//todo: 예외 처리
}
return flowOf(true).map { api.searchEvents(keyword, startDate, endDate).events }
}

fun addEvent(addEventRequest: AddEventRequest): Flow<List<EventResponse>> {
return flowOf(true)
.map {
api.addEvent(addEventRequest).events
}.catch {
throw it
}
return flowOf(true).map { api.addEvent(addEventRequest).events }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ interface EventDao {
@Query("DELETE FROM Event WHERE endDateTime >= :startDateTime AND startDateTime <= :endDateTime")
suspend fun deleteEvents(startDateTime: Long, endDateTime: Long)

@Query("SELECT * FROM Event WHERE id = :id")
fun get(id: Int): Flow<Event>

@Query("SELECT * FROM Event WHERE endDateTime >= :startDateTime AND startDateTime <= :endDateTime")
suspend fun getEvents(startDateTime: Long, endDateTime: Long): List<Event>

@Query("UPDATE Event SET title = :title WHERE id = :id ")
suspend fun updateTitle(id: Int, title: String)

@Query("UPDATE Event SET startDateTime = :startDateTime WHERE id = :id ")
suspend fun updateStartDateTime(id: Int, startDateTime: Long)

@Query("UPDATE Event SET endDateTime = :endDateTime WHERE id = :id ")
suspend fun updateEndDateTime(id: Int, endDateTime: Long)

@Query("UPDATE Event SET color = :color WHERE id = :id ")
suspend fun updateColor(id: Int, color: String)

@Query("UPDATE Event SET notification = :notification WHERE id = :id ")
suspend fun updateNotification(id: Int, notification: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.teameetmeet.meetmeet.data.local.datastore

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import com.teameetmeet.meetmeet.data.NoDataException
Expand All @@ -25,7 +24,7 @@ class DataStoreHelper @Inject constructor(

fun getAppToken(): Flow<String?> = dataStore.data.map { it[ACCESS_TOKEN] }

fun getRefreshToken(): Flow<String?> = dataStore.data.map {it[REFRESH_TOKEN]}
fun getRefreshToken(): Flow<String?> = dataStore.data.map { it[REFRESH_TOKEN] }

suspend fun fetchUserProfile(userProfile: UserProfile) {
dataStore.edit {
Expand All @@ -50,23 +49,6 @@ class DataStoreHelper @Inject constructor(
}
}

fun getAlarmState(): Flow<Boolean> {
return dataStore.data
.map { it[IS_PUSH_ALARM_ON] ?: true }
}

suspend fun storeAlarmState(isOn: Boolean) {
dataStore.edit {
it[IS_PUSH_ALARM_ON] = isOn
}
}

suspend fun resetAlarmState() {
dataStore.edit {
it[IS_PUSH_ALARM_ON] = true
}
}

suspend fun deleteAppToken() {
dataStore.edit {
it[ACCESS_TOKEN] = ""
Expand All @@ -88,6 +70,5 @@ class DataStoreHelper @Inject constructor(
val USER_PROFILE_IMAGE = stringPreferencesKey("userProfileImage")
val USER_NICKNAME = stringPreferencesKey("userNickName")
val USER_EMAIL = stringPreferencesKey("userEmail")
val IS_PUSH_ALARM_ON = booleanPreferencesKey("isPushAlarmOn")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interface LoginApi {
@POST("/auth/login")
suspend fun loginSelf(@Body selfSignRequest: SelfSignRequest): LoginResponse


@GET("auth/check/email")
suspend fun checkEmailDuplication(@Query("email") email: String): AvailableResponse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,42 @@ import com.teameetmeet.meetmeet.util.date.DateTimeFormat
import com.teameetmeet.meetmeet.util.date.toDateString
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import java.time.ZoneId
import javax.inject.Inject

class CalendarRepository @Inject constructor(
private val localCalendarDataSource: LocalCalendarDataSource,
private val remoteCalendarDataSource: RemoteCalendarDataSource
) {
suspend fun getEvents(startDate: Long, endDate: Long): Flow<List<Event>> {
try {
syncEvents(startDate, endDate)
} finally {
return localCalendarDataSource.getEvents(startDate, endDate)
}
fun getSyncedEvents(startDateTime: Long, endDateTime: Long): Flow<List<Event>> {
return remoteCalendarDataSource
.getEvents(
startDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")),
endDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC"))
).onEach {
localCalendarDataSource.deleteEvents(startDateTime, endDateTime)
localCalendarDataSource.insertEvents(it.map(EventResponse::toEvent))
}.map {
localCalendarDataSource.getEvents(startDateTime, endDateTime).first()
}.catch {
emit(localCalendarDataSource.getEvents(startDateTime, endDateTime).first())
}
}

fun getEventsByUserId(userId: Int, startDate: Long, endDate: Long): Flow<List<Event>> {
return remoteCalendarDataSource.getEventsByUserId(
userId,
startDate.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")),
endDate.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC"))
).map {
it.map(UserEventResponse::toEvent)
}
fun getEventsByUserId(userId: Int, startDateTime: Long, endDateTime: Long): Flow<List<Event>> {
return remoteCalendarDataSource
.getEventsByUserId(
userId,
startDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")),
endDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC"))
).map {
it.map(UserEventResponse::toEvent)
}.catch {
throw it.toException()
}
}

suspend fun deleteEvents() {
Expand Down Expand Up @@ -82,19 +94,8 @@ class CalendarRepository @Inject constructor(
endDate: String
): Flow<List<EventResponse>> {
return remoteCalendarDataSource.searchEvents(keyword, startDate, endDate)
}

private suspend fun syncEvents(startDateTime: Long, endDateTime: Long) {
remoteCalendarDataSource
.getEvents(
startDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC")),
endDateTime.toDateString(DateTimeFormat.ISO_DATE_TIME, ZoneId.of("UTC"))
).catch {
//todo: 예외처리
throw it
}.collect {
localCalendarDataSource.deleteEvents(startDateTime, endDateTime)
localCalendarDataSource.insertEvents(it.map(EventResponse::toEvent))
.catch {
throw it.toException()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class EventStoryRepository @Inject constructor(
val contents = media?.map { uri ->
val file = uri.toAbsolutePath()?.let { File(it) } ?: return@map null
val type = uri.getMimeType() ?: return@map null
println(type.toMediaType().toString())
MultipartBody.Part.createFormData(
"contents", file.name, file.asRequestBody(type.toMediaType())
)
Expand All @@ -126,7 +125,7 @@ class EventStoryRepository @Inject constructor(
contents
)
}.catch {
throw it
throw it.toException()
}
}

Expand All @@ -139,49 +138,49 @@ class EventStoryRepository @Inject constructor(
}

fun getFeedDetail(feedId: Int): Flow<FeedDetail> {
return flowOf(true).map {
val userNickname = dataStore.getUserProfile().first().nickname
eventStoryApi.getFeedDetail(feedId).let { feed ->
feed.copy(
isMine = userNickname == feed.author.nickname,
comments = feed.comments.map { comment ->
comment.copy(
isMine = comment.author.nickname == userNickname
)
}
)
return flowOf(true)
.map {
val userNickname = dataStore.getUserProfile().first().nickname
eventStoryApi.getFeedDetail(feedId).let { feed ->
feed.copy(
isMine = userNickname == feed.author.nickname,
comments = feed.comments.map { comment ->
comment.copy(isMine = comment.author.nickname == userNickname)
}
)
}
}.catch {
throw it.toException()
}
}.catch {
//todo: 예외처리
throw it
}
}

fun deleteFeed(feedId: Int): Flow<Unit> {
return flowOf(true).map {
eventStoryApi.deleteFeed(feedId)
}.catch {
throw it.toException()
}
return flowOf(true)
.map {
eventStoryApi.deleteFeed(feedId)
}.catch {
throw it.toException()
}
}

fun addFeedComment(feedId: Int, memo: String): Flow<Unit> {
return flowOf(true).map {
eventStoryApi.addFeedComment(
feedId, AddFeedCommentRequest(memo)
)
}.catch {
//todo: 예외처리
throw it
}
return flowOf(true)
.map {
eventStoryApi.addFeedComment(
feedId, AddFeedCommentRequest(memo)
)
}.catch {
throw it.toException()
}
}

fun deleteFeedComment(feedId: Int, commentId: Int): Flow<Unit> {
return flowOf(true).map {
eventStoryApi.deleteFeedComment(feedId, commentId)
}.catch {
throw it.toException()
}
return flowOf(true)
.map {
eventStoryApi.deleteFeedComment(feedId, commentId)
}.catch {
throw it.toException()
}
}

fun inviteEvent(eventId: Int, userId: Int): Flow<Unit> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TokenRepository @Inject constructor(
is HttpException -> {
if(it.code() == 418) {
val token = refreshAccessToken()
autoLoginApp(token)
emit(autoLoginApp(token).first())
} else {
throw it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class UserRepository @Inject constructor(
fun resetDataStore(): Flow<Unit> {
return flowOf(true)
.map {
dataStore.resetAlarmState()
dataStore.deleteUserProfile()
dataStore.deleteAppToken()
}.catch {
Expand Down
Loading

0 comments on commit 5a3ee0a

Please sign in to comment.