-
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-02_Android] [Linus_Funny] 4번째 PR 요청 _ API 통신 + 드래그 앤 드롭 + 활동 기록 #212
base: team-02
Are you sure you want to change the base?
Changes from all commits
41f60f7
68b79ee
307a0fe
0a996eb
e1b042f
0483bc7
61daba2
383d202
51b89a3
6dbfeeb
7b1207c
e772c8c
0ac7a70
bab08d9
78d3479
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.todolist.data | ||
|
||
import retrofit2.Response | ||
|
||
interface CardDataSource { | ||
|
||
suspend fun getCards(): Response<CardResponse> | ||
|
||
suspend fun addCard(newCard: NewCard): Response<Card> | ||
|
||
suspend fun deleteCard(cardId: Int) | ||
|
||
suspend fun moveCard(movedCard: MovedCard) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.todolist.data | ||
|
||
import com.example.todolist.network.ApiClient | ||
import retrofit2.Response | ||
|
||
class CardRemoteDataSource(private val apiClient: ApiClient) : CardDataSource { | ||
|
||
override suspend fun getCards(): Response<CardResponse> { | ||
return apiClient.getCards() | ||
} | ||
|
||
override suspend fun addCard(newCard: NewCard): Response<Card> { | ||
return apiClient.addCard(newCard) | ||
} | ||
|
||
override suspend fun deleteCard(cardId: Int) { | ||
apiClient.deleteCard(cardId) | ||
} | ||
|
||
override suspend fun moveCard(movedCard: MovedCard) { | ||
apiClient.moveCard(movedCard.cardId, movedCard) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.todolist.data | ||
|
||
class CardRepository(private val cardDataSource: CardRemoteDataSource) { | ||
|
||
suspend fun getCards(): Data? { | ||
val cards = cardDataSource.getCards() | ||
return cards.body()?.data | ||
} | ||
Comment on lines
+5
to
+8
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. getCards() 메소드를 사용하는 사람은 리턴값으로 List 를 기대할 확률이 높습니다. 또한, Data 는 서버쪽에서 주체를 가지는 형태로 보이는데요, Repository 등으로 레이어를 나누는 것은 서버는 어떻게 구현되는지 어떤 모양의 데이터를 사용하는지 모르게 하는것에도 목적이 있습니다. |
||
|
||
suspend fun addCard(subject: String, content: String, status: String): Card? { | ||
return cardDataSource.addCard(NewCard(subject, content, status)).body() | ||
} | ||
Comment on lines
+10
to
+12
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. 여기도 정말 리턴 타입이 꼭 필요한 상황인지 확인 부탁드립니다! |
||
|
||
suspend fun deleteCard(cardId: Int) { | ||
cardDataSource.deleteCard(cardId) | ||
} | ||
|
||
suspend fun dropCard(cardId: Int, order: Int, status: String) { | ||
cardDataSource.moveCard(MovedCard(cardId, order, status)) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.example.todolist.data | ||
|
||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.io.Serializable | ||
|
||
data class CardResponse( | ||
@SerializedName("data") | ||
val `data`: Data? | ||
) | ||
|
||
data class Data( | ||
@SerializedName("completed") | ||
val completed: Completed?, | ||
@SerializedName("ongoing") | ||
val ongoing: Ongoing?, | ||
@SerializedName("todo") | ||
val todo: Todo? | ||
) | ||
|
||
data class Todo( | ||
@SerializedName("cards") | ||
val cards: List<Card>?, | ||
@SerializedName("count") | ||
val count: Int? | ||
) | ||
|
||
data class Ongoing( | ||
@SerializedName("cards") | ||
val cards: List<Card>?, | ||
@SerializedName("count") | ||
val count: Int? | ||
) | ||
|
||
data class Completed( | ||
@SerializedName("cards") | ||
val cards: List<Card>?, | ||
@SerializedName("count") | ||
val count: Int? | ||
) | ||
|
||
data class Card( | ||
@SerializedName("cardId") | ||
val cardId: Int?, | ||
@SerializedName("content") | ||
val content: String?, | ||
@SerializedName("order") | ||
val order: Int?, | ||
@SerializedName("status") | ||
val status: String?, | ||
@SerializedName("subject") | ||
val subject: String?, | ||
@SerializedName("userId") | ||
val userId: Int? | ||
) : Serializable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.todolist.data | ||
|
||
import retrofit2.Response | ||
|
||
interface HistoryDataSource { | ||
|
||
suspend fun getHistories() : Response<HistoryResponse> | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.todolist.data | ||
|
||
import com.example.todolist.network.ApiClient | ||
import retrofit2.Response | ||
|
||
class HistoryRemoteDataSource(private val apiClient: ApiClient) : HistoryDataSource { | ||
|
||
override suspend fun getHistories(): Response<HistoryResponse> { | ||
return apiClient.getHistories() | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.todolist.data | ||
|
||
class HistoryRepository(private val historyDataSource: HistoryRemoteDataSource) { | ||
|
||
suspend fun getHistories() = | ||
historyDataSource.getHistories().body()?.histories | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.todolist.data | ||
|
||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class HistoryResponse( | ||
@SerializedName("histories") | ||
val histories: List<History>? | ||
) | ||
|
||
data class History( | ||
@SerializedName("action") | ||
val action: String?, | ||
@SerializedName("cardId") | ||
val cardId: Int?, | ||
@SerializedName("cardSubject") | ||
val cardSubject: String?, | ||
@SerializedName("createdAt") | ||
val createdAt: String?, | ||
@SerializedName("currentCardStatus") | ||
val currentCardStatus: String?, | ||
@SerializedName("id") | ||
val id: Int?, | ||
@SerializedName("prevCardStatus") | ||
val prevCardStatus: String?, | ||
@SerializedName("userId") | ||
val userId: Int? | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example.todolist.data | ||
|
||
data class MovedCard(val cardId: Int, val toOrder: Int, val toStatus: String) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.todolist.data | ||
|
||
data class NewCard( | ||
val subject: String, | ||
val content: String, | ||
val status: String, | ||
val userId: Int = 1 | ||
) |
This file was deleted.
This file was deleted.
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.
이 메소드에서 Card 를 리턴해야 하는 상황이 어떻게 될까요?
아마 이 카드를 추가 할 때는 이미 new card 라는 데이터가 있어서 보기에는 같은게 아닐까? 생각이 들었습니다.