Skip to content

Commit

Permalink
Merge pull request #29 from DACOS-SOLUX-Hackathon-Team5/feature/#28-l…
Browse files Browse the repository at this point in the history
…ike-api

[Feature/#28] : 좋아요, 리뷰, 제보, 착한 업소 api 연결
  • Loading branch information
seoyeonsw authored Nov 8, 2024
2 parents fbf77b7 + b36351b commit fff4af6
Show file tree
Hide file tree
Showing 24 changed files with 456 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.hackathon.alddeul_babsang.app.di

import com.hackathon.alddeul_babsang.data.datasource.BabsangDataSource
import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource
import com.hackathon.alddeul_babsang.data.datasource.ExampleDataSource
import com.hackathon.alddeul_babsang.data.datasource.ProfileDataSource
import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource
import com.hackathon.alddeul_babsang.data.datasourceimpl.BabsangDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.DetailDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.ExampleDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.ProfileDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.UserPreferencesDataSourceImpl
import dagger.Binds
import dagger.Module
Expand All @@ -27,4 +31,12 @@ abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindBabsangDataSource(babsangDataSourceImpl: BabsangDataSourceImpl): BabsangDataSource

@Binds
@Singleton
abstract fun bindProfileDataSource(profileDataSourceImpl: ProfileDataSourceImpl): ProfileDataSource

@Binds
@Singleton
abstract fun bindDetailDataSource(detailDataSourceImpl: DetailDataSourceImpl): DetailDataSource
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.hackathon.alddeul_babsang.app.di

import com.hackathon.alddeul_babsang.data.repositoryimpl.BabsangRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.DetailRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.ExampleRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.ProfileRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.UserPreferencesRepositoryImpl
import com.hackathon.alddeul_babsang.domain.repository.BabsangRepository
import com.hackathon.alddeul_babsang.domain.repository.DetailRepository
import com.hackathon.alddeul_babsang.domain.repository.ExampleRepository
import com.hackathon.alddeul_babsang.domain.repository.ProfileRepository
import com.hackathon.alddeul_babsang.domain.repository.UserPreferencesRepository
import dagger.Binds
import dagger.Module
Expand All @@ -27,4 +31,12 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindBabsangRepository(babsangRepositoryImpl: BabsangRepositoryImpl): BabsangRepository

@Binds
@Singleton
abstract fun bindProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl): ProfileRepository

@Binds
@Singleton
abstract fun bindDetailRepository(detailRepositoryImpl: DetailRepositoryImpl): DetailRepository
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hackathon.alddeul_babsang.app.di

