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

[Team-02_Android] [Linus_Funny] 4번째 PR 요청 _ API 통신 + 드래그 앤 드롭 + 활동 기록 #212

Open
wants to merge 15 commits into
base: team-02
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions android/todo-list/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}

android {
Expand Down Expand Up @@ -48,4 +49,14 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.activity:activity-ktx:1.4.0'

implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation platform("com.squareup.okhttp3:okhttp-bom:4.9.0")
implementation "com.squareup.okhttp3:okhttp"
implementation "com.squareup.okhttp3:logging-interceptor"
// Kotlin
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
// Externals
implementation 'com.google.code.gson:gson:2.9.0'
}
7 changes: 6 additions & 1 deletion android/todo-list/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.todolist">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TodoList">
android:theme="@style/Theme.TodoList"
android:usesCleartextTraffic="true"
>
<activity
android:exported="true"
android:label="@string/app_name"
Expand Down
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)
}
Comment on lines +12 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 메소드에서 Card 를 리턴해야 하는 상황이 어떻게 될까요?
아마 이 카드를 추가 할 때는 이미 new card 라는 데이터가 있어서 보기에는 같은게 아닐까? 생각이 들었습니다.


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
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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.

Loading