-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/ssjm/sw_hackathon/goalApi/GoalApiUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.ssjm.sw_hackathon.goalApi | ||
|
||
import android.content.ContentValues | ||
import android.util.Log | ||
import com.ssjm.sw_hackathon.apiClient.ApiClient | ||
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTask | ||
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTasksResponse | ||
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTasksService | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import retrofit2.Retrofit | ||
import java.time.LocalDate | ||
|
||
// api 통신을 위한 retrofit | ||
private val retrofit: Retrofit = ApiClient.getInstance() | ||
|
||
fun apiGetDailyTasks( | ||
date: LocalDate, | ||
setDailyTask: (dailyTasks: MutableList<GetDailyTask>) -> Unit | ||
) { | ||
retrofit.create(GetDailyTasksService::class.java) | ||
.getDailyTasksGoal(date = date) | ||
.enqueue(object : Callback<GetDailyTasksResponse> { | ||
override fun onResponse(call: Call<GetDailyTasksResponse>, response: Response<GetDailyTasksResponse>) { | ||
Log.d(ContentValues.TAG, "daily 실천 사항 조회 결과 -------------------------------------------") | ||
Log.d(ContentValues.TAG, "onResponse: ${response.body().toString()}") | ||
|
||
if(response.body() != null) { | ||
setDailyTask(response.body()!!.data) | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<GetDailyTasksResponse>, t: Throwable) { | ||
Log.d(ContentValues.TAG, "daily 실천 사항 조회 결과 fail -------------------------------------------") | ||
Log.e(ContentValues.TAG, "onFailure: ${t.message}") | ||
} | ||
}) | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/ssjm/sw_hackathon/goalApi/getDailyTasks/GetDailyTasksData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ssjm.sw_hackathon.goalApi.getDailyTasks | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class GetDailyTasksResponse( | ||
@SerializedName("success") | ||
val success: Boolean, | ||
|
||
@SerializedName("code") | ||
val code: Int, | ||
|
||
@SerializedName("message") | ||
val message: String, | ||
|
||
@SerializedName("data") | ||
val data: MutableList<GetDailyTask>, | ||
) | ||
|
||
data class GetDailyTask( | ||
@SerializedName("id") | ||
val id: Int, | ||
|
||
@SerializedName("name") | ||
val name: String, | ||
|
||
@SerializedName("days") | ||
val days: MutableList<String>, | ||
|
||
@SerializedName("status") | ||
val status: String, | ||
) |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/ssjm/sw_hackathon/goalApi/getDailyTasks/GetDailyTasksService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ssjm.sw_hackathon.goalApi.getDailyTasks | ||
|
||
import com.ssjm.sw_hackathon.token.GloabalApplication | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Path | ||
import retrofit2.http.Query | ||
import java.time.LocalDate | ||
|
||
private var accessTokenValue: String = "Bearer " + GloabalApplication.prefs.getString("accessToken", "") | ||
private var refreshTokenValue: String = GloabalApplication.prefs.getString("refreshToken", "") | ||
private var goalIdValue: Int = GloabalApplication.prefs.getInt("goalId", 0) | ||
|
||
interface GetDailyTasksService { | ||
@GET("goals/{goal_id}/daily-tasks") | ||
fun getDailyTasksGoal( | ||
@Header("Authorization") authorization: String = accessTokenValue, // 로그인으로 발급받은 AccessToken: JWT {발급받은 토큰} 형태로 입력 | ||
@Header("refresh-token") refreshToken: String = refreshTokenValue, // 로그인으로 발급받은 RefreshToken | ||
@Path("goal_id") goalId: Int = goalIdValue, | ||
@Query("date") date: LocalDate | ||
): Call<GetDailyTasksResponse> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.