import com.hackathon.alddeul_babsang.data.service.BabsangApiService
import com.hackathon.alddeul_babsang.data.service.DetailApiService
import com.hackathon.alddeul_babsang.data.service.ProfileApiService
import com.sopt.data.service.ExampleApiService
import dagger.Module
import dagger.Provides
Expand All @@ -24,4 +26,16 @@ object ServiceModule {
fun provideBabsangService(
@AlddeulRetrofit retrofit: Retrofit
): BabsangApiService = retrofit.create(BabsangApiService::class.java)

@Provides
@Singleton
fun provideProfileService(
@AlddeulRetrofit retrofit: Retrofit
): ProfileApiService = retrofit.create(ProfileApiService::class.java)

@Provides
@Singleton
fun provideDetailService(
@AlddeulRetrofit retrofit: Retrofit
): DetailApiService = retrofit.create(DetailApiService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hackathon.alddeul_babsang.data.datasource

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto
import okhttp3.MultipartBody
import okhttp3.RequestBody

interface DetailDataSource {
suspend fun postReview(
storeId: Long,
data: Map<String, RequestBody>, // JSON 데이터를 포함하는 Map
reviewImage: MultipartBody.Part? = null // 이미지 파일
): BaseResponse<ResponseReviewDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hackathon.alddeul_babsang.data.datasource

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto

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

suspend fun postLike(
requestLikesDto: RequestLikesDto
): BaseResponse<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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.ResponseReviewDto
import com.hackathon.alddeul_babsang.data.service.DetailApiService
import okhttp3.MultipartBody
import okhttp3.RequestBody
import javax.inject.Inject

class DetailDataSourceImpl @Inject constructor(
private val detailApiService: DetailApiService
) : DetailDataSource {
override suspend fun postReview(
storeId: Long,
data: Map<String, RequestBody>,
reviewImage: MultipartBody.Part?
): BaseResponse<ResponseReviewDto> {
return detailApiService.postReview(storeId, data, reviewImage)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hackathon.alddeul_babsang.data.datasourceimpl

import com.hackathon.alddeul_babsang.data.datasource.ProfileDataSource
import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto
import com.hackathon.alddeul_babsang.data.service.ProfileApiService
import javax.inject.Inject

class ProfileDataSourceImpl @Inject constructor(
private val profileApiService: ProfileApiService
) : ProfileDataSource {
override suspend fun getLikes(
userId: Long
): BaseResponse<ResponseLikesDto> {
return profileApiService.getLikes(userId)
}

override suspend fun postLike(requestLikesDto: RequestLikesDto): BaseResponse<String> {
return profileApiService.postLike(requestLikesDto)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hackathon.alddeul_babsang.data.dto.request

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

@Serializable
data class RequestLikesDto (
@SerialName("userId") val userId: Long,
@SerialName("storeId") val storeId: Long
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hackathon.alddeul_babsang.data.dto.response

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

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

@Serializable
data class FavoriteRestaurantDto(
@SerialName("restaurantId") val restaurantId: Long,
@SerialName("name") val name: String,
@SerialName("category") val category: String,
@SerialName("address") val address: String,
@SerialName("contact") val contact: String,
@SerialName("restaurantImageUrl") val restaurantImageUrl: String? = null,
@SerialName("favorite") val favorite: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hackathon.alddeul_babsang.data.dto.response

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

@Serializable
data class ResponseReviewDto (
@SerialName("storeId") val storeId: Long,
@SerialName("userId") val userId: Long,
@SerialName("message") val message: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.hackathon.alddeul_babsang.data.repositoryimpl

import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource
import com.hackathon.alddeul_babsang.domain.repository.DetailRepository
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import java.io.File
import javax.inject.Inject

class DetailRepositoryImpl @Inject constructor(
private val detailDataSource: DetailDataSource
) : DetailRepository {
override suspend fun postReview(
storeId: Long,
userId: Long,
rating: Double,
content: String,
reviewImage: File
): Result<String> {
return runCatching {
val dataMap = mapOf(
"userId" to userId.toString().toRequestBody("text/plain".toMediaTypeOrNull()),
"rating" to rating.toString().toRequestBody("text/plain".toMediaTypeOrNull()),
"content" to content.toRequestBody("text/plain".toMediaTypeOrNull())
)

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

detailDataSource.postReview(
storeId = storeId,
data = dataMap,
reviewImage = filePart
).message
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hackathon.alddeul_babsang.data.repositoryimpl

import com.hackathon.alddeul_babsang.data.datasource.ProfileDataSource
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto
import com.hackathon.alddeul_babsang.data.dto.response.FavoriteRestaurantDto
import com.hackathon.alddeul_babsang.domain.repository.ProfileRepository
import javax.inject.Inject

class ProfileRepositoryImpl @Inject constructor(
private val profileDataSource: ProfileDataSource
) : ProfileRepository {
override suspend fun getLikes(
userId: Long,
): Result<List<FavoriteRestaurantDto>> {
return runCatching {
profileDataSource.getLikes(
userId = userId
).result?.favoriteRestaurants ?: emptyList()
}
}

override suspend fun postLike(userId: Long, storeId: Long): Result<String> {
return runCatching {
profileDataSource.postLike(
requestLikesDto = RequestLikesDto(
userId = userId,
storeId = storeId
)
).result.toString()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ object ApiKeyStorage {
const val DELETE_ACCOUNT = "delete-account"
const val MYPAGE = "mypage"
const val LOGOUT = "logout"
const val USER_ID = "userId"
const val STORE_ID = "storeId"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hackathon.alddeul_babsang.data.service

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseReviewDto
import com.sopt.data.service.ApiKeyStorage.REVIEW
import com.sopt.data.service.ApiKeyStorage.STORE_ID
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.PartMap
import retrofit2.http.Path

interface DetailApiService {
@Multipart
@POST("/$REVIEW/{$STORE_ID}")
suspend fun postReview(
@Path("storeId") storeId: Long,
@PartMap data: Map<String, @JvmSuppressWildcards RequestBody>,
@Part reviewImage: MultipartBody.Part? = null
): BaseResponse<ResponseReviewDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hackathon.alddeul_babsang.data.service

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.request.RequestLikesDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseLikesDto
import com.sopt.data.service.ApiKeyStorage.FAVORITES
import com.sopt.data.service.ApiKeyStorage.USER_ID
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path

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

@POST("/$FAVORITES")
suspend fun postLike(
@Body requestLikesDto: RequestLikesDto
): BaseResponse<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hackathon.alddeul_babsang.domain.repository

import java.io.File

interface DetailRepository {
suspend fun postReview(
storeId: Long,
userId: Long,
rating: Double,
content: String,
reviewImage: File
): Result<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hackathon.alddeul_babsang.domain.repository

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

interface ProfileRepository {
suspend fun getLikes(
userId: Long,
): Result<List<FavoriteRestaurantDto>>

suspend fun postLike(
userId: Long,
storeId: Long,
): Result<String>
}
Loading

0 comments on commit fff4af6

Please sign in to comment.