Skip to content

Commit

Permalink
[feat] POST 사진에 태그 추가 (#71)
Browse files Browse the repository at this point in the history
- 뷰모델 작업은 GET 작업 후 붙일 예정
  • Loading branch information
visionWWW committed Jul 21, 2022
1 parent a061099 commit 03294f5
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.photosurfer.android.di

import com.photosurfer.android.data.remote.datasource.RemoteChooseTagDataSource
import com.photosurfer.android.data.remote.datasource.RemoteChooseTagDataSourceImpl
import com.photosurfer.android.data.remote.datasource.RemotePushSettingDataSource
import com.photosurfer.android.data.remote.datasource.RemotePushSettingDataSourceImpl
import dagger.Binds
Expand All @@ -15,4 +17,8 @@ interface RemoteDataSourceModule {
@Binds
@Singleton
fun bindsRemotePushSettingDataSource(source: RemotePushSettingDataSourceImpl): RemotePushSettingDataSource

@Binds
@Singleton
fun bindRemoteChooseTagDataSource(source: RemoteChooseTagDataSourceImpl): RemoteChooseTagDataSource
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.photosurfer.android.di

import com.photosurfer.android.data.repository.ChooseTagRepositoryImpl
import com.photosurfer.android.data.repository.PushSettingRepositoryImpl
import com.photosurfer.android.domain.repository.ChooseTagRepository
import com.photosurfer.android.domain.repository.PushSettingRepository
import dagger.Binds
import dagger.Module
Expand All @@ -15,4 +17,9 @@ interface RepositoryModule {
@Binds
@Singleton
fun bindsPushSettingRepository(repository: PushSettingRepositoryImpl): PushSettingRepository

@Binds
@Singleton
fun bindsChooseTagRepository(repository: ChooseTagRepositoryImpl): ChooseTagRepository

}
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>>
}
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)
}
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)
}
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>
)
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>
)
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>>

}
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"))
}

}
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
)
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
)
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>
)
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>>
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.photosurfer.android.register_tag

import android.content.ContentValues.TAG
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.viewModels
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.photosurfer.android.core.base.BaseFragment
import com.photosurfer.android.core.util.MultiPartResolver
import com.photosurfer.android.core.util.PhotoSurferSnackBar
import com.photosurfer.android.domain.entity.TagInfo
import com.photosurfer.android.register_tag.databinding.FragmentChooseTagBinding
Expand Down Expand Up @@ -43,6 +40,14 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme
initRecyclerViewLayout()

val file: File = setImgToFile(getImgToUri())

initButtonSaveClickListener()
}

private fun initButtonSaveClickListener() {
binding.tvSave.setOnClickListener {
chooseTagViewModel.postChooseTag()
}
}

private fun getImgToUri(): Uri? {
Expand Down Expand Up @@ -126,7 +131,7 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme
private fun addInputTag() {
binding.etTag.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
chooseTagViewModel.inputList.add(TagInfo(0L, binding.etTag.text.toString()))
chooseTagViewModel.inputList.add(TagInfo(0, binding.etTag.text.toString()))
chooseTagViewModel.setEmptyInput(chooseTagViewModel.inputList.size)
binding.etTag.text.clear()
true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,71 @@
package com.photosurfer.android.register_tag

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.photosurfer.android.core.base.BaseViewModel
import com.photosurfer.android.core.util.Event
import com.photosurfer.android.domain.entity.TagInfo
import com.photosurfer.android.domain.entity.request.DomainChooseTagRequest
import com.photosurfer.android.domain.repository.ChooseTagRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import java.io.File
import javax.inject.Inject

class ChooseTagViewModel : ViewModel() {
@HiltViewModel
class ChooseTagViewModel @Inject constructor(
private val chooseTagRepository: ChooseTagRepository
) : BaseViewModel() {
private var _isEmptyInput = MutableLiveData<Int>()
val isEmptyInput: LiveData<Int> get() = _isEmptyInput
var inputList: MutableList<TagInfo> = mutableListOf()
val recentList: MutableList<TagInfo> = mutableListOf()
val oftenList: MutableList<TagInfo> = mutableListOf()
val platformList: MutableList<TagInfo> = mutableListOf()

private val _chooseTagSuccess = MutableLiveData<Event<Boolean>>()
val chooseTagSuccess: LiveData<Event<Boolean>> = _chooseTagSuccess

private val _chooseTagFailure = MutableLiveData<Event<Boolean>>()
val chooseTagFailure: LiveData<Event<Boolean>> = _chooseTagFailure


val imageFile: File
get() {
TODO()
}

fun setTagList() {
recentList.addAll(
listOf(
TagInfo(7L, "포토서퍼"),
TagInfo(8L, "카페"),
TagInfo(9L, "생활꿀팁"),
TagInfo(10L, "위시리스트"),
TagInfo(11L, "휴학"),
TagInfo(12L, "여행")
TagInfo(7, "포토서퍼"),
TagInfo(8, "카페"),
TagInfo(9, "생활꿀팁"),
TagInfo(10, "위시리스트"),
TagInfo(11, "휴학"),
TagInfo(12, "여행")
)
)
oftenList.addAll(
listOf(
TagInfo(13L, "좋은노래"),
TagInfo(14L, "솝트"),
TagInfo(15L, "전시회"),
TagInfo(16L, "그래픽디자인"),
TagInfo(17L, "포토서퍼"),
TagInfo(18L, "인턴")
TagInfo(13, "좋은노래"),
TagInfo(14, "솝트"),
TagInfo(15, "전시회"),
TagInfo(16, "그래픽디자인"),
TagInfo(17, "포토서퍼"),
TagInfo(18, "인턴")
)
)
platformList.addAll(
listOf(
TagInfo(1L, "카카오톡"),
TagInfo(2L, "유튜브"),
TagInfo(3L, "인스타그램"),
TagInfo(4L, "쇼핑몰"),
TagInfo(5L, "커뮤니티"),
TagInfo(6L, "기타")
TagInfo(1, "카카오톡"),
TagInfo(2, "유튜브"),
TagInfo(3, "인스타그램"),
TagInfo(4, "쇼핑몰"),
TagInfo(5, "커뮤니티"),
TagInfo(6, "기타")
)
)

Expand All @@ -65,4 +83,21 @@ class ChooseTagViewModel : ViewModel() {
inputList.remove(item)
}

// TODO: GET 서버 로직 붙이고 추가할 예정
// fun postChooseTag() {
// viewModelScope.launch {
// chooseTagRepository.postTag(
// DomainChooseTagRequest(
// // TODO : imageFile 멀티파트 처리한 거 넣어줘야함
// file = imageFile,
// tags = inputList
// )
// ).onSuccess {
// _chooseTagSuccess.postValue(Event(true))
// }.onFailure {
// _chooseTagFailure.postValue(Event(true))
// }
// }
// }

}
Loading

0 comments on commit 03294f5

Please sign in to comment.