This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature/detail-screen] 미션 상세 화면 연결 및 서버통신 (#41)
* [feature/detail-screen] Mission Detail 화면 패키기 구조 잡기 * [feature/detail-screen] 상세화면에 넘겨줄 Argument 타입 정의 * [feature/detail-screen] 상세화면에 args 넘겨주기 * [feature/detail-screen] Mission List-Detail 간 Navigation 정의 * [feature/detail-screen] 성공시 화면 새로고침 유도 * [feature/detail-screen] Mission Detail 서버통신 전 * [feature/detail-screen] 이미지 피커 준비 * [feature/detail-screen] MissionDetailViewModel 레포지터리, 뷰모델 연결 * [feature/detail-screen] MissionDetailViewModel 뷰에 연결 * [feature/detail-screen] fix lint
- Loading branch information
Showing
15 changed files
with
465 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 17 additions & 7 deletions
24
app/src/main/java/org/sopt/stamp/data/remote/model/response/StampResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
package org.sopt.stamp.data.remote.model.response | ||
|
||
import kotlinx.datetime.Instant | ||
import kotlinx.serialization.Serializable | ||
import org.sopt.stamp.domain.model.Archive | ||
|
||
@Serializable | ||
data class StampResponse( | ||
val createdAt: Instant? = null, | ||
val updatedAt: Instant? = null, | ||
val id: Long, | ||
val createdAt: String? = null, | ||
val updatedAt: String? = null, | ||
val id: Int, | ||
val contents: String, | ||
val images: List<String>, | ||
val userId: Long, | ||
val images: List<String>? = null, | ||
val userId: Int, | ||
val missionId: Int, | ||
) | ||
) { | ||
fun toDomain() = Archive( | ||
createdAt = createdAt, | ||
updatedAt = updatedAt, | ||
id = id, | ||
contents = contents, | ||
images = images ?: emptyList(), | ||
userId = userId, | ||
missionId = missionId, | ||
) | ||
} |
88 changes: 88 additions & 0 deletions
88
app/src/main/java/org/sopt/stamp/data/repository/StampRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.sopt.stamp.data.repository | ||
|
||
import android.content.Context | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import org.sopt.stamp.data.remote.api.StampService | ||
import org.sopt.stamp.domain.model.Archive | ||
import org.sopt.stamp.domain.repository.StampRepository | ||
import org.sopt.stamp.feature.mission.model.ImageModel | ||
import org.sopt.stamp.util.ContentUriRequestBody | ||
import javax.inject.Inject | ||
|
||
class StampRepositoryImpl @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
private val service: StampService, | ||
private val json: Json | ||
) : StampRepository { | ||
@Serializable | ||
private data class Content( | ||
val content: String | ||
) | ||
|
||
override suspend fun completeMission( | ||
missionId: Int, | ||
imageUri: ImageModel, | ||
content: String | ||
): Result<Unit> { | ||
val contentJson = json.encodeToString(Content(content)) | ||
val contentRequestBody = contentJson.toRequestBody("application/json".toMediaType()) | ||
val imageRequestBody = when (imageUri) { | ||
is ImageModel.Empty -> null | ||
is ImageModel.Local -> { | ||
imageUri.uri.map { | ||
ContentUriRequestBody(context, it) | ||
}.map { | ||
it.toFormData() | ||
} | ||
} | ||
|
||
is ImageModel.Remote -> null | ||
} | ||
return runCatching { | ||
service.registerStamp( | ||
missionId, | ||
contentRequestBody, | ||
imageRequestBody | ||
) | ||
} | ||
} | ||
|
||
override suspend fun getMissionContent(missionId: Int): Result<Archive> { | ||
return runCatching { | ||
service.retrieveStamp(missionId).toDomain() | ||
} | ||
} | ||
|
||
override suspend fun modifyMission( | ||
missionId: Int, | ||
imageUri: ImageModel, | ||
content: String | ||
): Result<Unit> { | ||
val contentJson = json.encodeToString(Content(content)) | ||
val contentRequestBody = contentJson.toRequestBody("application/json".toMediaType()) | ||
val imageRequestBody = when (imageUri) { | ||
is ImageModel.Empty -> null | ||
is ImageModel.Local -> { | ||
imageUri.uri.map { | ||
ContentUriRequestBody(context, it) | ||
}.map { | ||
it.toFormData() | ||
} | ||
} | ||
|
||
is ImageModel.Remote -> null | ||
} | ||
return runCatching { | ||
service.modifyStamp( | ||
missionId, | ||
contentRequestBody, | ||
imageRequestBody | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.stamp.domain.model | ||
|
||
data class Archive( | ||
val createdAt: String? = null, | ||
val updatedAt: String? = null, | ||
val id: Int, | ||
val contents: String, | ||
val images: List<String>, | ||
val userId: Int, | ||
val missionId: Int, | ||
) |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/org/sopt/stamp/domain/repository/StampRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.sopt.stamp.domain.repository | ||
|
||
import org.sopt.stamp.domain.model.Archive | ||
import org.sopt.stamp.feature.mission.model.ImageModel | ||
|
||
interface StampRepository { | ||
suspend fun completeMission( | ||
missionId: Int, | ||
imageUri: ImageModel, | ||
content: String | ||
): Result<Unit> | ||
|
||
suspend fun getMissionContent( | ||
missionId: Int | ||
): Result<Archive> | ||
|
||
suspend fun modifyMission( | ||
missionId: Int, | ||
imageUri: ImageModel, | ||
content: String | ||
): Result<Unit> | ||
} |
Oops, something went wrong.