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

๐Ÿ”€ :: (#429) - Set up attend api #441

Merged
merged 14 commits into from
Apr 11, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.msg.gcms.data.remote.datasource.attend

import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusCollectivelyRequest
import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusRequest
import com.msg.gcms.data.remote.dto.attend.request.PostAttendListRequest
import com.msg.gcms.data.remote.dto.attend.response.GetClubAttendListResponse
import kotlinx.coroutines.flow.Flow
import java.time.LocalDate

interface AttendDataSource {
suspend fun getClubAttendList(clubId: Long, date: LocalDate, period: String): Flow<GetClubAttendListResponse>
suspend fun postAttendList(body: PostAttendListRequest): Flow<Unit>
suspend fun patchAttendStatus(body: PatchAttendStatusRequest): Flow<Unit>
suspend fun patchAttendStatusCollectively(body: PatchAttendStatusCollectivelyRequest): Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.msg.gcms.data.remote.datasource.attend

import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusCollectivelyRequest
import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusRequest
import com.msg.gcms.data.remote.dto.attend.request.PostAttendListRequest
import com.msg.gcms.data.remote.dto.attend.response.GetClubAttendListResponse
import com.msg.gcms.data.remote.network.api.AttendAPI
import com.msg.gcms.data.remote.util.GCMSApiHandler
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import java.time.LocalDate
import java.time.LocalTime
import javax.inject.Inject

class AttendDataSourceImpl @Inject constructor(
private val attendAPI: AttendAPI
) : AttendDataSource {
override suspend fun getClubAttendList(
clubId: Long,
date: LocalDate,
period: String
): Flow<GetClubAttendListResponse> = flow {
emit(
GCMSApiHandler<GetClubAttendListResponse>()
.httpRequest {
attendAPI.getAttendList(
clubId = clubId,
date = date,
period = period
)
}
.sendRequest()
)
}

override suspend fun postAttendList(body: PostAttendListRequest): Flow<Unit> = flow {
emit(
GCMSApiHandler<Unit>()
.httpRequest {
attendAPI.postAttendList(
body = body
)
}
.sendRequest()
)
}

override suspend fun patchAttendStatus(body: PatchAttendStatusRequest): Flow<Unit> = flow {
emit(
GCMSApiHandler<Unit>()
.httpRequest {
attendAPI.patchAttendStatus(
body = body
)
}
.sendRequest()
)
}

override suspend fun patchAttendStatusCollectively(body: PatchAttendStatusCollectivelyRequest): Flow<Unit> = flow {
emit(
GCMSApiHandler<Unit>()
.httpRequest {
attendAPI.patchAttendStatusCollectively(
body = body
)
}
.sendRequest()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.gcms.data.remote.dto.attend.request

import com.google.gson.annotations.SerializedName

data class PatchAttendStatusCollectivelyRequest(
@SerializedName("attendanceIds")
val attendanceIds: List<Long>,
@SerializedName("attendanceStatus")
val attendanceStatus: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.gcms.data.remote.dto.attend.request

import com.google.gson.annotations.SerializedName

data class PatchAttendStatusRequest(
@SerializedName("attendanceId")
val attendanceId: Long,
@SerializedName("attendanceStatus")
val attendanceStatus: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.msg.gcms.data.remote.dto.attend.request

import com.google.gson.annotations.SerializedName
import java.time.LocalDate

data class PostAttendListRequest(
@SerializedName("name")
val name: String,
@SerializedName("date")
val date: LocalDate,
@SerializedName("periods")
val periods: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.msg.gcms.data.remote.dto.attend.response

import com.google.gson.annotations.SerializedName
import com.msg.gcms.domain.data.attend.GetClubAttendListResponseData
import com.msg.gcms.domain.data.attend.GetClubAttendListResponseData.User as DomainUser
import java.time.LocalDate
import java.time.LocalTime
import java.util.UUID

data class GetClubAttendListResponse(
@SerializedName("date")
val date: LocalDate,
@SerializedName("period")
val period: LocalTime,
@SerializedName("users")
val users: List<User>
) {
data class User(
@SerializedName("id")
val id: UUID,
@SerializedName("attendanceId")
val attendanceId: Long,
@SerializedName("name")
val name: String,
@SerializedName("grade")
val grade: Int,
@SerializedName("classNum")
val classNum: Int,
@SerializedName("number")
val number: Int,
@SerializedName("attendanceState")
val attendanceStatus: String
)

fun User.toDomainUser(): DomainUser {
return DomainUser(
id = id,
attendanceId = attendanceId,
name = name,
grade = grade,
classNum = classNum,
number = number,
attendanceStatus = attendanceStatus
)
}
}

fun GetClubAttendListResponse.toGetClubAttendListResponseData(): GetClubAttendListResponseData {
return GetClubAttendListResponseData(
date = date,
period = period,
users = users.map { it.toDomainUser() }
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.msg.gcms.data.remote.network.api

import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusCollectivelyRequest
import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusRequest
import com.msg.gcms.data.remote.dto.attend.request.PostAttendListRequest
import com.msg.gcms.data.remote.dto.attend.response.GetClubAttendListResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query
import java.time.LocalDate
import java.time.LocalTime

interface AttendAPI {

@GET("attend/{club_id}")
suspend fun getAttendList(
@Path("club_id") clubId: Long,
@Query("date") date: LocalDate,
@Query("period") period: String
): GetClubAttendListResponse

@POST("attend/{club_id}/club")
suspend fun postAttendList(
@Body body: PostAttendListRequest
)

@PATCH("attend")
suspend fun patchAttendStatus(
@Body body: PatchAttendStatusRequest
)

@PATCH("attend/batch")
suspend fun patchAttendStatusCollectively(
@Body body: PatchAttendStatusCollectivelyRequest
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.msg.gcms.data.repository

import com.msg.gcms.data.remote.datasource.attend.AttendDataSource
import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusCollectivelyRequest
import com.msg.gcms.data.remote.dto.attend.request.PatchAttendStatusRequest
import com.msg.gcms.data.remote.dto.attend.request.PostAttendListRequest
import com.msg.gcms.data.remote.dto.attend.response.toGetClubAttendListResponseData
import com.msg.gcms.domain.data.attend.GetClubAttendListResponseData
import com.msg.gcms.domain.data.attend.PatchAttendStatusCollectivelyRequestData
import com.msg.gcms.domain.data.attend.PatchAttendStatusRequestData
import com.msg.gcms.domain.data.attend.PostAttendListRequestData
import com.msg.gcms.domain.repository.AttendRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import java.time.LocalDate
import java.time.LocalTime
import javax.inject.Inject

class AttendRepositoryImpl @Inject constructor(
private val attendDataSource: AttendDataSource
) : AttendRepository {
override suspend fun getClubAttendList(
clubId: Long,
date: LocalDate,
period: String
): Flow<GetClubAttendListResponseData> {
return attendDataSource.getClubAttendList(
clubId = clubId,
date = date,
period = period
).map {
it.toGetClubAttendListResponseData()
}
}

override suspend fun postAttendList(body: PostAttendListRequestData): Flow<Unit> {
return attendDataSource.postAttendList(
body = PostAttendListRequest(
name = body.name,
date = body.date,
periods = body.periods
)
)
}

override suspend fun patchAttendStatus(body: PatchAttendStatusRequestData): Flow<Unit> {
return attendDataSource.patchAttendStatus(
body = PatchAttendStatusRequest(
attendanceId = body.attendanceId,
attendanceStatus = body.attendanceStatus
)
)
}

override suspend fun patchAttendStatusCollectively(body: PatchAttendStatusCollectivelyRequestData): Flow<Unit> {
return attendDataSource.patchAttendStatusCollectively(
body = PatchAttendStatusCollectivelyRequest(
attendanceIds = body.attendanceIds,
attendanceStatus = body.attendanceStatus
)
)
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/msg/gcms/di/module/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.msg.gcms.data.remote.network.api.AuthAPI
import com.msg.gcms.data.remote.network.api.ImageAPI
import com.msg.gcms.data.remote.network.LoginInterceptor
import com.msg.gcms.data.remote.network.api.ApplicantAPI
import com.msg.gcms.data.remote.network.api.AttendAPI
import com.msg.gcms.data.remote.network.api.ClubMemberAPI
import com.msg.gcms.data.remote.network.api.UserAPI
import dagger.Module
Expand All @@ -17,6 +18,7 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

Expand Down Expand Up @@ -102,4 +104,10 @@ object NetworkModule {
fun provideUserService(retrofit: Retrofit): UserAPI {
return retrofit.create(UserAPI::class.java)
}

@Provides
@Singleton
fun provideAttendService(retrofit: Retrofit): AttendAPI {
return retrofit.create(AttendAPI::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.msg.gcms.di.module

import com.msg.gcms.data.remote.datasource.applicant.ApplicantDataSource
import com.msg.gcms.data.remote.datasource.applicant.ApplicantDataSourceImpl
import com.msg.gcms.data.remote.datasource.attend.AttendDataSource
import com.msg.gcms.data.remote.datasource.attend.AttendDataSourceImpl
import com.msg.gcms.data.remote.datasource.auth.AuthDataSource
import com.msg.gcms.data.remote.datasource.auth.AuthDataSourceImpl
import com.msg.gcms.data.remote.datasource.club.ClubDataSource
Expand Down Expand Up @@ -51,4 +53,8 @@ abstract class RemoteDataSourceModule {
clubMemberDataSourceImpl: ClubMemberDataSourceImpl
): ClubMemberDataSource

@Binds
abstract fun bindAttendDataSource(
attendDataSourceImpl: AttendDataSourceImpl
): AttendDataSource
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/msg/gcms/di/module/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.msg.gcms.di.module

import com.msg.gcms.data.repository.ApplicantRepositoryImpl
import com.msg.gcms.data.repository.AttendRepositoryImpl
import com.msg.gcms.data.repository.AuthRepositoryImpl
import com.msg.gcms.data.repository.ClubMemberRepositoryImpl
import com.msg.gcms.data.repository.ClubRepositoryImpl
import com.msg.gcms.data.repository.ImageRepositoryImpl
import com.msg.gcms.data.repository.UserRepositoryImpl
import com.msg.gcms.domain.repository.ApplicantRepository
import com.msg.gcms.domain.repository.AttendRepository
import com.msg.gcms.domain.repository.AuthRepository
import com.msg.gcms.domain.repository.ClubMemberRepository
import com.msg.gcms.domain.repository.ClubRepository
Expand Down Expand Up @@ -50,4 +52,9 @@ abstract class RepositoryModule {
abstract fun provideUserRepository(
userRepositoryImpl: UserRepositoryImpl
): UserRepository

@Binds
abstract fun bindAttendRepository(
attendRepositoryImpl: AttendRepositoryImpl
): AttendRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.msg.gcms.domain.data.attend

import java.time.LocalDate
import java.time.LocalTime
import java.util.UUID

data class GetClubAttendListResponseData(
val date: LocalDate,
val period: LocalTime,
val users: List<User>
) {
data class User(
val id: UUID,
val attendanceId: Long,
val name: String,
val grade: Int,
val classNum: Int,
val number: Int,
val attendanceStatus: String
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.msg.gcms.domain.data.attend

data class PatchAttendStatusCollectivelyRequestData(
val attendanceIds: List<Long>,
val attendanceStatus: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.msg.gcms.domain.data.attend

data class PatchAttendStatusRequestData(
val attendanceId: Long,
val attendanceStatus: String
)
Loading
Loading