Skip to content

Commit

Permalink
#26 예비 밥상 조회 api 연결 중
Browse files Browse the repository at this point in the history
  • Loading branch information
seoyeonsw committed Nov 8, 2024
1 parent 0793bfb commit 32a9d43
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.hackathon.alddeul_babsang.data.datasource

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto

interface ReportDataSource {
suspend fun getReports(): BaseResponse<List<ResponseReportDto>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hackathon.alddeul_babsang.data.datasourceimpl

import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource
import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import com.hackathon.alddeul_babsang.data.service.ReportApiService
import javax.inject.Inject

class ReportDataSourceImpl @Inject constructor(
private val reportApiService: ReportApiService
) : ReportDataSource {
override suspend fun getReports(): BaseResponse<List<ResponseReportDto>> {
return reportApiService.getREPORTS()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hackathon.alddeul_babsang.data.dto.response

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

@Serializable
data class ResponseReportDto(
@SerialName("id") val id: Long,
@SerialName("name") val name: String,
@SerialName("category") val category: String,
@SerialName("address") val address: String,
@SerialName("contact") val contact: String,
@SerialName("imageUrl") val imageUrl: String? = null,
@SerialName("favorite") val isFavorite: Boolean
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hackathon.alddeul_babsang.data.mapper

import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity

class toLikesEntity {
}

fun ResponseReportDto.toLikesEntity() = ReportEntity(
id, imageUrl, name, category, address, contact, isFavorite
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hackathon.alddeul_babsang.data.repositoryimpl

import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import com.hackathon.alddeul_babsang.domain.repository.ReportRepository
import javax.inject.Inject

class ReportRepositoryImpl @Inject constructor(
private val reportDataSource: ReportDataSource
) : ReportRepository {
override suspend fun getReports(): Result<List<ResponseReportDto>> {
return runCatching {
reportDataSource.getReports().result ?: emptyList()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hackathon.alddeul_babsang.data.service

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import com.sopt.data.service.ApiKeyStorage.REPORTS
import retrofit2.http.GET

interface ReportApiService {
@GET("/$REPORTS")
suspend fun getREPORTS(): BaseResponse<List<ResponseReportDto>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hackathon.alddeul_babsang.domain.entity

data class BabsangEntity(
val id: Long,
val avatar: String? = null,
val name: String,
val codeName: String,
val address: String,
val phone: String,
val favorite: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hackathon.alddeul_babsang.domain.repository

import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto

interface ReportRepository {
suspend fun getReports(): Result<List<ResponseReportDto>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900
import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular
import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular
import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity
import com.hackathon.alddeul_babsang.presentation.profile.screen.LikeItem

@Composable
fun BabsangItem(
onClick: () -> Unit = {},
data: LikesEntity
data: ReportEntity
) {
var isFavorite by remember { mutableStateOf(data.favorite) }

Expand Down Expand Up @@ -165,7 +165,7 @@ fun ReplaceImage2(codeName: String, imageUrl: String?) {
fun BabsangListItemPreview() {
AlddeulBabsangTheme {
LikeItem(
data = LikesEntity(
data = ReportEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hackathon.alddeul_babsang.presentation.babsang.screen

import androidx.lifecycle.ViewModel
import com.hackathon.alddeul_babsang.domain.entity.BabsangRecommendEntity
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

Expand Down Expand Up @@ -46,7 +46,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() {
)
)
val mockBabsang = listOf(
LikesEntity(
ReportEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand All @@ -55,7 +55,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() {
phone = "02-210-0120",
favorite = true
),
LikesEntity(
ReportEntity(
id = 2,
avatar = null,
name = "송이네 일식",
Expand All @@ -64,7 +64,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() {
phone = "02-210-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 3,
avatar = null,
name = "송이네 한식",
Expand All @@ -73,7 +73,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() {
phone = "02-223-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 4,
avatar = null,
name = "송이네 중식",
Expand All @@ -82,7 +82,7 @@ class BabsangViewModel @Inject constructor() : ViewModel() {
phone = "02-223-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 4,
avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4",
name = "송이네 밥상",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900
import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular
import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular
import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity

@Composable
fun LikeItem(
onClick: () -> Unit = {},
data: LikesEntity
data: ReportEntity
) {
var isFavorite by remember { mutableStateOf(data.favorite) }

Expand Down Expand Up @@ -164,7 +164,7 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) {
fun LikeItemPreview() {
AlddeulBabsangTheme {
LikeItem(
data = LikesEntity(
data = ReportEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.hackathon.alddeul_babsang.presentation.profile.screen


import androidx.lifecycle.ViewModel
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class LikeViewModel @Inject constructor() : ViewModel() {
val mockLikes = listOf(
LikesEntity(
ReportEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand All @@ -18,7 +18,7 @@ class LikeViewModel @Inject constructor() : ViewModel() {
phone = "02-210-0120",
favorite = true
),
LikesEntity(
ReportEntity(
id = 2,
avatar = null,
name = "송이네 일식",
Expand All @@ -27,7 +27,7 @@ class LikeViewModel @Inject constructor() : ViewModel() {
phone = "02-210-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 3,
avatar = null,
name = "송이네 한식",
Expand All @@ -36,7 +36,7 @@ class LikeViewModel @Inject constructor() : ViewModel() {
phone = "02-223-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 4,
avatar = null,
name = "송이네 중식",
Expand All @@ -45,7 +45,7 @@ class LikeViewModel @Inject constructor() : ViewModel() {
phone = "02-223-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 4,
avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4",
name = "송이네 밥상",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import com.hackathon.alddeul_babsang.core_ui.theme.Orange900
import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular
import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular
import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity

@Composable
fun ReportItem(
onClick: () -> Unit = {},
data: LikesEntity
data: ReportEntity
) {
var isFavorite by remember { mutableStateOf(data.favorite) }

Expand Down Expand Up @@ -167,7 +167,7 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) {
fun BabsangItemPreview() {
AlddeulBabsangTheme {
ReportItem(
data = LikesEntity(
data = ReportEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.hackathon.alddeul_babsang.presentation.report.screen

import androidx.lifecycle.ViewModel
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.domain.entity.ReportEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ReportViewModel @Inject constructor() : ViewModel() {
val mockReportBabsang = listOf(
LikesEntity(
ReportEntity(
id = 1,
avatar = null,
name = "송이네 밥상",
Expand All @@ -17,7 +17,7 @@ class ReportViewModel @Inject constructor() : ViewModel() {
phone = "02-210-0120",
favorite = true
),
LikesEntity(
ReportEntity(
id = 2,
avatar = null,
name = "송이네 일식",
Expand All @@ -26,7 +26,7 @@ class ReportViewModel @Inject constructor() : ViewModel() {
phone = "02-210-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 3,
avatar = null,
name = "송이네 한식",
Expand All @@ -35,7 +35,7 @@ class ReportViewModel @Inject constructor() : ViewModel() {
phone = "02-223-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 4,
avatar = null,
name = "송이네 중식",
Expand All @@ -44,7 +44,7 @@ class ReportViewModel @Inject constructor() : ViewModel() {
phone = "02-223-0220",
favorite = true
),
LikesEntity(
ReportEntity(
id = 4,
avatar = "https://avatars.githubusercontent.com/u/166610834?s=400&u=568eacc2e4696d563a4fd732c148edba2196e4f6&v=4",
name = "송이네 밥상",
Expand Down

0 comments on commit 32a9d43

Please sign in to comment.