Skip to content

Commit

Permalink
Merge pull request #10 from UMC-5th-Notation/corgi
Browse files Browse the repository at this point in the history
rest fix
  • Loading branch information
Dev-Corgi authored Feb 5, 2024
2 parents 8bc3164 + fdde4ee commit b8535d5
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 0 deletions.
40 changes: 40 additions & 0 deletions app/src/main/java/com/notation/campusnote/ApiService/ApiService.kt
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>
}
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
)
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 app/src/main/java/com/notation/campusnote/ApiService/RestHelper.kt
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)
}


}
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
)
}
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
)
}
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
)
}
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
)
}

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
)
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)
}
}

0 comments on commit b8535d5

Please sign in to comment.