-
Notifications
You must be signed in to change notification settings - Fork 3
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 #6 from Rifzzu/main
change auth + fix UI
- Loading branch information
Showing
62 changed files
with
1,315 additions
and
159 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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/example/buzzwiseapp/data/LoginPayload.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,11 @@ | ||
package com.example.buzzwiseapp.data | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class LoginPayload( | ||
@field:SerializedName("email") | ||
val email: String, | ||
|
||
@field:SerializedName("password") | ||
val password: String | ||
) |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/example/buzzwiseapp/data/RegisterPayload.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,14 @@ | ||
package com.example.buzzwiseapp.data | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class RegisterPayload( | ||
@field:SerializedName("name") | ||
val name: String, | ||
|
||
@field:SerializedName("email") | ||
val email: String, | ||
|
||
@field:SerializedName("password") | ||
val password: String | ||
) |
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
18 changes: 15 additions & 3 deletions
18
app/src/main/java/com/example/buzzwiseapp/data/api/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 |
---|---|---|
@@ -1,19 +1,31 @@ | ||
package com.example.buzzwiseapp.data.api | ||
|
||
import com.example.buzzwiseapp.data.LoginPayload | ||
import com.example.buzzwiseapp.data.RegisterPayload | ||
import com.example.buzzwiseapp.data.response.DataItem | ||
import com.example.buzzwiseapp.data.response.JobDetailResponse | ||
import com.example.buzzwiseapp.data.response.JobResponse | ||
import com.example.buzzwiseapp.data.response.LoginResponse | ||
import okhttp3.ResponseBody | ||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
|
||
interface ApiService { | ||
|
||
@GET("jobs/alljobs") | ||
fun getAllJobs(): Call<JobResponse> | ||
|
||
@GET("/jobs/{userId}") | ||
@GET("jobs/job/{userId}") | ||
fun getDetailStory( | ||
@Path("userId") userId: String | ||
): Call<JobDetailResponse> | ||
@POST("/api/users/signUp") | ||
fun registerUser( | ||
@Body payload: RegisterPayload | ||
): Call<ResponseBody> | ||
@POST("/api/users/signIn") | ||
fun loginUser( | ||
@Body payload: LoginPayload | ||
): Call<LoginResponse> | ||
} |
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/example/buzzwiseapp/data/model/UserModel.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,6 @@ | ||
package com.example.buzzwiseapp.data.model | ||
|
||
data class UserModel( | ||
val token: String, | ||
val isLogin: Boolean | ||
) |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/example/buzzwiseapp/data/model/UserPreference.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,63 @@ | ||
package com.example.buzzwiseapp.data.model | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.example.buzzwiseapp.data.api.ApiConfig | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class UserPreference private constructor(private val dataStore: DataStore<Preferences>){ | ||
//Get User | ||
fun getUser(): Flow<UserModel> { | ||
return dataStore.data.map { preferences -> | ||
UserModel( | ||
preferences[TOKEN] ?:"", | ||
preferences[STATE_KEY] ?: false | ||
) | ||
} | ||
} | ||
|
||
//Save User Data | ||
suspend fun saveUser(user: UserModel) { | ||
dataStore.edit { preferences -> | ||
preferences[TOKEN] = user.token | ||
preferences[STATE_KEY] = user.isLogin | ||
} | ||
} | ||
|
||
//Change State | ||
suspend fun login() { | ||
dataStore.edit { preferences -> | ||
preferences[STATE_KEY] = true | ||
} | ||
} | ||
|
||
suspend fun logout() { | ||
dataStore.edit { preferences -> | ||
preferences[STATE_KEY] = false | ||
preferences[TOKEN] = "" | ||
} | ||
} | ||
|
||
companion object { | ||
@Volatile | ||
private var INSTANCE: UserPreference? = null | ||
|
||
private val TOKEN = stringPreferencesKey("password") | ||
private val STATE_KEY = booleanPreferencesKey("state") | ||
|
||
fun getInstance(dataStore: DataStore<Preferences>): UserPreference { | ||
return INSTANCE ?: synchronized(this) { | ||
val instance = UserPreference(dataStore) | ||
INSTANCE = instance | ||
instance | ||
} | ||
} | ||
fun setToken(token: String) { | ||
ApiConfig.setToken(token) | ||
} | ||
} | ||
} |
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
132 changes: 132 additions & 0 deletions
132
app/src/main/java/com/example/buzzwiseapp/data/response/LoginResponse.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,132 @@ | ||
package com.example.buzzwiseapp.data.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class LoginResponse( | ||
|
||
@field:SerializedName("data") | ||
val data: Data? = null, | ||
|
||
@field:SerializedName("message") | ||
val message: String? = null | ||
) | ||
|
||
data class MultiFactor( | ||
|
||
@field:SerializedName("enrolledFactors") | ||
val enrolledFactors: List<Any?>? = null | ||
) | ||
|
||
data class StsTokenManager( | ||
|
||
@field:SerializedName("apiKey") | ||
val apiKey: String? = null, | ||
|
||
@field:SerializedName("expirationTime") | ||
val expirationTime: Long? = null, | ||
|
||
@field:SerializedName("accessToken") | ||
val accessToken: String? = null, | ||
|
||
@field:SerializedName("refreshToken") | ||
val refreshToken: String? = null | ||
) | ||
|
||
data class User( | ||
|
||
@field:SerializedName("apiKey") | ||
val apiKey: String? = null, | ||
|
||
@field:SerializedName("providerData") | ||
val providerData: List<ProviderDataItem?>? = null, | ||
|
||
@field:SerializedName("displayName") | ||
val displayName: String? = null, | ||
|
||
@field:SerializedName("appName") | ||
val appName: String? = null, | ||
|
||
@field:SerializedName("redirectEventId") | ||
val redirectEventId: Any? = null, | ||
|
||
@field:SerializedName("authDomain") | ||
val authDomain: String? = null, | ||
|
||
@field:SerializedName("uid") | ||
val uid: String? = null, | ||
|
||
@field:SerializedName("photoURL") | ||
val photoURL: Any? = null, | ||
|
||
@field:SerializedName("emailVerified") | ||
val emailVerified: Boolean? = null, | ||
|
||
@field:SerializedName("createdAt") | ||
val createdAt: String? = null, | ||
|
||
@field:SerializedName("isAnonymous") | ||
val isAnonymous: Boolean? = null, | ||
|
||
@field:SerializedName("stsTokenManager") | ||
val stsTokenManager: StsTokenManager? = null, | ||
|
||
@field:SerializedName("phoneNumber") | ||
val phoneNumber: Any? = null, | ||
|
||
@field:SerializedName("lastLoginAt") | ||
val lastLoginAt: String? = null, | ||
|
||
@field:SerializedName("multiFactor") | ||
val multiFactor: MultiFactor? = null, | ||
|
||
@field:SerializedName("tenantId") | ||
val tenantId: Any? = null, | ||
|
||
@field:SerializedName("email") | ||
val email: String? = null | ||
) | ||
|
||
data class AdditionalUserInfo( | ||
|
||
@field:SerializedName("providerId") | ||
val providerId: String? = null, | ||
|
||
@field:SerializedName("isNewUser") | ||
val isNewUser: Boolean? = null | ||
) | ||
|
||
data class Data( | ||
|
||
@field:SerializedName("credential") | ||
val credential: Any? = null, | ||
|
||
@field:SerializedName("additionalUserInfo") | ||
val additionalUserInfo: AdditionalUserInfo? = null, | ||
|
||
@field:SerializedName("operationType") | ||
val operationType: String? = null, | ||
|
||
@field:SerializedName("user") | ||
val user: User? = null | ||
) | ||
|
||
data class ProviderDataItem( | ||
|
||
@field:SerializedName("uid") | ||
val uid: String? = null, | ||
|
||
@field:SerializedName("photoURL") | ||
val photoURL: Any? = null, | ||
|
||
@field:SerializedName("phoneNumber") | ||
val phoneNumber: Any? = null, | ||
|
||
@field:SerializedName("displayName") | ||
val displayName: String? = null, | ||
|
||
@field:SerializedName("providerId") | ||
val providerId: String? = null, | ||
|
||
@field:SerializedName("email") | ||
val email: String? = null | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/example/buzzwiseapp/data/response/RegisterResponse.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,9 @@ | ||
package com.example.buzzwiseapp.data.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class RegisterResponse( | ||
|
||
@field:SerializedName("error") | ||
val error: String | ||
) |
Oops, something went wrong.