Skip to content

Commit

Permalink
Merge pull request #7 from AdultOfNineteen/bug/issue-6
Browse files Browse the repository at this point in the history
[BUG] 노트 작성 문제 수정
  • Loading branch information
DongChyeon authored Dec 4, 2023
2 parents 1ac0e63 + 14a03ab commit 308fbbe
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.teamwiney.core.common.model

enum class WineSmell(val type: String, val value: String, val korName: String) {
FRUIT("FRUIT", "FRUIT", "과일향"),
BERRY("FRUIT", "BERRY", "베리류"),
LEMONANDLIME("FRUIT", "LEMONANDLIME", "레몬/라임"),
APPLEPEAR("FRUIT", "APPLEPEAR", "사과/배"),
PEACHPLUM("FRUIT", "PEACHPLUM", "복숭아/자두"),
TROPICALFRUIT("FRUIT", "TROPICALFRUIT", "열대과일"),
FLOWER("NATURAL", "FLOWER", "꽃향"),
GRASSWOOD("NATURAL", "GRASSWOOD", "풀/나무"),
HERB("NATURAL", "HERB", "허브향"),
OAK("OAK", "OAK", "오크향"),
SPICE("OAK", "SPICE", "향신료"),
NUTS("OAK", "NUTS", "견과류"),
VANILLA("OAK", "VANILLA", "바닐라"),
CHOCOLATE("OAK", "CHOCOLATE", "초콜릿"),
FLINT("OTHER", "FLINT", "부싯돌"),
BREAD("OTHER", "BREAD", ""),
RUBBER("OTHER", "RUBBER", "고무"),
EARTHASH("OTHER", "EARTASH", "흙/재"),
MEDICINE("OTHER", "MEDICNE", "약품")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.teamwiney.data.network.model.response.TastingNoteIdRes
import kotlinx.coroutines.flow.Flow
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Part

interface TastingNoteDataSource {

Expand All @@ -32,8 +31,7 @@ interface TastingNoteDataSource {
fun deleteTastingNote(noteId: Int): Flow<ApiResult<ResponseWrapper<String>>>

fun postTastingNote(
wineNoteWriteRequest: HashMap<String, RequestBody>,
smellKeywordList: List<MultipartBody.Part>,
request: RequestBody,
multipartFiles: List<MultipartBody.Part>,
): Flow<ApiResult<ResponseWrapper<TastingNoteIdRes>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,10 @@ class TastingNoteDataSourceImpl @Inject constructor(
}.flowOn(ioDispatcher)

override fun postTastingNote(
wineNoteWriteRequest: HashMap<String, RequestBody>,
smellKeywordList: List<MultipartBody.Part>,
request: RequestBody,
multipartFiles: List<MultipartBody.Part>
): Flow<ApiResult<ResponseWrapper<TastingNoteIdRes>>> = flow {
emit(
tastingNoteService.postTastingNote(
wineNoteWriteRequest,
smellKeywordList,
multipartFiles
)
)
emit(tastingNoteService.postTastingNote(request, multipartFiles))
}.flowOn(ioDispatcher)

}
7 changes: 5 additions & 2 deletions data/src/main/java/com/teamwiney/data/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teamwiney.data.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import com.teamwiney.data.datasource.AuthDataSource
Expand All @@ -22,6 +23,7 @@ import com.teamwiney.data.repository.wine.WineRepositoryImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton
Expand Down Expand Up @@ -67,8 +69,9 @@ object DataModule {
@Provides
@Singleton
fun providesTastingNotRepository(
tastingNoteDataSource: TastingNoteDataSource
): TastingNoteRepository = TastingNoteRepositoryImpl(tastingNoteDataSource)
tastingNoteDataSource: TastingNoteDataSource,
@ApplicationContext context: Context
): TastingNoteRepository = TastingNoteRepositoryImpl(tastingNoteDataSource, context)

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.PartMap
import retrofit2.http.Path
import retrofit2.http.Query
import java.util.PrimitiveIterator.OfInt

interface TastingNoteService {

Expand Down Expand Up @@ -58,8 +56,7 @@ interface TastingNoteService {
@Multipart
@POST("/tasting-notes")
suspend fun postTastingNote(
@PartMap wineNoteWriteRequest: HashMap<String, RequestBody>,
@Part smellKeywordList: List<MultipartBody.Part>,
@Part("request") request: RequestBody,
@Part multipartFiles: List<MultipartBody.Part>,
): ApiResult<ResponseWrapper<TastingNoteIdRes>>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teamwiney.data.repository.tastingnote

import android.net.Uri
import com.teamwiney.core.common.base.ResponseWrapper
import com.teamwiney.core.common.`typealias`.BaseResponse
import com.teamwiney.data.network.adapter.ApiResult
Expand All @@ -10,8 +11,6 @@ import com.teamwiney.data.network.model.response.TastingNoteDetail
import com.teamwiney.data.network.model.response.TastingNoteFilters
import com.teamwiney.data.network.model.response.TastingNoteIdRes
import kotlinx.coroutines.flow.Flow
import okhttp3.MultipartBody
import okhttp3.RequestBody

interface TastingNoteRepository {

Expand Down Expand Up @@ -40,8 +39,21 @@ interface TastingNoteRepository {
fun deleteTastingNote(noteId: Int): Flow<ApiResult<BaseResponse>>

fun postTastingNote(
wineNoteWriteRequest: HashMap<String, RequestBody>,
smellKeywordList: List<MultipartBody.Part>,
multipartFiles: List<MultipartBody.Part>,
wineId: Long,
officialAlcohol: Double,
alcohol: Int,
color: String,
sweetness: Int,
acidity: Int,
body: Int,
tannin: Int,
finish: Int,
memo: String,
rating: Int,
vintage: String,
price: String,
buyAgain: Boolean?,
smellKeywordList: List<String>,
imgUris: List<Uri>
): Flow<ApiResult<ResponseWrapper<TastingNoteIdRes>>>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.teamwiney.data.repository.tastingnote

import android.content.Context
import android.net.Uri
import com.teamwiney.core.common.base.ResponseWrapper
import com.teamwiney.core.common.`typealias`.BaseResponse
import com.teamwiney.data.datasource.TastingNoteDataSource
Expand All @@ -10,13 +12,22 @@ import com.teamwiney.data.network.model.response.TastingNote
import com.teamwiney.data.network.model.response.TastingNoteDetail
import com.teamwiney.data.network.model.response.TastingNoteFilters
import com.teamwiney.data.network.model.response.TastingNoteIdRes
import com.teamwiney.data.util.fileFromContentUri
import com.teamwiney.data.util.resizeAndSaveImage
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONArray
import org.json.JSONObject
import javax.inject.Inject

class TastingNoteRepositoryImpl @Inject constructor(
private val tastingNoteDataSource: TastingNoteDataSource
private val tastingNoteDataSource: TastingNoteDataSource,
@ApplicationContext private val context: Context
) : TastingNoteRepository {

override fun getTasteAnalysis(): Flow<ApiResult<ResponseWrapper<TasteAnalysis>>> =
Expand Down Expand Up @@ -50,14 +61,49 @@ class TastingNoteRepositoryImpl @Inject constructor(
tastingNoteDataSource.deleteTastingNote(noteId)

override fun postTastingNote(
wineNoteWriteRequest: HashMap<String, RequestBody>,
smellKeywordList: List<MultipartBody.Part>,
multipartFiles: List<MultipartBody.Part>
wineId: Long,
officialAlcohol: Double,
alcohol: Int,
color: String,
sweetness: Int,
acidity: Int,
body: Int,
tannin: Int,
finish: Int,
memo: String,
rating: Int,
vintage: String,
price: String,
buyAgain: Boolean?,
smellKeywordList: List<String>,
imgUris: List<Uri>
): Flow<ApiResult<ResponseWrapper<TastingNoteIdRes>>> {
return tastingNoteDataSource.postTastingNote(
wineNoteWriteRequest,
smellKeywordList,
multipartFiles
)
val jsonObjectBuilder = JSONObject().apply {
put("wineId", wineId)
put("officialAlcohol", officialAlcohol)
put("alcohol", alcohol)
put("color", color)
put("sweetness", sweetness)
put("acidity", acidity)
put("body", body)
put("tannin", tannin)
put("finish", finish)
put("memo", memo)
put("rating", rating)
if (vintage.isNotEmpty()) put("vintage", vintage.toInt())
if (price.isNotEmpty()) put("price", price.toInt())
buyAgain?.let { put("buyAgain", it) }
put("smellKeywordList", JSONArray().apply { smellKeywordList.forEach { put(it) } })
}

val request = jsonObjectBuilder.toString().toRequestBody("application/json".toMediaType())
val multipartFiles = imgUris.map {
val originalFile = fileFromContentUri(context, it)
val compressedFile = resizeAndSaveImage(context, originalFile)
val requestBody: RequestBody = compressedFile.asRequestBody("image/*".toMediaType())
MultipartBody.Part.createFormData("multipartFiles", compressedFile.name, requestBody)
}

return tastingNoteDataSource.postTastingNote(request, multipartFiles)
}
}
4 changes: 1 addition & 3 deletions data/src/main/java/com/teamwiney/data/util/FileExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import java.security.SecureRandom
import java.util.*

fun fileFromContentUri(context: Context, contentUri: Uri): File {
// Preparing Temp file name
val fileExtension = getFileExtension(context, contentUri)
val fileName = "temp_file" + if (fileExtension != null) ".$fileExtension" else ""

// Creating Temp file
val tempFile = File(context.cacheDir, fileName)
tempFile.createNewFile()

Expand Down Expand Up @@ -97,7 +95,7 @@ private fun createFile(context: Context): File {

val storageDir = context.cacheDir

return File(storageDir, fileName)
return File(storageDir, "${fileName}.jpg")
}

private fun generateRandomFileName(length: Int): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -16,7 +18,6 @@ import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicTextField
Expand Down Expand Up @@ -61,15 +62,15 @@ import com.teamwiney.ui.components.WButton
import com.teamwiney.ui.components.bottomBorder
import com.teamwiney.ui.theme.LocalColors
import com.teamwiney.ui.theme.WineyTheme
import kotlinx.coroutines.Job

data class WineSmell(
data class WineSmellKeyword(
val title: String,
val options: List<WineSmellOption>,
)

data class WineSmellOption(
val name: String,
val value: String,
var isSelected: Boolean = false
)

Expand Down Expand Up @@ -113,8 +114,9 @@ fun NoteWineInfoColorAndSmellScreen(
updateThumbX = { viewModel.updateThumbX(it) },
) { viewModel.updateColor(it) }
HeightSpacer(35.dp)
WineFavorPicker(
wineSmells = uiState.wineSmells,
WineFlavorPicker(
wineSmellKeywords = uiState.wineSmellKeywords,
isWineSmellKeywordSelected = viewModel::isWineSmellSelected,
updateWineSmell = { wineSmellOption ->
viewModel.updateWineSmells(wineSmellOption)
},
Expand Down Expand Up @@ -146,8 +148,9 @@ fun NoteWineInfoColorAndSmellScreen(
}

@Composable
private fun WineFavorPicker(
wineSmells: List<WineSmell>,
private fun WineFlavorPicker(
wineSmellKeywords: List<WineSmellKeyword>,
isWineSmellKeywordSelected: (WineSmellOption) -> Boolean,
updateWineSmell: (WineSmellOption) -> Unit = {}, navigateToStandardSmell: () -> Unit
) {
Column(
Expand Down Expand Up @@ -194,41 +197,46 @@ private fun WineFavorPicker(
Column(
verticalArrangement = Arrangement.spacedBy(25.dp)
) {
wineSmells.forEach {
WineSmellContainer(wineSmell = it, updateWineSmell = updateWineSmell)
wineSmellKeywords.forEach {
WineSmellContainer(
wineSmellKeyword = it,
isWineSmellKeywordSelected = isWineSmellKeywordSelected,
updateWineSmell = updateWineSmell
)
}
}
}
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun WineSmellContainer(
wineSmell: WineSmell,
wineSmellKeyword: WineSmellKeyword,
isWineSmellKeywordSelected: (WineSmellOption) -> Boolean,
updateWineSmell: (WineSmellOption) -> Unit = {}
) {
Column(
verticalArrangement = Arrangement.spacedBy(14.dp)
) {
Text(
text = wineSmell.title,
text = wineSmellKeyword.title,
modifier = Modifier.padding(start = 24.dp),
style = WineyTheme.typography.bodyB2,
color = WineyTheme.colors.gray_500
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(5.dp)
FlowRow(
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp),
horizontalArrangement = Arrangement.spacedBy(5.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
Spacer(modifier = Modifier.width(14.dp))
wineSmell.options.forEach {
wineSmellKeyword.options.forEach {
NoteFeatureText(
name = it.name,
enable = it.isSelected,
enable = isWineSmellKeywordSelected(it),
) {
updateWineSmell(it.copy(isSelected = !it.isSelected))
}
}
Spacer(modifier = Modifier.width(14.dp))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fun NoteWineInfoFlavorScreen(
HeightSpacer(30.dp)
WineTasteSlider(
score = uiState.wineNote.alcohol,
onValueChange = { viewModel.updateWineNoteAlcohol(it) },
onValueChange = { viewModel.updateAlcohol(it) },
title = "알코올",
subTitle = "알코올 세기의 정도"
)
Expand Down
Loading

0 comments on commit 308fbbe

Please sign in to comment.