Skip to content

Commit

Permalink
Merge pull request #164 from PawWithU/feature/create_announcement
Browse files Browse the repository at this point in the history
feature/create_announcement: 공고 등록 api 연결
  • Loading branch information
kang9366 authored May 31, 2024
2 parents 670ddc7 + 8f87528 commit b4261a4
Show file tree
Hide file tree
Showing 104 changed files with 254 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import com.kusitms.connectdog.core.data.api.model.intermediator.InterApplication
import com.kusitms.connectdog.core.data.api.model.intermediator.InterProfileFindingResponseItem
import com.kusitms.connectdog.core.data.api.model.intermediator.InterProfileInfoResponse
import com.kusitms.connectdog.core.data.api.model.intermediator.IntermediatorProfileInfoResponseItem
import com.kusitms.connectdog.core.data.api.model.intermediator.IntermediatorSignUpBody
import com.kusitms.connectdog.core.data.api.model.volunteer.ReviewDetailResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

Expand All @@ -29,9 +32,11 @@ internal interface InterApiService {
/**
* 회원가입
*/
@Multipart
@POST("/intermediaries/sign-up")
suspend fun intermediatorSignUp(
@Body body: IntermediatorSignUpBody
@Part("request") json: RequestBody,
@Part file: MultipartBody.Part
)

@POST("/intermediaries/phone/isDuplicated")
Expand Down Expand Up @@ -126,4 +131,11 @@ internal interface InterApiService {
suspend fun postFcmToken(
@Body fcmToken: FcmTokenRequestBody
)

@Multipart
@POST("/intermediaries/posts")
suspend fun postApplication(
@Part("request") json: RequestBody,
@Part files: List<MultipartBody.Part>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.kusitms.connectdog.core.data.api.model.intermediator

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class CreateApplicationDto(
val departureLoc: String,
val arrivalLoc: String,
val startDate: String,
val endDate: String,
val pickUpTime: String,
val isKennel: Boolean,
val content: String,
val dogName: String,
val dogSize: String,
val specifics: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.kusitms.connectdog.core.data.di

import com.kusitms.connectdog.core.data.api.InterApiService
import com.kusitms.connectdog.core.data.repository.InterHomeRepository
import com.kusitms.connectdog.core.data.repository.InterHomeRepositoryImpl
import com.kusitms.connectdog.core.data.repository.InterManagementRepository
import com.kusitms.connectdog.core.data.repository.InterManagementRepositoryImpl
import com.kusitms.connectdog.core.data.repository.InterProfileRepository
Expand All @@ -15,6 +17,12 @@ import javax.inject.Singleton
@Module
internal class InterDataModule {

@Provides
@Singleton
fun provideInterHomeRepository(apiService: InterApiService): InterHomeRepository {
return InterHomeRepositoryImpl(apiService)
}

@Provides
@Singleton
fun provideInterManagementRepository(apiService: InterApiService): InterManagementRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package com.kusitms.connectdog.core.data.repository

interface InterHomeRepository
import com.kusitms.connectdog.core.data.api.model.intermediator.CreateApplicationDto
import java.io.File

interface InterHomeRepository {
suspend fun createApplication(body: CreateApplicationDto, images: List<File>)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
package com.kusitms.connectdog.core.data.repository

class InterHomeRepositoryImpl
import com.google.gson.Gson
import com.kusitms.connectdog.core.data.api.InterApiService
import com.kusitms.connectdog.core.data.api.model.intermediator.CreateApplicationDto
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
import javax.inject.Inject

internal class InterHomeRepositoryImpl @Inject constructor(
private val api: InterApiService
) : InterHomeRepository {
override suspend fun createApplication(body: CreateApplicationDto, images: List<File>) {
val jsonBody = RequestBody.create(
"application/json; charset=utf-8".toMediaTypeOrNull(),
Gson().toJson(body)
)

val files = images.map { file ->
val fileBody = RequestBody.create("multipart/form-data".toMediaTypeOrNull(), file)
MultipartBody.Part.createFormData("files", file.name, fileBody)
}

api.postApplication(jsonBody, files)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
28
29
0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.kusitms.connectdog.core.designsystem.component.bottomSheet
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.kusitms.connectdog.core.util

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import java.io.File
import java.io.FileOutputStream

object ImageConverter {
fun uriToFile(context: Context, uri: Uri, quality: Int): File? {
val inputStream = context.contentResolver.openInputStream(uri)
val bitmap = BitmapFactory.decodeStream(inputStream)
val tempFile = File.createTempFile("compressed_", ".jpg", context.cacheDir)
val outputStream = FileOutputStream(tempFile)

bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)
outputStream.flush()
outputStream.close()

return tempFile
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.kusitms.connectdog.feature.intermediator.screen.InterManagementRoute
import com.kusitms.connectdog.feature.intermediator.screen.InterProfileEditScreen
import com.kusitms.connectdog.feature.intermediator.screen.InterProfileScreen
import com.kusitms.connectdog.feature.intermediator.screen.ReviewScreen
import com.kusitms.connectdog.feature.intermediator.viewmodel.CreateApplicationViewModel

fun NavController.navigateInterHome() {
navigate(IntermediatorRoute.route) {
Expand Down Expand Up @@ -55,6 +56,7 @@ fun NavController.navigateToAnnouncementManagement(postId: Long) {

fun NavGraphBuilder.intermediatorNavGraph(
imeHeight: Int,
createApplicationViewModel: CreateApplicationViewModel,
onBackClick: () -> Unit,
onSettingClick: () -> Unit,
onNotificationClick: () -> Unit,
Expand Down Expand Up @@ -99,7 +101,8 @@ fun NavGraphBuilder.intermediatorNavGraph(
CreateApplicationInfoScreen(
onBackClick = onBackClick,
navigateToCreateDog = onNavigateToCreateDog,
imeHeight = imeHeight
imeHeight = imeHeight,
viewModel = createApplicationViewModel
)
}

Expand All @@ -116,7 +119,9 @@ fun NavGraphBuilder.intermediatorNavGraph(

composable(route = IntermediatorRoute.create_application_dog) {
CreateApplicationDogScreen(
onBackClick = onBackClick
imeHeight = imeHeight,
onBackClick = onBackClick,
viewModel = createApplicationViewModel
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -33,8 +35,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -44,13 +48,16 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.AsyncImage
import com.kusitms.connectdog.core.designsystem.component.ConnectDogBottomButton
import com.kusitms.connectdog.core.designsystem.component.ConnectDogTextField
import com.kusitms.connectdog.core.designsystem.component.ConnectDogTopAppBar
import com.kusitms.connectdog.core.designsystem.component.Detail
Expand All @@ -67,26 +74,50 @@ import com.kusitms.connectdog.feature.intermediator.viewmodel.CreateApplicationV
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun CreateApplicationDogScreen(
imeHeight: Int,
viewModel: CreateApplicationViewModel,
onBackClick: () -> Unit
) {
val focusManager = LocalFocusManager.current
val interactionSource = remember { MutableInteractionSource() }

Scaffold(
modifier = Modifier
.clickable(
onClick = { focusManager.clearFocus() },
indication = null,
interactionSource = interactionSource
),
topBar = {
ConnectDogTopAppBar(
titleRes = R.string.create_announcement,
navigationType = TopAppBarNavigationType.BACK,
onNavigationClick = onBackClick
)
},
bottomBar = {
ConnectDogBottomButton(
modifier = Modifier.background(color = Color.White).padding(horizontal = 20.dp, vertical = 24.dp),
onClick = { },
content = "등록 완료"
)
}
) {
Content()
Content(
viewModel = viewModel,
imeHeight = imeHeight
)
}
}

@Composable
private fun Content(
viewModel: CreateApplicationViewModel = hiltViewModel()
viewModel: CreateApplicationViewModel,
imeHeight: Int
) {
val scrollState = rememberScrollState()
val context = LocalContext.current

Column(
modifier = Modifier
.padding(top = 32.dp)
Expand Down Expand Up @@ -114,7 +145,7 @@ private fun Content(
Spacer(modifier = Modifier.height(32.dp))
Divider(thickness = 8.dp, color = Gray7)
Spacer(modifier = Modifier.height(32.dp))
Significant()
Significant(viewModel = viewModel, imeHeight = imeHeight, scrollState = scrollState)
}
}

Expand Down Expand Up @@ -303,7 +334,15 @@ private fun AddPhotoButton(onClick: () -> Unit) {
}

@Composable
private fun Significant() {
private fun Significant(
scrollState: ScrollState,
imeHeight: Int,
viewModel: CreateApplicationViewModel
) {
LaunchedEffect(imeHeight) {
if (imeHeight != 0) scrollState.animateScrollTo(scrollState.maxValue)
}

Column(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -316,6 +355,13 @@ private fun Significant() {
color = Gray1
)
Spacer(modifier = Modifier.height(12.dp))
ConnectDogTextField(text = "", onTextChanged = {}, label = "", placeholder = "", height = 244)
ConnectDogTextField(
text = viewModel.specifics,
onTextChanged = viewModel::updateSpecifics,
label = "",
placeholder = "",
height = 244
)
Spacer(modifier = Modifier.height((imeHeight).dp))
}
}
Loading

0 comments on commit b4261a4

Please sign in to comment.