Skip to content

Commit

Permalink
[MERGE] #59 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#59] ์บ˜๋ฆฐ๋”๋ทฐ / ์›”๊ฐ„ ์บ˜๋ฆฐ๋” ์„œ๋ฒ„ํ†ต์‹  ๋กœ์ง ๊ตฌํ˜„
  • Loading branch information
boiledEgg-s authored Jul 17, 2024
2 parents 3c0a58c + 7d4ec19 commit 923dc21
Show file tree
Hide file tree
Showing 51 changed files with 1,082 additions and 474 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/terning/point/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.terning.data.datasource.SearchDataSource
import com.terning.data.datasource.TokenReissueDataSource
import com.terning.data.datasourceimpl.AuthDataSourceImpl
import com.terning.data.datasourceimpl.SearchDataSourceImpl
import com.terning.data.datasource.CalendarDataSource
import com.terning.data.datasourceimpl.CalendarDataSourceImpl
import com.terning.data.datasourceimpl.TokenReissueDataSourceImpl
import dagger.Binds
import dagger.Module
Expand All @@ -16,6 +18,10 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
abstract class DataSourceModule {

@Binds
@Singleton
abstract fun bindCalendarDataSource(calendarDataSourceImpl: CalendarDataSourceImpl): CalendarDataSource

@Binds
@Singleton
abstract fun bindAuthDataSource(authDataSourceImpl: AuthDataSourceImpl): AuthDataSource
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/terning/point/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.terning.point.di

import com.terning.data.repositoryimpl.AuthRepositoryImpl
import com.terning.data.repositoryimpl.CalendarRepositoryImpl
import com.terning.data.repositoryimpl.SearchViewsRepositoryImpl
import com.terning.data.repositoryimpl.TokenReissueRepositoryImpl
import com.terning.data.repositoryimpl.TokenRepositoryImpl
import com.terning.domain.repository.AuthRepository
import com.terning.domain.repository.CalendarRepository
import com.terning.domain.repository.SearchRepository
import com.terning.domain.repository.TokenReissueRepository
import com.terning.domain.repository.TokenRepository
Expand All @@ -18,6 +20,10 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {

@Binds
@Singleton
abstract fun calendarRepository(calendarRepositoryImpl: CalendarRepositoryImpl): CalendarRepository

@Binds
@Singleton
abstract fun bindAuthRepository(authRepositoryImpl: AuthRepositoryImpl): AuthRepository
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/terning/point/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.terning.point.di

import com.terning.data.service.AuthService
import com.terning.data.service.CalendarService
import com.terning.data.service.SearchService
import com.terning.data.service.TokenReissueService
import com.terning.point.di.qualifier.JWT
Expand All @@ -26,6 +27,12 @@ object ServiceModule {
fun provideSearchService(@JWT retrofit: Retrofit): SearchService =
retrofit.create(SearchService::class.java)

@Provides
@Singleton
fun provideCalendarService(@JWT retrofit: Retrofit): CalendarService =
retrofit.create(CalendarService::class.java)


@Provides
@Singleton
fun provideTokenReissueService(@REISSUE retrofit: Retrofit): TokenReissueService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.extension.getStringAsTitle
import com.terning.core.extension.noRippleClickable
import java.time.LocalDate
import java.time.YearMonth

@Composable
fun CalendarTopAppBar(
modifier: Modifier = Modifier,
date: LocalDate,
date: YearMonth,
isWeekExpanded: Boolean,
isListExpanded: Boolean,
onListButtonClicked: () -> Unit,
Expand Down Expand Up @@ -58,7 +59,7 @@ fun CalendarTopAppBar(
)
}
Text(
text = date.getStringAsTitle(),
text = LocalDate.of(date.year, date.month, 1).getStringAsTitle(),
style = TerningTheme.typography.title2,
color = Black,
modifier = Modifier.padding(horizontal = 8.dp)
Expand Down Expand Up @@ -97,7 +98,7 @@ fun CalendarTopAppBar(
fun CalendarTopBarPreview() {
TerningPointTheme {
CalendarTopAppBar(
date = LocalDate.now(),
date = YearMonth.now(),
isListExpanded = false,
isWeekExpanded = false
,
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/com/terning/core/extension/LocalDateExt.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.terning.core.extension

import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.format.TextStyle
import java.util.Locale

Expand All @@ -10,6 +11,11 @@ fun LocalDate.getStringAsTitle(): String =
fun LocalDate.getDateStringInKorean(): String =
"${monthValue}์›” ${dayOfMonth}์ผ ${dayOfWeek.getDisplayName(TextStyle.FULL, Locale.KOREAN)}"

fun LocalDate.getDateAsMapString(): String {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
return format(formatter)
}

fun LocalDate.getWeekIndexContainingSelectedDate(inDays: Int): Int = (inDays + dayOfMonth - 1) / 7

fun LocalDate.isToday(): Boolean = this == LocalDate.now()
3 changes: 3 additions & 0 deletions core/src/main/java/com/terning/core/extension/Map.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.terning.core.extension

fun<T> List<T>?.isListNotEmpty():Boolean = this.orEmpty().isNotEmpty()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.terning.data.datasource

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.CalendarDayListRequestDto
import com.terning.data.dto.request.CalendarMonthListRequestDto
import com.terning.data.dto.request.CalendarMonthRequestDto
import com.terning.data.dto.response.CalendarDayListResponseDto
import com.terning.data.dto.response.CalendarMonthListResponseDto
import com.terning.data.dto.response.CalendarMonthResponseDto

interface CalendarDataSource {
suspend fun getCalendarMonth(request: CalendarMonthRequestDto): BaseResponse<List<CalendarMonthResponseDto>>
suspend fun getCalendarMonthList(request: CalendarMonthListRequestDto): BaseResponse<List<CalendarMonthListResponseDto>>
suspend fun getCalendarDayList(request: CalendarDayListRequestDto): BaseResponse<List<CalendarDayListResponseDto>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.terning.data.datasourceimpl

import com.terning.data.datasource.CalendarDataSource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.CalendarDayListRequestDto
import com.terning.data.dto.request.CalendarMonthListRequestDto
import com.terning.data.dto.request.CalendarMonthRequestDto
import com.terning.data.dto.response.CalendarDayListResponseDto
import com.terning.data.dto.response.CalendarMonthListResponseDto
import com.terning.data.dto.response.CalendarMonthResponseDto
import com.terning.data.service.CalendarService
import javax.inject.Inject

class CalendarDataSourceImpl @Inject constructor(
private val calendarService: CalendarService
) : CalendarDataSource {
override suspend fun getCalendarMonth(request: CalendarMonthRequestDto): BaseResponse<List<CalendarMonthResponseDto>> =
calendarService.getCalendarScrapMonth(request.year, request.month)

override suspend fun getCalendarMonthList(request: CalendarMonthListRequestDto): BaseResponse<List<CalendarMonthListResponseDto>> =
calendarService.getCalendarScrapMonthList(request.year, request.month)

override suspend fun getCalendarDayList(request: CalendarDayListRequestDto): BaseResponse<List<CalendarDayListResponseDto>> =
calendarService.getCalendarScrapDayList(request.date)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.terning.data.dto.request

data class CalendarDayListRequestDto(
val date: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.terning.data.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CalendarMonthListRequestDto(
@SerialName("deadline")
val year: Int,
@SerialName("scraps")
val month: Int
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.terning.data.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CalendarMonthRequestDto(
@SerialName("year")
val year: Int,
@SerialName("month")
val month: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.CalendarScrapDetailModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CalendarDayListResponseDto(
@SerialName("scrapId")
val scrapId: Long,
@SerialName("internshipAnnouncementId")
val internshipAnnouncementId: Long,
@SerialName("title")
val title: String,
@SerialName("dDay")
val dDay: String,
@SerialName("workingPeriod")
val workingPeriod: String,
@SerialName("color")
val color: String,
@SerialName("companyImage")
val companyImage: String,
@SerialName("startYear")
val startYear: Int,
@SerialName("startMonth")
val startMonth: Int
){
fun toScrapDetailModelList(): CalendarScrapDetailModel =
CalendarScrapDetailModel(
scrapId = scrapId,
internshipAnnouncementId = internshipAnnouncementId,
title = title,
dDay = dDay,
workingPeriod = workingPeriod,
color = color,
companyImage = companyImage,
startYear = startYear,
startMonth = startMonth,
deadLine = ""
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.CalendarScrapDetailModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CalendarMonthListResponseDto(
@SerialName("deadline")
val deadline: String,
@SerialName("scraps")
val scraps: List<Scrap>
) {
@Serializable
data class Scrap(
@SerialName("scrapId")
val scrapId: Long,
@SerialName("internshipAnnouncementId")
val internshipAnnouncementId: Long,
@SerialName("title")
val title: String,
@SerialName("dDay")
val dDay: String,
@SerialName("workingPeriod")
val workingPeriod: String,
@SerialName("color")
val color: String,
@SerialName("companyImage")
val companyImage: String,
@SerialName("startYear")
val startYear: Int,
@SerialName("startMonth")
val startMonth: Int
)

fun toScrapDetailModelList(): List<CalendarScrapDetailModel> = scraps.map { scrap ->
CalendarScrapDetailModel(
scrapId = scrap.scrapId,
internshipAnnouncementId = scrap.internshipAnnouncementId,
title = scrap.title,
dDay = scrap.dDay,
workingPeriod = scrap.workingPeriod,
color = scrap.color,
companyImage = scrap.companyImage,
startYear = scrap.startYear,
startMonth = scrap.startMonth,
deadLine = deadline
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.CalendarScrapModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CalendarMonthResponseDto(
@SerialName("deadline")
val deadline: String,
@SerialName("scraps")
val scraps: List<Scrap>
) {
@Serializable
data class Scrap(
@SerialName("scrapId")
val scrapId: Long,
@SerialName("title")
val title: String,
@SerialName("color")
val color: String
)

fun toScrapModelList(): List<CalendarScrapModel> = scraps.map { scrap ->
CalendarScrapModel(
scrapId = scrap.scrapId,
title = scrap.title,
color = scrap.color,
deadLine = deadline,
isScrapped = true
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.terning.data.repositoryimpl

import com.terning.data.datasource.CalendarDataSource
import com.terning.data.dto.request.CalendarDayListRequestDto
import com.terning.data.dto.request.CalendarMonthListRequestDto
import com.terning.data.dto.request.CalendarMonthRequestDto
import com.terning.domain.entity.response.CalendarScrapDetailModel
import com.terning.domain.entity.response.CalendarScrapModel
import com.terning.domain.repository.CalendarRepository
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import javax.inject.Inject

class CalendarRepositoryImpl @Inject constructor(
private val calendarDataSource: CalendarDataSource
) : CalendarRepository {
override suspend fun getScrapMonth(
year: Int,
month: Int
): Result<Map<String, List<CalendarScrapModel>>> =
runCatching {
val result = calendarDataSource.getCalendarMonth(
request = CalendarMonthRequestDto(
year = year,
month = month
)
).result

val scrapModelMapByDeadLine = result.flatMap { dto ->
dto.toScrapModelList()
}.groupBy { it.deadLine }

scrapModelMapByDeadLine
}

override suspend fun getScrapMonthList(
year: Int,
month: Int
): Result<Map<String, List<CalendarScrapDetailModel>>> =
runCatching {
val result = calendarDataSource.getCalendarMonthList(
request = CalendarMonthListRequestDto(
year = year,
month = month
)
).result

val scrapModelMapByDeadLine = result.flatMap { dto ->
dto.toScrapDetailModelList()
}.groupBy { it.deadLine }

scrapModelMapByDeadLine
}

override suspend fun getScrapDayList(
currentDate: LocalDate
): Result<List<CalendarScrapDetailModel>> =
runCatching {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val request = CalendarDayListRequestDto(currentDate.format(formatter))
val response = calendarDataSource.getCalendarDayList(request)
val scrapModelList = response.result.map { scrap ->
scrap.toScrapDetailModelList()
}
scrapModelList
}
}
Loading

0 comments on commit 923dc21

Please sign in to comment.