-
Notifications
You must be signed in to change notification settings - Fork 75
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
[Team04] Stitch&스타크 - 네트워크 통신 및 드래그 앤 드롭, 스와이프 구현 - 최종 PR #210
base: team-04
Are you sure you want to change the base?
Changes from all commits
5e669dd
25ea26d
5d44ced
e8af100
f1ed922
0c6e127
161060a
50a3d75
fd30c11
4d297df
09cf433
2b86c38
aae4853
32fc36a
573f0e8
edf6f70
a8d32cb
0b0e3af
2635df0
0ad17e2
e3a2a90
e9f5045
01998b7
bffef65
1690d23
9369a9d
fe8f161
8ea5fd3
78e4762
20bb8ca
ac8a775
70169cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
package com.example.todolist.common | ||
|
||
import android.os.Build | ||
import android.text.Html | ||
import android.text.Spanned | ||
import androidx.core.text.HtmlCompat | ||
import androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY | ||
|
||
|
||
fun String.htmlToString() : String { | ||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY).toString() | ||
} else { | ||
Html.fromHtml(this).toString() | ||
} | ||
fun String.htmlToSpanned() : Spanned { | ||
return HtmlCompat.fromHtml(this, FROM_HTML_MODE_LEGACY) | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ data class History( | |
val title: String, | ||
val nowStatus: String, | ||
val beforeStatus: String?, | ||
val createData: String, | ||
val createDateTime: String, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네이밍 개선 좋습니다~ |
||
) | ||
|
||
enum class ActionType(val action: String) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.todolist.model.request | ||
|
||
data class ModifyTaskRequest( | ||
val id: Int, | ||
val title: String, | ||
val contents: String, | ||
val author: String = "Android", | ||
val status: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.todolist.model.request | ||
|
||
import com.example.todolist.model.Status | ||
|
||
data class MoveTaskRequest( | ||
val beforeStatus: Status, | ||
val nowStatus: Status | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.todolist.model.request | ||
|
||
data class TaskRequest( | ||
val title: String, | ||
val contents: String, | ||
val status: String, | ||
val author: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
package com.example.todolist.model | ||
package com.example.todolist.model.response | ||
|
||
import com.example.todolist.model.Status | ||
import com.google.gson.annotations.SerializedName | ||
|
||
data class TasksResponse( | ||
@SerializedName("todoCollection") | ||
val todo: MutableList<TaskDetailResponse>, | ||
@SerializedName("inProgressCollection") | ||
val inProgress: MutableList<TaskDetailResponse>, | ||
@SerializedName("doneCollection") | ||
val done: MutableList<TaskDetailResponse>, | ||
) | ||
|
||
data class CommonResponse( | ||
val status: Int, | ||
@SerializedName("resources") | ||
val taskDetailResponse: TaskDetailResponse, | ||
) | ||
|
||
data class TaskDetailResponse( | ||
val id: Int, | ||
val title: String, | ||
val content: String, | ||
val contents: String, | ||
val status: Status, | ||
val author: String = "Android", | ||
val updateDateTime: String? = null, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.todolist.network | ||
|
||
sealed class Result<out T : Any> { | ||
data class Success<out T : Any>(val data: T) : Result<T>() | ||
data class Error(val error: String) : Result<Nothing>() | ||
} | ||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.example.todolist.network | ||
|
||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitAPI { | ||
private const val BASE_URL = "http://www.louie-03.com/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private val okHttpClient: OkHttpClient by lazy { | ||
OkHttpClient.Builder() | ||
.addInterceptor(HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
}) | ||
.build() | ||
} | ||
|
||
private val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(okHttpClient) | ||
.build() | ||
} | ||
|
||
val service: Service by lazy { | ||
retrofit.create(Service::class.java) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.todolist.network | ||
|
||
import com.example.todolist.model.History | ||
import com.example.todolist.model.Task | ||
import com.example.todolist.model.request.ModifyTaskRequest | ||
import com.example.todolist.model.request.MoveTaskRequest | ||
import com.example.todolist.model.response.CommonResponse | ||
import com.example.todolist.model.response.TasksResponse | ||
import retrofit2.Response | ||
import retrofit2.http.* | ||
|
||
interface Service { | ||
|
||
@Headers("Content-Type: application/json") | ||
@GET("cards") | ||
suspend fun loadTasks(): Response<TasksResponse> | ||
|
||
@Headers("Content-Type: application/json") | ||
@POST("cards") | ||
suspend fun saveTask(@Body cardInfo: Task): Response<CommonResponse> | ||
|
||
@Headers("Content-Type: application/json") | ||
@PATCH("cards/{id}") | ||
suspend fun modifyTask( | ||
@Path("id") id: Int, | ||
@Body modifyTaskRequest: ModifyTaskRequest | ||
): Response<CommonResponse> | ||
|
||
@Headers("Content-Type: application/json") | ||
@GET("activity-logs") | ||
suspend fun loadHistory(): Response<List<History>> | ||
|
||
@DELETE("cards/{id}") | ||
suspend fun deleteTask(@Path("id") id: Int): Response<CommonResponse> | ||
|
||
@PATCH("cards/{id}/move") | ||
suspend fun moveTask(@Path("id") id: Int, @Body request: MoveTaskRequest): Response<CommonResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.todolist.repository | ||
|
||
import com.example.todolist.model.History | ||
import com.example.todolist.model.Status | ||
import com.example.todolist.model.Task | ||
import com.example.todolist.model.request.ModifyTaskRequest | ||
import com.example.todolist.model.request.MoveTaskRequest | ||
import com.example.todolist.model.response.CommonResponse | ||
import com.example.todolist.model.response.TaskDetailResponse | ||
import com.example.todolist.model.response.TasksResponse | ||
|
||
interface TaskDataSource { | ||
|
||
suspend fun loadTasks(): TasksResponse? | ||
|
||
suspend fun addTask(cardData: Task): CommonResponse? | ||
|
||
suspend fun modifyTask(modifyTaskRequest: ModifyTaskRequest): CommonResponse? | ||
|
||
suspend fun loadHistory(): List<History>? | ||
|
||
suspend fun deleteTask(id: Int): CommonResponse? | ||
|
||
suspend fun moveTask(request: MoveTaskRequest, id: Int): CommonResponse? | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.todolist.repository | ||
|
||
import com.example.todolist.model.History | ||
import com.example.todolist.model.Status | ||
import com.example.todolist.model.Task | ||
import com.example.todolist.model.request.ModifyTaskRequest | ||
import com.example.todolist.model.request.MoveTaskRequest | ||
import com.example.todolist.model.response.CommonResponse | ||
import com.example.todolist.model.response.TaskDetailResponse | ||
import com.example.todolist.model.response.TasksResponse | ||
import com.example.todolist.network.RetrofitAPI | ||
|
||
class TaskRemoteDataSource : TaskDataSource { | ||
|
||
override suspend fun loadTasks(): TasksResponse? { | ||
val response = RetrofitAPI.service.loadTasks() | ||
return if (response.isSuccessful) response.body() else null | ||
} | ||
|
||
override suspend fun addTask(cardData: Task): CommonResponse? { | ||
val response = RetrofitAPI.service.saveTask(cardData) | ||
return if (response.isSuccessful) response.body() else null | ||
} | ||
|
||
override suspend fun modifyTask(modifyTaskRequest: ModifyTaskRequest): CommonResponse? { | ||
val response = RetrofitAPI.service.modifyTask(modifyTaskRequest.id, modifyTaskRequest) | ||
return if (response.isSuccessful) response.body() else null | ||
} | ||
|
||
override suspend fun loadHistory(): List<History>? { | ||
val response = RetrofitAPI.service.loadHistory() | ||
return if (response.isSuccessful) response.body() else null | ||
} | ||
|
||
override suspend fun deleteTask(id: Int): CommonResponse? { | ||
val response = RetrofitAPI.service.deleteTask(id) | ||
return if (response.isSuccessful) response.body() else null | ||
} | ||
|
||
override suspend fun moveTask(request: MoveTaskRequest, id: Int): CommonResponse? { | ||
val response = RetrofitAPI.service.moveTask(id, request) | ||
return if (response.isSuccessful) response.body() else null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.example.todolist.repository | ||
|
||
import com.example.todolist.model.History | ||
import com.example.todolist.model.Status | ||
import com.example.todolist.network.Result | ||
import com.example.todolist.model.Task | ||
import com.example.todolist.model.request.ModifyTaskRequest | ||
import com.example.todolist.model.request.MoveTaskRequest | ||
import com.example.todolist.model.response.CommonResponse | ||
import com.example.todolist.model.response.TaskDetailResponse | ||
import com.example.todolist.model.response.TasksResponse | ||
|
||
class TaskRemoteRepository( | ||
private val taskRemoteDataSource: TaskRemoteDataSource, | ||
) { | ||
|
||
suspend fun loadTask(): Result<TasksResponse> { | ||
val response = taskRemoteDataSource.loadTasks() | ||
response?.let { | ||
return Result.Success(it) | ||
} | ||
return Result.Error("error") | ||
} | ||
|
||
suspend fun addTask(cardData: Task): Result<CommonResponse> { | ||
val response = taskRemoteDataSource.addTask(cardData) | ||
response?.let { | ||
return Result.Success(it) | ||
} | ||
return Result.Error("error") | ||
} | ||
|
||
suspend fun modifyTask(modifyTaskRequest: ModifyTaskRequest): Result<CommonResponse> { | ||
val response = taskRemoteDataSource.modifyTask(modifyTaskRequest) | ||
response?.let { | ||
return Result.Success(it) | ||
} | ||
return Result.Error("error") | ||
} | ||
|
||
suspend fun loadHistory(): Result<List<History>> { | ||
val response = taskRemoteDataSource.loadHistory() | ||
response?.let { | ||
return Result.Success(it) | ||
} | ||
return Result.Error("error") | ||
} | ||
|
||
suspend fun deleteTask(id: Int): Result<TaskDetailResponse> { | ||
val response = taskRemoteDataSource.deleteTask(id) | ||
response?.let { | ||
return Result.Success(it.taskDetailResponse) | ||
} | ||
return Result.Error("error") | ||
} | ||
|
||
suspend fun moveTask(task: TaskDetailResponse, status: Status): Result<TaskDetailResponse> { | ||
val response = taskRemoteDataSource.moveTask(MoveTaskRequest(task.status, status), task.id) | ||
response?.let { | ||
return Result.Success(it.taskDetailResponse) | ||
} | ||
return Result.Error("error") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 버전 분기 코드를 개선했군요!
좋습니다~
xxxCompat
클래스들이 버전 분기 처리를 해주느니 기억해두면 좋겠네요~