-
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.
- 뷰모델 작업은 GET 작업 후 붙일 예정
- Loading branch information
Showing
16 changed files
with
256 additions
and
38 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
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
13 changes: 13 additions & 0 deletions
13
...src/main/java/com/photosurfer/android/data/remote/datasource/RemoteChooseTagDataSource.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,13 @@ | ||
package com.photosurfer.android.data.remote.datasource | ||
|
||
import com.photosurfer.android.data.remote.calladapter.NetworkState | ||
import com.photosurfer.android.data.remote.model.request.ChooseTagRequest | ||
import com.photosurfer.android.data.remote.model.response.BaseResponse | ||
import com.photosurfer.android.data.remote.model.response.ChooseTagResponse | ||
|
||
interface RemoteChooseTagDataSource { | ||
|
||
suspend fun postTag( | ||
chooseTagRequest: ChooseTagRequest | ||
): NetworkState<BaseResponse<ChooseTagResponse>> | ||
} |
17 changes: 17 additions & 0 deletions
17
...main/java/com/photosurfer/android/data/remote/datasource/RemoteChooseTagDataSourceImpl.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,17 @@ | ||
package com.photosurfer.android.data.remote.datasource | ||
|
||
import com.photosurfer.android.data.remote.calladapter.NetworkState | ||
import com.photosurfer.android.data.remote.model.request.ChooseTagRequest | ||
import com.photosurfer.android.data.remote.model.response.BaseResponse | ||
import com.photosurfer.android.data.remote.model.response.ChooseTagResponse | ||
import com.photosurfer.android.data.remote.service.ChooseTagService | ||
import javax.inject.Inject | ||
|
||
class RemoteChooseTagDataSourceImpl @Inject constructor( | ||
private val chooseTagService: ChooseTagService | ||
) : RemoteChooseTagDataSource{ | ||
override suspend fun postTag( | ||
chooseTagRequest: ChooseTagRequest | ||
): NetworkState<BaseResponse<ChooseTagResponse>> = | ||
chooseTagService.postTag(chooseTagRequest) | ||
} |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/com/photosurfer/android/data/remote/mapper/TagMapper.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,13 @@ | ||
package com.photosurfer.android.data.remote.mapper | ||
|
||
import com.photosurfer.android.data.remote.model.request.Tag | ||
import javax.inject.Inject | ||
|
||
class TagMapper @Inject constructor() { | ||
|
||
fun toDomainTag(tag: com.photosurfer.android.domain.entity.request.Tag):Tag = | ||
Tag(name = tag.name, type = tag.type) | ||
|
||
fun toDataTag(tag: Tag):com.photosurfer.android.domain.entity.request.Tag = | ||
com.photosurfer.android.domain.entity.request.Tag(name = tag.name, type = tag.type) | ||
} |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/com/photosurfer/android/data/remote/model/request/ChooseTagRequest.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,15 @@ | ||
package com.photosurfer.android.data.remote.model.request | ||
|
||
|
||
import com.photosurfer.android.domain.entity.TagNameType | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import java.io.File | ||
|
||
@Serializable | ||
data class ChooseTagRequest( | ||
@SerialName("file") | ||
val file: File, | ||
@SerialName("tags") | ||
val tags: List<TagNameType> | ||
) |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/photosurfer/android/data/remote/model/response/ChooseTagResponse.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,16 @@ | ||
package com.photosurfer.android.data.remote.model.response | ||
|
||
|
||
import com.photosurfer.android.domain.entity.TagIdNameType | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ChooseTagResponse( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("imageURL") | ||
val imageURL: String, | ||
@SerialName("tag") | ||
val tag: List<TagIdNameType> | ||
) |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/photosurfer/android/data/remote/service/ChooseTagService.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,16 @@ | ||
package com.photosurfer.android.data.remote.service | ||
|
||
import com.photosurfer.android.data.remote.calladapter.NetworkState | ||
import com.photosurfer.android.data.remote.model.request.ChooseTagRequest | ||
import com.photosurfer.android.data.remote.model.response.BaseResponse | ||
import com.photosurfer.android.data.remote.model.response.ChooseTagResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface ChooseTagService { | ||
@POST("photo/") | ||
suspend fun postTag( | ||
@Body body: ChooseTagRequest | ||
): NetworkState<BaseResponse<ChooseTagResponse>> | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
data/src/main/java/com/photosurfer/android/data/repository/ChooseTagRepositoryImpl.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,52 @@ | ||
package com.photosurfer.android.data.repository | ||
|
||
import com.photosurfer.android.core.exception.RetrofitFailureStateException | ||
import com.photosurfer.android.data.remote.calladapter.NetworkState | ||
import com.photosurfer.android.data.remote.datasource.RemoteChooseTagDataSource | ||
import com.photosurfer.android.data.remote.mapper.TagMapper | ||
import com.photosurfer.android.data.remote.model.request.ChooseTagRequest | ||
import com.photosurfer.android.domain.entity.TagNameType | ||
import com.photosurfer.android.domain.entity.request.DomainChooseTagRequest | ||
import com.photosurfer.android.domain.repository.ChooseTagRepository | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class ChooseTagRepositoryImpl @Inject constructor( | ||
private val remoteChooseTagDataSource: RemoteChooseTagDataSource, | ||
private val tagMapper: TagMapper | ||
) : ChooseTagRepository { | ||
override suspend fun postTag(domainChooseTagRequest: DomainChooseTagRequest): Result<List<TagNameType>> { | ||
when( | ||
val response = remoteChooseTagDataSource.postTag( | ||
ChooseTagRequest( | ||
file = domainChooseTagRequest.file, | ||
tags = domainChooseTagRequest.tags.map{ | ||
tagMapper.toDomainTag(it) | ||
} | ||
) | ||
) | ||
) { | ||
is NetworkState.Success -> return Result.success( | ||
response.body.data.tag.map{ | ||
tagMapper.toDataTag(it) | ||
} | ||
) | ||
is NetworkState.Failure -> return Result.failure( | ||
RetrofitFailureStateException( | ||
response.error, | ||
response.code | ||
) | ||
) | ||
is NetworkState.NetworkError -> Timber.d( | ||
response.error, | ||
"${this.javaClass.name}_postChooseTag" | ||
) | ||
is NetworkState.UnknownError -> Timber.d( | ||
response.t, | ||
"${this.javaClass.name}_postChooseTag" | ||
) | ||
} | ||
return Result.failure(IllegalStateException("NetworkError or UnKnownError please check timber")) | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/photosurfer/android/domain/entity/TagIdNameType.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,7 @@ | ||
package com.photosurfer.android.domain.entity | ||
|
||
data class TagIdNameType( | ||
val id: Int, | ||
val name: String, | ||
val type: String | ||
) |
6 changes: 6 additions & 0 deletions
6
domain/src/main/java/com/photosurfer/android/domain/entity/TagNameType.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,6 @@ | ||
package com.photosurfer.android.domain.entity | ||
|
||
data class TagNameType( | ||
val name: String, | ||
val type: String | ||
) |
9 changes: 9 additions & 0 deletions
9
domain/src/main/java/com/photosurfer/android/domain/entity/request/DomainChooseTagRequest.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,9 @@ | ||
package com.photosurfer.android.domain.entity.request | ||
|
||
import com.photosurfer.android.domain.entity.TagNameType | ||
import java.io.File | ||
|
||
data class DomainChooseTagRequest( | ||
val file: File, | ||
val tags: List<TagNameType> | ||
) |
11 changes: 11 additions & 0 deletions
11
domain/src/main/java/com/photosurfer/android/domain/repository/ChooseTagRepository.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,11 @@ | ||
package com.photosurfer.android.domain.repository | ||
|
||
import com.photosurfer.android.domain.entity.request.DomainChooseTagRequest | ||
import com.photosurfer.android.domain.entity.request.Tag | ||
|
||
interface ChooseTagRepository { | ||
|
||
suspend fun postTag( | ||
domainChooseTagRequest: DomainChooseTagRequest | ||
): Result<List<Tag>> | ||
} |
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
Oops, something went wrong.