-
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.
Merge pull request #10 from UMC-5th-Notation/corgi
rest fix
- Loading branch information
Showing
10 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/notation/campusnote/ApiService/ApiService.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,40 @@ | ||
import com.notation.campusnote.ApiService.Datas.CrawlData | ||
import com.notation.campusnote.ApiService.Datas.LogInData | ||
import retrofit2.Call | ||
import retrofit2.http.* | ||
import com.notation.campusnote.ApiService.Datas.SignUpData | ||
import com.notation.campusnote.ApiService.Results.CrawlResult | ||
import com.notation.campusnote.ApiService.Results.LogInResult | ||
import com.notation.campusnote.ApiService.Results.RefreashTokenResult | ||
import com.notation.campusnote.ApiService.Results.SignUpResult | ||
import com.notation.campusnote.ApiService.Results.UserResult | ||
|
||
data class Post( | ||
val data: Any // 또는 다른 적절한 타입으로 지정할 수 있음 | ||
) | ||
|
||
data class SignUpRequest( | ||
val clientId: String, | ||
val name: String, | ||
val university: String, | ||
val semester: String, | ||
val img: String | ||
) | ||
|
||
interface ApiService { | ||
|
||
@POST("api/v1/crawl") | ||
fun postCrawl(@Body data: CrawlData): Call<CrawlResult> | ||
|
||
@POST("api/v1/auth/refresh-token") | ||
fun postRefreshToken(): Call<RefreashTokenResult> | ||
|
||
@POST("api/v1/auth/signUp") | ||
fun postSignUp(@Body data: SignUpData): Call<SignUpResult> | ||
|
||
@POST("api/v1/login") | ||
fun postLogin(@Body data: LogInData): Call<LogInResult> | ||
|
||
@GET("api/v1/user") | ||
fun getUser(): Call<UserResult> | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/notation/campusnote/ApiService/Datas/CrawlData.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,5 @@ | ||
package com.notation.campusnote.ApiService.Datas | ||
|
||
data class CrawlData ( | ||
val url: String | ||
) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/notation/campusnote/ApiService/Datas/LogInData.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,5 @@ | ||
package com.notation.campusnote.ApiService.Datas | ||
|
||
data class LogInData( | ||
val clientId: String | ||
) |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/notation/campusnote/ApiService/RestHelper.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,65 @@ | ||
import android.util.Log | ||
import com.notation.campusnote.ApiService.Datas.CrawlData | ||
import com.notation.campusnote.ApiService.Datas.LogInData | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import com.notation.campusnote.ApiService.Datas.SignUpData | ||
import com.notation.campusnote.ApiService.Results.CrawlResult | ||
import com.notation.campusnote.ApiService.Results.LogInResult | ||
import com.notation.campusnote.ApiService.Results.RefreashTokenResult | ||
import com.notation.campusnote.ApiService.Results.SignUpResult | ||
import com.notation.campusnote.ApiService.Results.UserResult | ||
|
||
object RestHelper { | ||
|
||
fun <T> restHelper(call: Call<T>, callback: (result: T?) -> Unit) { | ||
call.enqueue(object : Callback<T> { | ||
override fun onResponse(call: Call<T>, response: Response<T>) { | ||
if (response.isSuccessful) { | ||
val output = response.body() | ||
if (output != null) { | ||
Log.d("REST 테스팅", "REST Success, output: $output") | ||
callback(output) | ||
} else { | ||
// Handle null response | ||
Log.e("REST 테스팅", "Error: Response Body is null") | ||
callback(null) | ||
} | ||
} else { | ||
// Handle error | ||
Log.e("REST 테스팅", "Error: ${response.code()} - ${response.message()}") | ||
callback(null) | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<T>, t: Throwable) { | ||
// Handle failure | ||
Log.e("REST 테스팅", "Error: ${t.message}") | ||
callback(null) | ||
} | ||
}) | ||
} | ||
|
||
fun postKakaosignUp(data: SignUpData, callback: (result: SignUpResult?) -> Unit) { | ||
restHelper(ApiClient.apiService.postSignUp(data), callback) | ||
} | ||
|
||
fun postRefreashToken(callback: (result: RefreashTokenResult?) -> Unit) { | ||
restHelper(ApiClient.apiService.postRefreshToken(), callback) | ||
} | ||
|
||
fun postCrawl(data: CrawlData, callback: (result: CrawlResult?) -> Unit) { | ||
restHelper(ApiClient.apiService.postCrawl(data), callback) | ||
} | ||
|
||
fun postKakaologIn(data: LogInData, callback: (result: LogInResult?) -> Unit) { | ||
restHelper(ApiClient.apiService.postLogin(data), callback) | ||
} | ||
|
||
fun getUser(callback: (result: UserResult?) -> Unit) { | ||
restHelper(ApiClient.apiService.getUser(), callback) | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/notation/campusnote/ApiService/Results/CrawlResult.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,24 @@ | ||
package com.notation.campusnote.ApiService.Results | ||
|
||
data class CrawlResult( | ||
val code: String, | ||
val isSuccess: Boolean, | ||
val message: String, | ||
val result: List<Result> | ||
){ | ||
data class Result( | ||
val id: Int, | ||
val lessonDetailsDtoList: List<LessonDetailsDto>, | ||
val lessonName: String, | ||
val semester: String, | ||
val university: String | ||
) | ||
|
||
data class LessonDetailsDto( | ||
val dayOfWeek: String, | ||
val location: String, | ||
val professorName: String, | ||
val runningTime: String, | ||
val startTime: String | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/notation/campusnote/ApiService/Results/LogInResult.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,13 @@ | ||
package com.notation.campusnote.ApiService.Results | ||
|
||
data class LogInResult( | ||
val code: String, | ||
val isSuccess: Boolean, | ||
val message: String, | ||
val result: Result | ||
){ | ||
data class Result( | ||
val accessToken: String, | ||
val refreshToken: String | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/notation/campusnote/ApiService/Results/RefreashTokenResult.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,12 @@ | ||
package com.notation.campusnote.ApiService.Results | ||
|
||
data class RefreashTokenResult( | ||
val code: String, | ||
val isSuccess: Boolean, | ||
val message: String, | ||
val result: Result | ||
){ | ||
data class Result( | ||
val accessToken: String | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/notation/campusnote/ApiService/Results/SignUpResult.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,15 @@ | ||
package com.notation.campusnote.ApiService.Results | ||
|
||
|
||
data class SignUpResult( | ||
val code: String, | ||
val isSuccess: Boolean, | ||
val message: String, | ||
val result: Result | ||
){ | ||
data class Result( | ||
val accesstoken: String, | ||
val refreshtoken: String | ||
) | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/notation/campusnote/ApiService/Results/UserResult.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,8 @@ | ||
package com.notation.campusnote.ApiService.Results | ||
|
||
data class UserResult( | ||
val code: String, | ||
val isSuccess: Boolean, | ||
val message: String, | ||
val result: String | ||
) |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/notation/campusnote/ApiService/RetrofitClient.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,19 @@ | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitClient { | ||
private const val BASE_URL = "http://3.38.225.49:8080/" | ||
|
||
val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
} | ||
|
||
object ApiClient { | ||
val apiService: ApiService by lazy { | ||
RetrofitClient.retrofit.create(ApiService::class.java) | ||
} | ||
} |