Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 태그 추가 뷰 / 태그 리스트 GET #87

Merged
merged 6 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.photosurfer.android.di

import com.photosurfer.android.data.remote.datasource.RemotePushSettingDataSource
import com.photosurfer.android.data.remote.datasource.RemotePushSettingDataSourceImpl
import com.photosurfer.android.data.remote.datasource.RemoteAlarmListDataSource
import com.photosurfer.android.data.remote.datasource.RemoteAlarmListDataSourceImpl
import com.photosurfer.android.data.remote.datasource.*
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -18,7 +15,20 @@ interface RemoteDataSourceModule {
@Singleton
fun bindsRemotePushSettingDataSource(source: RemotePushSettingDataSourceImpl): RemotePushSettingDataSource

@Binds
@Singleton
fun bindRemoteChooseTagDataSource(source: RemoteChooseTagDataSourceImpl): RemoteChooseTagDataSource

@Binds
@Singleton
fun bindsRemoteUrgentAlarmListDataSource(source: RemoteUrgentAlarmListDataSourceImpl): RemoteUrgentAlarmListDataSource

@Binds
@Singleton
fun bindsRemoteTagListDataSource(source: RemoteTagListDataSourceImpl): RemoteTagListDataSource

@Binds
@Singleton
fun bindsRemoteAlarmListDataSource(source: RemoteAlarmListDataSourceImpl): RemoteAlarmListDataSource

}
13 changes: 13 additions & 0 deletions app/src/main/java/com/photosurfer/android/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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.data.repository.UrgentAlarmListRepositoryImpl
import com.photosurfer.android.data.repository.AlarmListRepositoryImpl
import com.photosurfer.android.domain.repository.PushSettingRepository
import com.photosurfer.android.domain.repository.AlarmListRepository
Expand All @@ -18,7 +21,17 @@ interface RepositoryModule {
@Singleton
fun bindsPushSettingRepository(repository: PushSettingRepositoryImpl): PushSettingRepository

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


@Binds
@Singleton
fun bindsUrgentAlarmListRepository(repository: UrgentAlarmListRepositoryImpl): UrgentAlarmListRepository

@Binds
@Singleton
fun bindsAlarmListRepository(repository: AlarmListRepositoryImpl): AlarmListRepository

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.intellij.lang.annotations.PrintFormat
import retrofit2.Retrofit
import retrofit2.create
import javax.inject.Singleton

@Module
Expand All @@ -23,6 +25,11 @@ object RetrofitServiceModule {
fun providesUrgentAlarmListService(retrofit: Retrofit): UrgentAlarmListService =
retrofit.create(UrgentAlarmListService::class.java)

@Provides
@Singleton
fun providesTagListService(retrofit: Retrofit): ChooseTagService =
retrofit.create(ChooseTagService::class.java)

@Provides
@Singleton
fun providesUpComingAlarmListService(retrofit: Retrofit): UpComingAlarmListService =
Expand All @@ -37,4 +44,5 @@ object RetrofitServiceModule {
@Singleton
fun providesSpecificAlarmService(retrofit: Retrofit): SpecificAlarmService =
retrofit.create(SpecificAlarmService::class.java)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.photosurfer.android.core.util

import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.DocumentsContract
import android.provider.MediaStore
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

class MutiPartResolver {
fun createImgMultiPart(uri: Uri, context: Context): MultipartBody.Part {
val file = File((getPath(context, uri).toString()))
val surveyBody = file.asRequestBody("image/*".toMediaTypeOrNull())
return MultipartBody.Part.createFormData("image", file.name, surveyBody)
}

private fun getPath(context: Context, uri: Uri): String? {
val docId = DocumentsContract.getDocumentId(uri)
val split = docId.split(":".toRegex()).toTypedArray()
val contentUri: Uri? = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
val selection = "_id=?"
val selectionArgs = arrayOf(split[1])
return getDataColumn(context, contentUri!!, selection, selectionArgs)
}

private fun getDataColumn(
context: Context,
uri: Uri,
selection: String?,
selectionArgs: Array<String>?
): String? {
var cursor: Cursor? = null
val column = "_data"
val projection = arrayOf(column)
try {
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
if (cursor != null && cursor.moveToFirst()) {
val columnIndex: Int = cursor.getColumnIndexOrThrow(column)
return cursor.getString(columnIndex)
}
} finally {
cursor?.close()
}
return null
}
}
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,10 @@
package com.photosurfer.android.data.remote.datasource

import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.model.response.BaseResponse
import com.photosurfer.android.data.remote.model.response.TagListResponse

interface RemoteTagListDataSource {

suspend fun getTagList(): NetworkState<BaseResponse<TagListResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.photosurfer.android.data.remote.datasource

import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.model.response.BaseResponse
import com.photosurfer.android.data.remote.model.response.TagListResponse
import com.photosurfer.android.data.remote.service.ChooseTagService
import javax.inject.Inject

class RemoteTagListDataSourceImpl @Inject constructor(
private val chooseTagListService: ChooseTagService
): RemoteTagListDataSource {
override suspend fun getTagList(): NetworkState<BaseResponse<TagListResponse>> =
chooseTagListService.getTagList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.photosurfer.android.data.remote.mapper

import com.photosurfer.android.domain.entity.TagIdNameType
import com.photosurfer.android.domain.entity.TagNameType
import javax.inject.Inject

class TagMapper @Inject constructor() {

}
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,31 @@
package com.photosurfer.android.data.remote.model.response


import com.photosurfer.android.domain.entity.TagInfo
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TagListResponse(
@SerialName("often")
val often: Often,
@SerialName("recent")
val recent: Recent,
@SerialName("platform")
val platform: Platform
)

data class Often(
@SerialName("tags")
val tags: List<TagInfo>
)

data class Recent(
@SerialName("tags")
val tags: List<TagInfo>
)

data class Platform(
@SerialName("tags")
val tags: List<TagInfo>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 com.photosurfer.android.data.remote.model.response.TagListResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST

interface ChooseTagService {
@Multipart
@POST("photo/")
suspend fun postTag(
@Body body: ChooseTagRequest
): NetworkState<BaseResponse<ChooseTagResponse>>

/*
suspend fun postTag(
@Part image: MultipartBody.Part?,
@Part("contents") contents: List<TagNameType>
): NetworkState<BaseResponse<ChooseTagResponse>>
*/

@GET("tag/main")
suspend fun getTagList(): NetworkState<BaseResponse<TagListResponse>>
}
Loading