Skip to content

Commit

Permalink
[ADD] api 미완성
Browse files Browse the repository at this point in the history
  • Loading branch information
2xHjin committed Jun 10, 2023
1 parent c40a33e commit 0932e15
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/nbit/Idear/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.view.GravityCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.footstep.dangbal.kotlin.src.main.map.ApiService
import com.footstep.dangbal.kotlin.src.main.map.RetrofitInterface
import com.nbit.Idear.databinding.ActivityMainBinding
import com.nbit.Idear.databinding.MainIncludeDrawerBinding
import com.nbit.Idear.home.ProxyWriteAdapter
import com.nbit.Idear.home.ProxyWriteData
import com.nbit.Idear.home.WriteSubData
import com.nbit.Idear.mypage.MyPageActivity
import com.nbit.Idear.write.WriteActivity
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

// 메인 페이지
class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -107,5 +111,15 @@ class MainActivity : AppCompatActivity() {
val intent = Intent(this, WriteActivity::class.java)
startActivity(intent)
}

//val retrofit = Retrofit.Builder()
// .baseUrl("https://api.example.com/") // 서버의 baseUrl을 설정합니다.
// .addConverterFactory(GsonConverterFactory.create()) // JSON 데이터 변환을 위한 Gson 변환기를 추가합니다.
// .build()

// val apiService = retrofit.create(RetrofitInterface::class.java)
val apiService = RetrofitInterface.create()


}
}
105 changes: 105 additions & 0 deletions app/src/main/java/com/nbit/Idear/home/ApiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.footstep.dangbal.kotlin.src.main.map

import android.util.Log
import com.naver.maps.map.overlay.Marker
import com.footstep.dangbal.kotlin.config.ApplicationClass
import com.footstep.dangbal.kotlin.src.main.map.model.AllResponse
import com.footstep.dangbal.kotlin.src.main.map.model.CityResponse
import com.footstep.dangbal.kotlin.src.main.map.model.PopupResponse
import com.footstep.dangbal.kotlin.src.main.map.model.SpecificFstResponse

class ApiService(val mapFragmentInterface: MapFragment) {
//val accessToken="Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImZvb3RzdGVwQG5hdmVyLmNvbSIsImlhdCI6MTY3NDkxNDc2NiwiZXhwIjoxNjc1MjE3MTY2fQ.KxwX1Q0o-omU1rRIiUJBd9gLPbTRVciP_9g_sklW1Bk"
suspend fun tryGetMapFootStepList(){
var return_map=HashMap<Int,Marker>()
// ApplicationClass.sSharedPreferences.edit().putString(X_ACCESS_TOKEN, accessToken).apply()

val mapRetrofitInterface=ApplicationClass.sRetrofit.create(RetrofitInterface::class.java)

try{
val response=mapRetrofitInterface.getMapFootStepList()
Log.d("FootStepList", "tryGetMapFootStepList 되긴하니?")

if(response!=null)
mapFragmentInterface.onGetMapFootStepListSuccess(response as AllResponse)
else
Log.d("FootStepList", "맵 서비스 List에서의 결과 : ${response.toString()}")
}
catch (e: Exception) {
Log.d("FootStepList", "onGetMapFootStepListFailure "+e.message.toString())

mapFragmentInterface.onGetMapFootStepListFailure(e.message ?: "통신 오류")
}
}

suspend fun tryGetMapFootStepPopup(place_id:Int){
// Log.d("FootStepList", "tryGetMapFootStepPopup 진입")

// ApplicationClass.sSharedPreferences.edit().putString(X_ACCESS_TOKEN, accessToken).apply()

val mapRetrofitInterface=ApplicationClass.sRetrofit.create(RetrofitInterface::class.java)
Log.d("FootStepList", "tryGetMapFootStepPopup 안쪽직전진입")

try{
val response=mapRetrofitInterface.getMapFootStepPopup(place_id)
Log.d("FootStepList", "tryGetMapFootStepPopup 되긴하니?")

if(response!=null) {
mapFragmentInterface.onGetMapFootStepPopupSuccess(
response as PopupResponse,
place_id
)
}
else
Log.d("FootStepList", "맵 서비스 Popup에서의 결과 : ${response.toString()}")
}
catch (e: Exception) {
Log.d("FootStepList", "onGetMapFootStepPopupFailure api"+e.message.toString())

mapFragmentInterface.onGetMapFootStepPopupFailure(e.message ?: "통신 오류")
}
}

suspend fun tryGetMapFootStepSpecific(start_date :String,ene_date:String){
val mapRetrofitInterface=ApplicationClass.sRetrofit.create(RetrofitInterface::class.java)
Log.d("FootStepList2", "tryGetMapFootStepSpecific 안쪽직전진입")

try{
val response=mapRetrofitInterface.getMapFootStepSpecific(start_date,ene_date)
Log.d("FootStepList", "tryGetMapFootStepPopup 되긴하니?")

if(response!=null) {
mapFragmentInterface.onGetMapFootStepSpecificSuccess(response as SpecificFstResponse)
}
else
Log.d("FootStepList", "맵 서비스 Specific에서의 결과 : ${response.toString()}")
}
catch (e: Exception) {
Log.d("FootStepList", "onGetMapFootStepSpecificFailure"+e.message.toString())

mapFragmentInterface.onGetMapFootStepSpecificFailure(e.message ?: "통신 오류")
}
}

suspend fun tryGetMapFootStepCity(city :String){
// ApplicationClass.sSharedPreferences.edit().putString(X_ACCESS_TOKEN, accessToken).apply()

val mapRetrofitInterface=ApplicationClass.sRetrofit.create(RetrofitInterface::class.java)

try{
val response=mapRetrofitInterface.getMapFootStepCity(city)
Log.d("FootStepList", "tryGetMapFootStepCity 되긴하니?")

if(response!=null)
mapFragmentInterface.onGetMapFootStepCitySuccess(response as CityResponse)
else
Log.d("FootStepList", "맵 서비스 City에서의 결과 : ${response.toString()}")
}
catch (e: Exception) {
Log.d("FootStepList", "tryGetMapFootStepCity onGetMapFootStepListFailure "+e.message.toString())

mapFragmentInterface.onGetMapFootStepCityFailure(e.message ?: "통신 오류")
}
}

}
35 changes: 35 additions & 0 deletions app/src/main/java/com/nbit/Idear/home/RetrofitInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.footstep.dangbal.kotlin.src.main.map

import com.footstep.dangbal.kotlin.src.main.map.model.*
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.*

interface RetrofitInterface {

@GET("/footstep/all")
suspend fun getMapFootStepList() : AllResponse

@GET("/footstep/{place-id}")
suspend fun getMapFootStepPopup(@Path("place-id") place_id : Int) : PopupResponse

@GET("/footstep/specific/{start-date}/{end-date}")
suspend fun getMapFootStepSpecific(@Path("start-date") start_date : String, @Path("end-date") end_date:String) : SpecificFstResponse

@GET("/footstep/city/{city-name}")
suspend fun getMapFootStepCity(@Path("city-name")city: String) : CityResponse

@GET("users/{user}")
fun getUser(@Path("user") username: String): Call<User>

companion object {
fun create(): ApiService {
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()

return retrofit.create(ApiService::class.java)
}
}
}

0 comments on commit 0932e15

Please sign in to comment.