-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DONE] clean meal & calendar code
- Loading branch information
Showing
227 changed files
with
1,495 additions
and
1,261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/dms/pmsandroid/data/calendar/CalendarDataExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.dms.pmsandroid.data.calendar | ||
|
||
import com.dms.pmsandroid.data.calendar.dto.CalendarResponse | ||
import com.dms.pmsandroid.domain.calendar.entity.EventModel | ||
import com.dms.pmsandroid.domain.calendar.entity.EventTypes | ||
import io.reactivex.rxjava3.core.Single | ||
import java.time.LocalDate | ||
|
||
fun CalendarResponse.toEventModel(): Single<MutableMap<LocalDate, EventModel>> = getEventsInResponse(this) | ||
|
||
private fun getEventsInResponse(response: CalendarResponse): Single<MutableMap<LocalDate, EventModel>> = | ||
Single.just(HashMap<LocalDate, EventModel>().apply { | ||
putAll(response.janEvents.toEventModelMap()) | ||
putAll(response.febEvents.toEventModelMap()) | ||
putAll(response.marEvents.toEventModelMap()) | ||
putAll(response.aprEvents.toEventModelMap()) | ||
putAll(response.mayEvents.toEventModelMap()) | ||
putAll(response.junEvents.toEventModelMap()) | ||
putAll(response.julEvents.toEventModelMap()) | ||
putAll(response.augEvents.toEventModelMap()) | ||
putAll(response.sepEvents.toEventModelMap()) | ||
putAll(response.octEvents.toEventModelMap()) | ||
putAll(response.novEvents.toEventModelMap()) | ||
putAll(response.decEvents.toEventModelMap()) | ||
}) | ||
|
||
fun String.toLocalDate():LocalDate = | ||
LocalDate.of(this.substring(0,4).toInt(), this.substring(5,7).toInt(), this.substring(8,10).toInt()) | ||
|
||
fun List<String>.toEventModel(): EventModel { | ||
val eventTypes = ArrayList<EventTypes>() | ||
val resultEvents = ArrayList<String>() | ||
resultEvents.addAll(this) | ||
resultEvents.removeIf { it == "ν μν΄μ μΌ" } | ||
for(event in resultEvents) { | ||
eventTypes.add(event.toEventType()) | ||
} | ||
return EventModel(resultEvents, eventTypes) | ||
} | ||
|
||
private fun Map<String, List<String>>.toEventModelMap() = | ||
this.mapKeys { it.key.toLocalDate() }.mapValues { it.value.toEventModel() } | ||
|
||
fun String.toEventType(): EventTypes { | ||
return when (this) { | ||
"μ무κ·κ°" -> { | ||
EventTypes.MUST_GO_HOME | ||
} | ||
|
||
"μ€κ°κ³ μ¬", "κΈ°λ§κ³ μ¬" -> { | ||
EventTypes.EXAM | ||
} | ||
|
||
"μ¬λ¦λ°©ν", "겨μΈλ°©ν", "μ¬λ¦λ°©νμ", "겨μΈλ°©νμ" -> { | ||
EventTypes.VACATION | ||
} | ||
|
||
"μ μ ", "μ΄λ¦°μ΄λ ", "μκ°νμ μΌ", "νμΆ©μΌ", "κ΄λ³΅μ ", "λ체곡ν΄μΌ", "μΆμμ°ν΄", "μΆμ", "κ°μ²μ ", "νκΈλ ", "κΈ°λ νμ μΌ(μ±νμ )" -> { | ||
EventTypes.HOLIDAYS | ||
} | ||
|
||
else -> { | ||
EventTypes.ETC | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/dms/pmsandroid/data/calendar/dto/CalendarResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.dms.pmsandroid.data.calendar.dto | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CalendarResponse( | ||
@SerializedName("1") | ||
val janEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("2") | ||
val febEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("3") | ||
val marEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("4") | ||
val aprEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("5") | ||
val mayEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("6") | ||
val junEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("7") | ||
val julEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("8") | ||
val augEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("9") | ||
val sepEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("10") | ||
val octEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("11") | ||
val novEvents: Map<String, List<String>>, | ||
|
||
@SerializedName("12") | ||
val decEvents: Map<String, List<String>> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/dms/pmsandroid/data/calendar/repository/CalendarRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.dms.pmsandroid.data.calendar.repository | ||
|
||
import com.dms.pmsandroid.data.calendar.remote.CalendarRemoteDatasource | ||
import com.dms.pmsandroid.data.calendar.toEventModel | ||
import com.dms.pmsandroid.data.calendar.toLocalDate | ||
import com.dms.pmsandroid.data.local.room.EventDatabase | ||
import com.dms.pmsandroid.data.local.room.RoomEvents | ||
import com.dms.pmsandroid.domain.calendar.repository.CalendarRepository | ||
import com.dms.pmsandroid.domain.calendar.entity.EventModel | ||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers | ||
import io.reactivex.rxjava3.core.Single | ||
import io.reactivex.rxjava3.schedulers.Schedulers | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import java.time.LocalDate | ||
import kotlin.collections.HashMap | ||
|
||
class CalendarRepositoryImpl( | ||
private val calendarRemoteDatasource: CalendarRemoteDatasource, | ||
private val eventDatabase: EventDatabase | ||
) : CalendarRepository { | ||
override fun getEvents(): Single<Map<LocalDate, EventModel>> = | ||
getSchedulesAtServerOrLocal() | ||
|
||
private fun getSchedulesAtServerOrLocal(): Single<Map<LocalDate, EventModel>> = | ||
calendarRemoteDatasource.getSchedules() | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.flatMap { response -> | ||
if (response.isSuccessful && response.body() != null) { | ||
val result = response.body()!!.toEventModel() | ||
result.subscribe { event -> | ||
CoroutineScope(Dispatchers.IO).launch { | ||
eventDatabase.eventDao().run { | ||
deleteEvents() | ||
insertEvent(event.map { | ||
RoomEvents( | ||
it.key.toString(), | ||
it.value.eventNames | ||
) | ||
}) | ||
} | ||
} | ||
} | ||
return@flatMap result | ||
} else { | ||
getSchedulesAtLocal() | ||
} | ||
}.onErrorResumeNext { | ||
getSchedulesAtLocal() | ||
} | ||
|
||
private fun getSchedulesAtLocal(): Single<Map<LocalDate, EventModel>> = | ||
eventDatabase.eventDao().getLocalEvent() | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.map { | ||
val filteredList = it.filter { it.events.isNotEmpty() } | ||
HashMap<LocalDate, EventModel>().apply { | ||
for (event in filteredList) { | ||
put(event.date.toLocalDate(), event.events.toEventModel()) | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/dms/pmsandroid/data/introduce/remote/IntroduceApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.dms.pmsandroid.data.introduce.remote | ||
|
||
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubDetailModel | ||
import com.dms.pmsandroid.presentation.feature.introduce.model.ClubListModel | ||
import io.reactivex.rxjava3.core.Single | ||
import retrofit2.Response | ||
import retrofit2.http.* | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Path | ||
|
||
interface IntroduceClubApi { | ||
@GET("/introduce/clubs") | ||
fun club( | ||
@Header("Authorization") accessToken: String | ||
): Single<Response<ClubListModel>> | ||
|
||
|
||
@GET("/introduce/clubs/{clubname}") | ||
fun clubDetail( | ||
@Header("Authorization")accessToken: String, | ||
@Path("clubname")clubname:String | ||
): Single<Response<ClubDetailModel>> | ||
} |
6 changes: 3 additions & 3 deletions
6
...mote/introduce/ProvideIntroduceClubApi.kt β ...troduce/remote/ProvideIntroduceClubApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.