Skip to content

Commit

Permalink
Merge pull request #36 from DACOS-SOLUX-Hackathon-Team5/feature/#34-m…
Browse files Browse the repository at this point in the history
…ap-api

[Feature/#34] : 나머지 api 연결
  • Loading branch information
gaeulzzang authored Nov 8, 2024
2 parents 5a52731 + b23848e commit b2a53e7
Show file tree
Hide file tree
Showing 38 changed files with 293 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseBabsangDto

interface BabsangDataSource {
suspend fun getStores(): BaseResponse<List<ResponseBabsangDto>>
suspend fun postStores(
userId: Int
): BaseResponse<List<ResponseBabsangDto>>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hackathon.alddeul_babsang.data.datasource

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseGetReviewDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto
import okhttp3.MultipartBody
Expand All @@ -16,4 +17,9 @@ interface DetailDataSource {
suspend fun getReviews(
id: Long
): BaseResponse<ResponseGetReviewDto>

suspend fun postStoreDetail(
id: Int,
Userid: Int
): BaseResponse<ResponseDetailDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ interface MapDataSource {
suspend fun getMapStores(): BaseResponse<List<ResponseMapStoresDto>>
suspend fun postMapStoreDetail(
id: Long,
requestMapStoreDetailDto: RequestMapStoreDetailDto
userId: Long,
): BaseResponse<ResponseMapStoreDetailDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto

interface ProfileDataSource {
suspend fun getLikes(
userId: Long
userId: Int
): BaseResponse<ResponseLikesDto>

suspend fun postLike(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.hackathon.alddeul_babsang.data.datasource

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto
import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import okhttp3.MultipartBody
import okhttp3.RequestBody

interface ReportDataSource {
suspend fun postReports(
userId: Int
): BaseResponse<List<ResponseReportDto>>

suspend fun postReportWrite(
requestReportWriteDto: RequestReportWriteDto
data: Map<String, RequestBody>,
imageUrl: MultipartBody.Part? = null
): BaseResponse<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import javax.inject.Inject
class BabsangDataSourceImpl @Inject constructor(
private val babsangApiService: BabsangApiService
) : BabsangDataSource {
override suspend fun getStores(): BaseResponse<List<ResponseBabsangDto>> {
return babsangApiService.getStores()
override suspend fun postStores(
userId: Int
): BaseResponse<List<ResponseBabsangDto>> {
return babsangApiService.postStores(userId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hackathon.alddeul_babsang.data.datasourceimpl

import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource
import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseGetReviewDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto
import com.hackathon.alddeul_babsang.data.service.DetailApiService
Expand All @@ -24,4 +25,8 @@ class DetailDataSourceImpl @Inject constructor(
return detailApiService.getReviews(id)
}

override suspend fun postStoreDetail(id: Int, Userid: Int): BaseResponse<ResponseDetailDto> {
return detailApiService.postStoreDetail(id, Userid)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class MapDataSourceImpl @Inject constructor(

override suspend fun postMapStoreDetail(
id: Long,
requestMapStoreDetailDto: RequestMapStoreDetailDto
userId: Long,
): BaseResponse<ResponseMapStoreDetailDto> {
return mapApiService.postMapStoreDetail(id, requestMapStoreDetailDto)
return mapApiService.postMapStoreDetail(id, userId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProfileDataSourceImpl @Inject constructor(
private val profileApiService: ProfileApiService
) : ProfileDataSource {
override suspend fun getLikes(
userId: Long
userId: Int
): BaseResponse<ResponseLikesDto> {
return profileApiService.getLikes(userId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.hackathon.alddeul_babsang.data.dto.request.RequestReportDto
import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import com.hackathon.alddeul_babsang.data.service.ReportApiService
import okhttp3.MultipartBody
import okhttp3.RequestBody
import javax.inject.Inject

class ReportDataSourceImpl @Inject constructor(
Expand All @@ -15,6 +17,10 @@ class ReportDataSourceImpl @Inject constructor(
return reportApiService.postReports(userId)
}

override suspend fun postReportWrite(requestReportWriteDto: RequestReportWriteDto): BaseResponse<String> {
return reportApiService.postReportWrite(requestReportWriteDto)
}}
override suspend fun postReportWrite(
data: Map<String, RequestBody>,
imageUrl: MultipartBody.Part?
): BaseResponse<String> {
return reportApiService.postReportWrite(data, imageUrl)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package com.hackathon.alddeul_babsang.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.io.Serial

@Serializable
data class ResponseBabsangDto (
@SerialName("id") val id: Long,
@SerialName("storeId") val storeId: Long,
@SerialName("name") val name: String,
@SerialName("category") val category: String,
@SerialName("address") val address: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.hackathon.alddeul_babsang.data.dto.response

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

@Serializable
data class ResponseDetailDto(
@SerialName("storeInfo") val storeInfo: StoreInfo,
@SerialName("aveRating") val aveRating: Double,
@SerialName("menu1") val menu1: Menu,
@SerialName("menu2") val menu2: Menu
)

@Serializable
data class StoreInfo(
@SerialName("storeId") val storeId: 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 favorite: Boolean
)

@Serializable
data class Menu(
@SerialName("name") val name: String,
@SerialName("price") val price: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class ResponseLikesDto(
@SerialName("favoriteStoreDetailDtos") val favoriteRestaurants: List<FavoriteRestaurantDto>
@SerialName("favoriteStoreDetailDtos") val favoriteStoreDetailDtos: List<FavoriteRestaurantDto>
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import javax.inject.Inject
class BabsangRepositoryImpl @Inject constructor(
private val babsangDataSource: BabsangDataSource
) : BabsangRepository{
override suspend fun getStores(): Result<List<ResponseBabsangDto>> {
override suspend fun postStores(
userId: Int
): Result<List<ResponseBabsangDto>> {
return runCatching {
babsangDataSource.getStores().result ?: emptyList()
babsangDataSource.postStores(
userId = userId
).result ?: emptyList()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hackathon.alddeul_babsang.data.repositoryimpl

import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource
import com.hackathon.alddeul_babsang.data.dto.response.ResponseDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.Review
import com.hackathon.alddeul_babsang.domain.repository.DetailRepository
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand Down Expand Up @@ -46,4 +47,10 @@ class DetailRepositoryImpl @Inject constructor(
detailDataSource.getReviews(id).result?.reviewList ?: emptyList()
}
}

override suspend fun postStoreDetail(id: Int, userId: Int): Result<ResponseDetailDto?> {
return runCatching {
detailDataSource.postStoreDetail(id = id, Userid = userId).result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class MapRepositoryImpl @Inject constructor(
return runCatching {
mapDataSource.postMapStoreDetail(
id = id,
requestMapStoreDetailDto = RequestMapStoreDetailDto(
userId
)
userId = userId
).result
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class ProfileRepositoryImpl @Inject constructor(
private val profileDataSource: ProfileDataSource
) : ProfileRepository {
override suspend fun getLikes(
userId: Long,
userId: Int,
): Result<List<FavoriteRestaurantDto>> {
return runCatching {
profileDataSource.getLikes(
userId = userId
).result?.favoriteRestaurants ?: emptyList()
).result?.favoriteStoreDetailDtos ?: emptyList()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import com.hackathon.alddeul_babsang.data.datasource.ReportDataSource
import com.hackathon.alddeul_babsang.data.dto.request.RequestReportWriteDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReportDto
import com.hackathon.alddeul_babsang.domain.repository.ReportRepository
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File
import javax.inject.Inject

class ReportRepositoryImpl @Inject constructor(
Expand All @@ -28,21 +33,30 @@ class ReportRepositoryImpl @Inject constructor(
menuPrice1: Int,
menuName2: String,
menuPrice2: Int,
imageUrl: String
imageUrl: File
): Result<String> {
return runCatching {
val dataMap = mapOf(
"name" to name.toRequestBody("text/plain".toMediaTypeOrNull()),
"category" to category.toRequestBody("text/plain".toMediaTypeOrNull()),
"address" to address.toRequestBody("text/plain".toMediaTypeOrNull()),
"contact" to contact.toRequestBody("text/plain".toMediaTypeOrNull()),
"menuName1" to menuName1.toRequestBody("text/plain".toMediaTypeOrNull()),
"menuPrice1" to menuPrice1.toString().toRequestBody("text/plain".toMediaTypeOrNull()),
"menuName2" to menuName2.toRequestBody("text/plain".toMediaTypeOrNull()),
"menuPrice2" to menuPrice2.toString().toRequestBody("text/plain".toMediaTypeOrNull())
)

// 이미지 파일 파트 생성
val filePart = imageUrl?.let {
val requestBody = it.asRequestBody("image/jpeg".toMediaTypeOrNull())
MultipartBody.Part.createFormData("imageUrl", it.name, requestBody)
}

reportDataSource.postReportWrite(
requestReportWriteDto = RequestReportWriteDto(
name = name,
category = category,
address = address,
contact = contact,
menuName1 = menuName1,
menuPrice1 = menuPrice1,
menuName2 = menuName2,
menuPrice2 = menuPrice2
)
).result ?: ""
data = dataMap,
imageUrl = filePart
).message
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package com.hackathon.alddeul_babsang.data.service
import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseBabsangDto
import com.sopt.data.service.ApiKeyStorage.STORES
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface BabsangApiService {
@GET("/$STORES")
suspend fun getStores(): BaseResponse<List<ResponseBabsangDto>>
@POST("/$STORES/")
suspend fun postStores(
@Query("userId") userId: Int
): BaseResponse<List<ResponseBabsangDto>>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hackathon.alddeul_babsang.data.service

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseGetReviewDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto
import com.sopt.data.service.ApiKeyStorage.ID
Expand All @@ -16,6 +17,7 @@ import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.PartMap
import retrofit2.http.Path
import retrofit2.http.Query

interface DetailApiService {
@Multipart
Expand All @@ -31,4 +33,10 @@ interface DetailApiService {
@Path("id") id: Long
): BaseResponse<ResponseGetReviewDto>

@POST("/$STORES/{$ID}")
suspend fun postStoreDetail(
@Path("id") id: Int,
@Query("Userid") Userid: Int
): BaseResponse<ResponseDetailDto>

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface MapApiService {
@GET("/$MAP/$STORES")
Expand All @@ -19,6 +20,6 @@ interface MapApiService {
@POST("/$MAP/$STORES/{$ID}")
suspend fun postMapStoreDetail(
@Path("id") id: Long,
@Body requestMapStoreDetailDto: RequestMapStoreDetailDto
@Query("userId") userId: Long,
): BaseResponse<ResponseMapStoreDetailDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import retrofit2.http.POST
import retrofit2.http.Path

interface ProfileApiService {
@GET("/$FAVORITES/{$USER_ID}}")
@GET("/$FAVORITES/{$USER_ID}")
suspend fun getLikes(
@Path("userId") userId: Long,
@Path("userId") userId: Int,
): BaseResponse<ResponseLikesDto>

@POST("/$FAVORITES")
Expand Down
Loading

0 comments on commit b2a53e7

Please sign in to comment.