Skip to content

Commit

Permalink
Merge pull request #114 from Team-Notitime/feat/announcement/113-read…
Browse files Browse the repository at this point in the history
…-api

Feat/announcement/113 read api
  • Loading branch information
easyhz authored Aug 21, 2024
2 parents 946e9fd + b3a11eb commit c610798
Show file tree
Hide file tree
Showing 27 changed files with 216 additions and 136 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
LOCAL_PROPERTIES_CONTENTS: ${{ secrets.LOCAL_PROPERTIES_CONTENTS }}
KEYSTORE_PROPERTIES_CONTENTS: ${{ secrets.KEYSTORE_PROPERTIES_CONTENTS }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}

steps:
- uses: actions/checkout@v4
Expand All @@ -38,6 +39,9 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Create google-services.json
run: echo "$GOOGLE_SERVICES_JSON" > app/google-services.json

- name: Decode and create keystore.jks
run: echo $SIGNING_KEY | base64 --decode > app/keystore.jks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal fun NavGraphBuilder.announcementGraph(
composable<AnnouncementDetail> {
val args = it.toRoute<AnnouncementDetail>()
AnnouncementDetailScreen(
organizationId = args.organizationId,
id = args.id,
title = args.title,
navigateToUp = navController::navigateUp
Expand Down Expand Up @@ -136,8 +137,9 @@ internal fun NavGraphBuilder.announcementGraph(
param = args.announcementParam.decode(),
snackBarHostState = snackBarHostState,
navigateToUp = navController::navigateUp,
navigateToSuccess = { id, title ->
navigateToSuccess = { organizationId, id, title ->
navController.navigateToSuccess(
organizationId,
id,
title,
navOptions
Expand All @@ -154,20 +156,22 @@ internal fun NavGraphBuilder.announcementGraph(
}
}
SuccessScreen(
organizationId = args.organizationId,
id = args.announcementId,
title = args.title,
navigateToHome = { navController.navigateToHome(navOptions) },
navigateToAnnouncementDetail = { id, title -> navController.navigateToAnnouncementDetail(id, title, navOptions)}
navigateToAnnouncementDetail = { organizationId, id, title -> navController.navigateToAnnouncementDetail(organizationId, id, title, navOptions)}
)
}
}

internal fun NavController.navigateToAnnouncementDetail(
organizationId: Int,
id: Int,
title: String,
navOptions: NavOptions? = null
) {
navigate(route = AnnouncementDetail(id, title), navOptions)
navigate(route = AnnouncementDetail(organizationId = organizationId, id, title), navOptions)
}

internal fun NavController.navigateToAnnouncementNofficeSelection() {
Expand Down Expand Up @@ -231,9 +235,10 @@ internal fun NavController.navigateToPromotion(param: AnnouncementParam) {
}

internal fun NavController.navigateToSuccess(
organizationId: Int,
id: Int,
title: String,
navOptions: NavOptions? = null
) {
navigate(route = AnnouncementSuccess(id, title), navOptions)
navigate(route = AnnouncementSuccess(organizationId, id, title), navOptions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class AnnouncementDetail(
val organizationId: Int,
val id: Int,
val title: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class AnnouncementSuccess(
val organizationId: Int,
val announcementId: Int,
val title: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object DateFormat {
val value: String
) {
FULL("yyyy.MM.dd(E) HH:mm"),
DATE_TIME_TEXT("yyyy.MM.dd HH:mm"),
DATE_TEXT("yyyy년 MM월 dd일"),
DATE_DASH("yyyy-MM-dd"),
CUSTOM_REMIND("MM월 dd일 E a h:mm"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.easyhz.noffice.core.design_system.component.card
import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -30,7 +31,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.easyhz.noffice.core.design_system.R
import com.easyhz.noffice.core.design_system.component.image.AnnouncementImage
import com.easyhz.noffice.core.design_system.extension.noRippleClickable
import com.easyhz.noffice.core.design_system.extension.screenHorizonPadding
import com.easyhz.noffice.core.design_system.theme.CardExceptionSubTitle
import com.easyhz.noffice.core.design_system.theme.CardExceptionTitle
Expand All @@ -52,12 +52,12 @@ fun ItemCard(
Column(modifier = modifier
.width(283.dp)
.height(296.dp)
.clickable { onClick() }
.clip(RoundedCornerShape(16.dp))
.border(1.dp, color = Grey200, RoundedCornerShape(16.dp))
.noRippleClickable { onClick() }
) {
AnnouncementImage(
modifier = Modifier.fillMaxWidth(),
modifier = Modifier.fillMaxWidth().height(160.dp),
imageUrl = imageUrl
)
Box(modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easyhz.noffice.data.announcement.mapper.announcement

import com.easyhz.noffice.core.common.util.DateFormat
import com.easyhz.noffice.core.common.util.DateFormat.formatDateTime
import com.easyhz.noffice.core.model.announcement.Announcement
import com.easyhz.noffice.core.model.announcement.param.AnnouncementParam
import com.easyhz.noffice.core.model.organization.announcement.OrganizationAnnouncement
Expand All @@ -11,7 +12,7 @@ import com.easyhz.noffice.core.network.model.response.announcement.AnnouncementR
fun AnnouncementResponse.toModel(): Announcement = Announcement(
announcementId = this.announcementId,
content = this.content,
createdAt = this.createdAt,
createdAt = formatDateTime(this.createdAt, DateFormat.PATTERN.DATE_TIME_TEXT),
endAt = DateFormat.formatDateTimeNullable(this.endAt),
memberId = this.memberId,
noticeAt = this.noticeAt,
Expand All @@ -38,15 +39,15 @@ fun AnnouncementParam.toRequest(): AnnouncementRequest = AnnouncementRequest(
tasks = this.tasks?.map { Task(content = it.content) }
)

fun AnnouncementResponse.toDetail(): OrganizationAnnouncement = OrganizationAnnouncement(
fun AnnouncementResponse.toDetail(pattern: DateFormat.PATTERN): OrganizationAnnouncement = OrganizationAnnouncement(
announcementId = this.announcementId,
title = this.title,
content = this.content,
profileImage = this.profileImageUrl,
place = this.placeLinkName,
placeUrl = this.placeLinkUrl,
taskSize = 0, // FIXME
createdAt = DateFormat.formatDateTime(this.createdAt),
endAt = DateFormat.formatDateTimeNullable(this.endAt, pattern = DateFormat.PATTERN.DAY),
updatedAt = DateFormat.formatDateTime(this.createdAt)
createdAt = formatDateTime(this.createdAt),
endAt = DateFormat.formatDateTimeNullable(this.endAt, pattern = pattern),
updatedAt = formatDateTime(this.createdAt)
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OrganizationAnnouncementPagingSource(


companion object {
const val PAGE_SIZE = 10
private const val START_PAGE = 1
const val PAGE_SIZE = 1
private const val START_PAGE = 0
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easyhz.noffice.data.organization.repository.organization

import androidx.paging.PagingData
import com.easyhz.noffice.core.common.util.DateFormat
import com.easyhz.noffice.core.model.organization.Organization
import com.easyhz.noffice.core.model.organization.OrganizationInformation
import com.easyhz.noffice.core.model.organization.announcement.OrganizationAnnouncement
Expand All @@ -12,7 +13,7 @@ interface OrganizationRepository {
suspend fun fetchOrganizations(): Flow<PagingData<Organization>>
suspend fun createOrganization(param: OrganizationCreationParam): Result<Organization>
suspend fun fetchOrganizationInfo(organizationId: Int): Result<OrganizationInformation>
suspend fun fetchAnnouncementsByOrganization(organizationId: Int): Flow<PagingData<OrganizationAnnouncement>>
suspend fun fetchAnnouncementsByOrganization(organizationId: Int, endAtDatePattern: DateFormat.PATTERN): Flow<PagingData<OrganizationAnnouncement>>
suspend fun updateOrganizationCategory(organizationId: Int, category: List<Int>): Result<Category>
suspend fun joinOrganization(organizationId: Int): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.paging.PagingData
import androidx.paging.map
import com.easyhz.noffice.core.common.di.Dispatcher
import com.easyhz.noffice.core.common.di.NofficeDispatchers
import com.easyhz.noffice.core.common.util.DateFormat
import com.easyhz.noffice.core.model.organization.Organization
import com.easyhz.noffice.core.model.organization.OrganizationInformation
import com.easyhz.noffice.core.model.organization.announcement.OrganizationAnnouncement
Expand Down Expand Up @@ -61,6 +62,7 @@ class OrganizationRepositoryImpl @Inject constructor(

override suspend fun fetchAnnouncementsByOrganization(
organizationId: Int,
endAtDatePattern: DateFormat.PATTERN,
): Flow<PagingData<OrganizationAnnouncement>> =
Pager(
config = PagingConfig(
Expand All @@ -75,7 +77,7 @@ class OrganizationRepositoryImpl @Inject constructor(
}
).flow.map { pagingData ->
pagingData.map { response ->
response.toDetail()
response.toDetail(endAtDatePattern)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easyhz.noffice.domain.organization.usecase.announcement

import androidx.paging.PagingData
import com.easyhz.noffice.core.common.util.DateFormat
import com.easyhz.noffice.core.model.organization.announcement.OrganizationAnnouncement
import com.easyhz.noffice.data.organization.repository.organization.OrganizationRepository
import kotlinx.coroutines.flow.Flow
Expand All @@ -9,7 +10,7 @@ import javax.inject.Inject
class FetchAnnouncementsByOrganizationUseCase @Inject constructor(
private val organizationRepository: OrganizationRepository
) {
suspend operator fun invoke(organizationId: Int): Flow<PagingData<OrganizationAnnouncement>> {
return organizationRepository.fetchAnnouncementsByOrganization(organizationId)
suspend operator fun invoke(organizationId: Int, pattern: DateFormat.PATTERN): Flow<PagingData<OrganizationAnnouncement>> {
return organizationRepository.fetchAnnouncementsByOrganization(organizationId, pattern)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.easyhz.noffice.domain.organization.usecase.organization

import com.easyhz.noffice.core.common.base.BaseUseCase
import com.easyhz.noffice.core.common.di.Dispatcher
import com.easyhz.noffice.core.common.di.NofficeDispatchers
import com.easyhz.noffice.core.model.organization.OrganizationInformation
import com.easyhz.noffice.core.model.organization.category.Category
import com.easyhz.noffice.data.organization.repository.category.CategoryRepository
import com.easyhz.noffice.data.organization.repository.organization.OrganizationRepository
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.withContext
import javax.inject.Inject

class FetchOrganizationUseCase @Inject constructor(
@Dispatcher(NofficeDispatchers.IO) private val dispatcher: CoroutineDispatcher,
private val categoryRepository: CategoryRepository,
private val organizationRepository: OrganizationRepository
):BaseUseCase<Int, OrganizationInformation>() {
override suspend fun invoke(param: Int): Result<OrganizationInformation> = withContext(dispatcher) {
runCatching {
val (categoriesResult, organizationInfoResult) = coroutineScope {
val categoriesDeferred = async { fetchCategories() }
val organizationInfoDeferred = async { fetchOrganizationInfo(param) }

categoriesDeferred.await() to organizationInfoDeferred.await()
}

val categoryList = categoriesResult.getOrThrow()
val info = organizationInfoResult.getOrThrow()

info.copy(category = categoryList.filter { it.id == info.id })
}
}


private suspend fun fetchCategories(): Result<List<Category>> {
return categoryRepository.fetchCategories()
}

private suspend fun fetchOrganizationInfo(id: Int): Result<OrganizationInformation> {
return organizationRepository.fetchOrganizationInfo(id)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ internal fun LazyListScope.detailTitle(
overflow = TextOverflow.Ellipsis
)
}
Spacer(modifier = Modifier.height(8.dp))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ sealed class PromotionSideEffect: UiSideEffect() {
data object HidePromotionBottomSheet: PromotionSideEffect()
data class ScrollToItem(val index: Int): PromotionSideEffect()
data class ShowSnackBar(@StringRes val stringId: Int): PromotionSideEffect()
data class NavigateToSuccess(val id: Int, val title: String): PromotionSideEffect()
data class NavigateToSuccess(val organizationId: Int, val id: Int, val title: String): PromotionSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.easyhz.noffice.feature.announcement.contract.detail
import com.easyhz.noffice.core.common.base.UiIntent

sealed class DetailIntent: UiIntent() {
data class InitScreen(val id: Int, val title: String): DetailIntent()
data class InitScreen(val organizationId: Int, val id: Int, val title: String): DetailIntent()
data object NavigateToUp: DetailIntent()
data object ClickPlace: DetailIntent()
data object HideBottomSheet: DetailIntent()
Expand Down
Loading

0 comments on commit c610798

Please sign in to comment.