-
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
[Team-01][Android] Todo 화면 및 레포지토리 구현 #151
base: team-01
Are you sure you want to change the base?
Changes from 7 commits
c7119d3
fd11ce4
b596a2d
eb126f0
dd55cf2
8ff7958
0708b5a
b3ee3c3
120d3b9
4e18c86
4860095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.todo_list.data | ||
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. 패키지명이 todo_list 인가요? 특별한 이유가 없다면 소문자로 작성되는것이 컨벤션이라 맞추는게 좋을거 같습니다! 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. 변경 완료했습니다. 감사합니다! |
||
|
||
import com.example.todo_list.history.data.HistoryCard | ||
import com.example.todo_list.tasks.data.Task | ||
import retrofit2.Response | ||
|
||
interface Repository { | ||
suspend fun getHistories(): Response<List<HistoryCard>> | ||
|
||
suspend fun getAllTasks(): Response<List<Task>> | ||
|
||
suspend fun getTask(id: Int): Response<Task> | ||
|
||
suspend fun createTask(title: String, contents: String, user: String, status: String): Response<Task> | ||
|
||
suspend fun deleteTask(id: Int) | ||
|
||
suspend fun updateTask(id: Int, param: HashMap<String, String>): Response<Task> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.todo_list.data | ||
|
||
import com.example.todo_list.history.data.HistoryCard | ||
import com.example.todo_list.network.NetworkModule | ||
import com.example.todo_list.tasks.data.Task | ||
import retrofit2.Response | ||
|
||
class TasksRepository : Repository { | ||
private val network = NetworkModule.service | ||
|
||
override suspend fun getHistories(): Response<List<HistoryCard>> { | ||
return network.getHistories("histories") | ||
} | ||
|
||
override suspend fun getAllTasks(): Response<List<Task>> { | ||
return network.getAllTasks() | ||
} | ||
|
||
override suspend fun getTask(id: Int): Response<Task> { | ||
return network.getTask(id) | ||
} | ||
|
||
override suspend fun createTask( | ||
title: String, | ||
contents: String, | ||
user: String, | ||
status: String | ||
): Response<Task> { | ||
return network.createTask( | ||
title, | ||
contents, | ||
user, | ||
status | ||
) | ||
} | ||
|
||
override suspend fun deleteTask(id: Int) { | ||
network.deleteTask(id) | ||
} | ||
|
||
override suspend fun updateTask(id: Int, param: HashMap<String, String>): Response<Task> { | ||
return network.updateTask( | ||
id, | ||
param | ||
) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,12 @@ | ||
package com.example.todo_list.history.data | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class HistoryCard( | ||
val id: Int, | ||
val todo: Todo, | ||
|
||
val action: String, | ||
@SerializedName("from status") | ||
val from_status: String, | ||
@SerializedName("to status") | ||
val to_status: String, | ||
val createdDateTime: String | ||
) | ||
|
||
data class Todo( | ||
val id: Int, | ||
val title: String, | ||
val contents: String, | ||
val todoId: Int, | ||
val todoTitle: String, | ||
val user: String, | ||
val status: String, | ||
val createdDateTime: String, | ||
val updatedDateTime: String | ||
val action: String, | ||
val fromStatus: String, | ||
val toStatus: String, | ||
val createdAt: String | ||
) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.todo_list.network | ||
|
||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
class NetworkModule { | ||
companion object RetrofitApiObject { | ||
private const val BASE_URL = "https://f278a12c-c825-466b-aa01-65337bbdf28a.mock.pstmn.io/" | ||
|
||
private val retrofit = | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
val service: TodoService = retrofit.create(TodoService::class.java) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.todo_list.network | ||
|
||
import com.example.todo_list.history.data.HistoryCard | ||
import com.example.todo_list.tasks.data.Task | ||
import retrofit2.Response | ||
import retrofit2.http.* | ||
|
||
interface TodoService { | ||
|
||
@GET("api/{histories}") | ||
suspend fun getHistories( | ||
@Path("histories") variable: String | ||
): Response<List<HistoryCard>> | ||
|
||
@GET("api/todos") | ||
suspend fun getAllTasks(): Response<List<Task>> | ||
|
||
@GET("api/todos/{id}") | ||
suspend fun getTask( | ||
@Path("id") id: Int | ||
): Response<Task> | ||
|
||
@FormUrlEncoded | ||
@POST("api/todos") | ||
suspend fun createTask( | ||
@Field("title") title: String, | ||
@Field("contents") contents: String, | ||
@Field("user") user: String, | ||
@Field("status") status: String, | ||
): Response<Task> | ||
|
||
@DELETE("api/todos/{id}") | ||
suspend fun deleteTask( | ||
@Path("id") id: Int | ||
): Response<Unit> | ||
|
||
@FormUrlEncoded | ||
@PATCH("api/todos/{id}") | ||
suspend fun updateTask( | ||
@Path("id") id: Int, | ||
@FieldMap param: HashMap<String, String> | ||
): Response<Task> | ||
} |
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.
요런 기능은 별도의 함수로 묶으면 보기에 조금 더 편해서 나중에 좋은 점이 있습니다. 혹은 task 가 바뀌게 되더라도 별도의 함수로 묶어 놓으면 바꿔야 할 부분이 명확하게 보일거 같습니다. 분리된 메소드의 위치는 activity/viewmodel 두 군데가 있을텐데 어느 부분이 더 일관적일지 보셔서 추가하시면 좋을거같네요~
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.
ViewModel을 앱 전체에서 사용할 수 있도록 파일명 및 위치를 변경했습니다.
ViewModel에서 함수로 묶어 사용하는 것이 더 나을 것 같다고 판단해서 ViewModel에 구현했습니다.
감사합니다!