Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.msg.gcms.data.remote.datasource.notification

import com.msg.gcms.data.remote.dto.notification.request.PatchModifyNotificationRequest
import com.msg.gcms.data.remote.dto.notification.request.PostWriteNotificationRequest
import com.msg.gcms.data.remote.dto.notification.response.GetDetailNotificationResponse
import com.msg.gcms.data.remote.dto.notification.response.GetNotificationListResponse
import kotlinx.coroutines.flow.Flow

interface NotificationDataSource {
suspend fun postWriteNotice(clubId: Long, body: PostWriteNotificationRequest): Flow<Unit>
suspend fun getNoticeList(clubId: Long): Flow<GetNotificationListResponse>
suspend fun getDetailNotice(id: Long): Flow<GetDetailNotificationResponse>
suspend fun patchNotice(id: Long ,body: PatchModifyNotificationRequest): Flow<Unit>
suspend fun deleteNotice(id: Long): Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.msg.gcms.data.remote.datasource.notification

import com.msg.gcms.data.remote.dto.notification.request.PatchModifyNotificationRequest
import com.msg.gcms.data.remote.dto.notification.request.PostWriteNotificationRequest
import com.msg.gcms.data.remote.dto.notification.response.GetDetailNotificationResponse
import com.msg.gcms.data.remote.dto.notification.response.GetNotificationListResponse
import com.msg.gcms.data.remote.network.api.NotificationAPI
import com.msg.gcms.data.remote.util.GCMSApiHandler
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class NotificationDataSourceImpl @Inject constructor(
private val noticeService: NotificationAPI
) : NotificationDataSource {
override suspend fun postWriteNotice(clubId: Long, body: PostWriteNotificationRequest): Flow<Unit> = flow {
emit(
GCMSApiHandler<Unit>()
.httpRequest {
noticeService.writeNotification(
clubId = clubId,
body = body
)
}
.sendRequest()
)
}

override suspend fun getNoticeList(clubId: Long): Flow<GetNotificationListResponse> = flow {
emit(
GCMSApiHandler<GetNotificationListResponse>()
.httpRequest {
noticeService.getNoticeList(clubId = clubId)
}
.sendRequest()
)
}

override suspend fun getDetailNotice(id: Long): Flow<GetDetailNotificationResponse> = flow {
emit(
GCMSApiHandler<GetDetailNotificationResponse>()
.httpRequest {
noticeService.getDetailNotification(id = id)
}
.sendRequest()
)
}

override suspend fun patchNotice(id: Long, body: PatchModifyNotificationRequest): Flow<Unit> = flow {
emit(
GCMSApiHandler<Unit>()
.httpRequest {
noticeService.patchNotification(
id = id,
body = body
)
}
.sendRequest()
)
}

override suspend fun deleteNotice(id: Long): Flow<Unit> = flow {
emit(
GCMSApiHandler<Unit>()
.httpRequest {
noticeService.deleteNotification(id = id)
}
.sendRequest()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.gcms.data.remote.dto.notification.request

import com.google.gson.annotations.SerializedName

data class PatchModifyNotificationRequest(
@SerializedName("title")
val title: String,
@SerializedName("content")
val content: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.gcms.data.remote.dto.notification.request

import com.google.gson.annotations.SerializedName

data class PostWriteNotificationRequest(
@SerializedName("title")
val title: String,
@SerializedName("content")
val content: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.msg.gcms.data.remote.dto.notification.response

import com.google.gson.annotations.SerializedName
import com.msg.gcms.domain.data.notification.GetDetailNotificationResponseData
import java.time.LocalDateTime

data class GetDetailNotificationResponse(
@SerializedName("title")
val title: String,
@SerializedName("content")
val content: String,
@SerializedName("username")
val username: String,
@SerializedName("userProfileImg")
val userProfileImg: String,
@SerializedName("createdAt")
val createdAt: LocalDateTime
)

fun GetDetailNotificationResponse.toDetailNotificationData(): GetDetailNotificationResponseData {
return GetDetailNotificationResponseData(
title = title,
content = content,
username = username,
userProfileImg = userProfileImg,
createdAt = createdAt
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.msg.gcms.data.remote.dto.notification.response

import com.google.gson.annotations.SerializedName
import com.msg.gcms.domain.data.notification.GetNotificationListResponseData
import com.msg.gcms.domain.data.notification.GetNotificationListResponseData.Notice as DomainNotice
import java.time.LocalDateTime

data class GetNotificationListResponse(
@SerializedName("notices")
val notices: List<Notice>
) {
data class Notice(
@SerializedName("id")
val id: Long,
@SerializedName("title")
val title: String,
@SerializedName("username")
val username: String,
@SerializedName("createdAt")
val createdAt: LocalDateTime
)

fun Notice.toDomainNotice(): DomainNotice {
return DomainNotice(
id = id,
title = title,
username = username,
createdAt = createdAt
)
}
}

fun GetNotificationListResponse.toGetNotificationListResponseData(): GetNotificationListResponseData {
return GetNotificationListResponseData(
notices = notices.map { it.toDomainNotice() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query
import java.time.LocalDate
import java.time.LocalTime

interface AttendAPI {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.msg.gcms.data.remote.network.api

import com.msg.gcms.data.remote.dto.notification.request.PatchModifyNotificationRequest
import com.msg.gcms.data.remote.dto.notification.request.PostWriteNotificationRequest
import com.msg.gcms.data.remote.dto.notification.response.GetDetailNotificationResponse
import com.msg.gcms.data.remote.dto.notification.response.GetNotificationListResponse
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Path

interface NotificationAPI {

@POST("notification/{club_id}")
fun writeNotification(
@Path("club_id") clubId: Long,
@Body body: PostWriteNotificationRequest
)

@GET("notification/{club_id}/all")
fun getNoticeList(
@Path("club_id") clubId: Long
): GetNotificationListResponse

@GET("notification/{id}")
fun getDetailNotification(
@Path("id") id: Long
): GetDetailNotificationResponse

@PATCH("notification/{id}")
fun patchNotification(
@Path("id") id: Long,
@Body body: PatchModifyNotificationRequest
)

@DELETE("notification/{id}")
fun deleteNotification(
@Path("id") id: Long
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.msg.gcms.data.repository

import com.msg.gcms.data.remote.datasource.notification.NotificationDataSource
import com.msg.gcms.data.remote.dto.notification.request.PatchModifyNotificationRequest
import com.msg.gcms.data.remote.dto.notification.request.PostWriteNotificationRequest
import com.msg.gcms.data.remote.dto.notification.response.GetDetailNotificationResponse
import com.msg.gcms.data.remote.dto.notification.response.toDetailNotificationData
import com.msg.gcms.data.remote.dto.notification.response.toGetNotificationListResponseData
import com.msg.gcms.domain.data.notification.GetDetailNotificationResponseData
import com.msg.gcms.domain.data.notification.GetNotificationListResponseData
import com.msg.gcms.domain.data.notification.PatchModifyNotificationRequestData
import com.msg.gcms.domain.data.notification.PostWriteNotificationRequestData
import com.msg.gcms.domain.repository.NotificationRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class NotificationRepositoryImpl @Inject constructor(
private val notificationDataSource: NotificationDataSource
) : NotificationRepository {
override suspend fun postWriteNotice(
clubId: Long,
body: PostWriteNotificationRequestData
): Flow<Unit> {
return notificationDataSource.postWriteNotice(
clubId = clubId,
body = PostWriteNotificationRequest(
title = body.title,
content = body.content
)
)
}

override suspend fun getNoticeList(clubId: Long): Flow<GetNotificationListResponseData> {
return notificationDataSource.getNoticeList(
clubId = clubId
).map {
it.toGetNotificationListResponseData()
}
}

override suspend fun getDetailNotice(id: Long): Flow<GetDetailNotificationResponseData> {
return notificationDataSource.getDetailNotice(id = id).map {
it.toDetailNotificationData()
}
}

override suspend fun patchNotice(
id: Long,
body: PatchModifyNotificationRequestData
): Flow<Unit> {
return notificationDataSource.patchNotice(
id = id,
body = PatchModifyNotificationRequest(
title = body.title,
content = body.content
)
)
}

override suspend fun deleteNotice(id: Long): Flow<Unit> {
return notificationDataSource.deleteNotice(
id = id
)
}
}
7 changes: 7 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 @@ -9,6 +9,7 @@ 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.NotificationAPI
import com.msg.gcms.data.remote.network.api.UserAPI
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -110,4 +111,10 @@ object NetworkModule {
fun provideAttendService(retrofit: Retrofit): AttendAPI {
return retrofit.create(AttendAPI::class.java)
}

@Provides
@Singleton
fun provideNotificationService(retrofit: Retrofit): NotificationAPI {
return retrofit.create(NotificationAPI::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.msg.gcms.data.remote.datasource.club_member.ClubMemberDataSource
import com.msg.gcms.data.remote.datasource.club_member.ClubMemberDataSourceImpl
import com.msg.gcms.data.remote.datasource.image.ImageDataSource
import com.msg.gcms.data.remote.datasource.image.ImageDataSourceImpl
import com.msg.gcms.data.remote.datasource.notification.NotificationDataSource
import com.msg.gcms.data.remote.datasource.notification.NotificationDataSourceImpl
import com.msg.gcms.data.remote.datasource.user.UserDataSource
import com.msg.gcms.data.remote.datasource.user.UserDataSourceImpl
import dagger.Binds
Expand Down Expand Up @@ -57,4 +59,9 @@ abstract class RemoteDataSourceModule {
abstract fun bindAttendDataSource(
attendDataSourceImpl: AttendDataSourceImpl
): AttendDataSource

@Binds
abstract fun bindNotificationDataSource(
notificationDataSourceImpl: NotificationDataSourceImpl
): NotificationDataSource
}
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
Expand Up @@ -6,13 +6,15 @@ 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.NotificationRepositoryImpl
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
import com.msg.gcms.domain.repository.ImageRepository
import com.msg.gcms.domain.repository.NotificationRepository
import com.msg.gcms.domain.repository.UserRepository
import dagger.Binds
import dagger.Module
Expand Down Expand Up @@ -57,4 +59,9 @@ abstract class RepositoryModule {
abstract fun bindAttendRepository(
attendRepositoryImpl: AttendRepositoryImpl
): AttendRepository

@Binds
abstract fun bindNotification(
notificationImpl: NotificationRepositoryImpl
): NotificationRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.msg.gcms.domain.data.notification

import java.time.LocalDateTime

data class GetDetailNotificationResponseData(
val title: String,
val content: String,
val username: String,
val userProfileImg: String,
val createdAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.msg.gcms.domain.data.notification

import java.time.LocalDateTime

data class GetNotificationListResponseData(
val notices: List<Notice>
) {
data class Notice(
val id: Long,
val title: String,
val username: String,
val createdAt: LocalDateTime
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.msg.gcms.domain.data.notification

data class PatchModifyNotificationRequestData(
val title: String,
val content: String
)
Loading