Skip to content

Commit

Permalink
✨ feature : Setting User Info API module 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjjungg committed Jan 21, 2023
1 parent 3d77f11 commit 34689f5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/src/main/java/com/shootit/greme/model/SettingServerModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.shootit.greme.model

import com.google.gson.annotations.SerializedName

data class UserCurrentInfo(
@SerializedName("username")
val username: String,
@SerializedName("imageUrl")
val imageUrl: String,
@SerializedName("interestType")
val interestType: List<Int>,
@SerializedName("genderType")
val genderType: Int,
@SerializedName("area")
val area: String,
@SerializedName("purpose")
val purpose: String,
)

data class UserInterestAndGenderInfo(
@SerializedName("interestType")
val interestType: List<Int>,
@SerializedName("genderType")
val genderType: Int
)

data class UserAreaAndPurposeInfo(
@SerializedName("area")
val area: String,
@SerializedName("purpose")
val purpose: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ object ConnectionObject {
val getSignOutRetrofitService: SignOutInterface by lazy {
getRetrofit.create(SignOutInterface::class.java)
}
val getSettingRetrofitService: SettingInterface by lazy {
getRetrofit.create(SettingInterface::class.java)
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/shootit/greme/network/SettingInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.shootit.greme.network

import com.shootit.greme.model.UserAreaAndPurposeInfo
import com.shootit.greme.model.UserCurrentInfo
import com.shootit.greme.model.UserInterestAndGenderInfo
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET

interface SettingInterface {

// get current profile
@GET("/user/profile")
fun getCurrentProfile() : Response<UserCurrentInfo>

// set interest, gender
@GET("/user/profile1")
fun setUserInterestAndGender(@Body data: UserInterestAndGenderInfo) : Response<Void>

// set area, purpose
@GET("/user/profile2")
fun setUserAreaAndPurpose(@Body data: UserAreaAndPurposeInfo) : Response<Void>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.shootit.greme.repository

import android.util.Log
import com.shootit.greme.model.ChallengeActivityModel
import com.shootit.greme.model.UserAreaAndPurposeInfo
import com.shootit.greme.model.UserCurrentInfo
import com.shootit.greme.model.UserInterestAndGenderInfo
import com.shootit.greme.network.ConnectionObject

class SettingRepository {

companion object {
private var instance: SettingRepository? = null

fun getInstance(): SettingRepository? {
if(instance == null) instance = SettingRepository()
return instance
}
}

suspend fun getCurrentProfile(): UserCurrentInfo? {
val response = ConnectionObject
.getSettingRetrofitService.getCurrentProfile()
return if (response.isSuccessful) {
response.body() as UserCurrentInfo
} else {
Log.d("challenge server err", response.errorBody()?.string().toString())
null
}
}

suspend fun setUserInterestAndGender(userInterestAndGenderInfo: UserInterestAndGenderInfo): Boolean {
val response = ConnectionObject
.getSettingRetrofitService.setUserInterestAndGender(userInterestAndGenderInfo)
return response.isSuccessful
}

suspend fun setUserAreaAndPurpose(userAreaAndPurposeInfo: UserAreaAndPurposeInfo): Boolean {
val response = ConnectionObject
.getSettingRetrofitService.setUserAreaAndPurpose(userAreaAndPurposeInfo)
return response.isSuccessful
}
}

0 comments on commit 34689f5

Please sign in to comment.