Quellcode durchsuchen

Added get-user api method, renamed UserFull to User class

Vadik Sirekanyan vor 7 Jahren
Ursprung
Commit
fcfc84b33b

+ 1 - 1
app/src/main/java/me/vadik/knigopis/feature/profile/ProfileActivity.kt

@@ -84,7 +84,7 @@ class ProfileActivity : AppCompatActivity() {
             })
     }
 
-    private fun onRefreshProfile(user: Credentials.UserFull) {
+    private fun onRefreshProfile(user: User) {
         userId = user.id
         profileUrl = user.fixedProfile
         profileNickname.text = user.nickname.orEmpty()

+ 5 - 6
app/src/main/java/me/vadik/knigopis/repository/api/Endpoint.kt

@@ -60,18 +60,17 @@ interface Endpoint {
     fun getLatestBooksWithNotes(): Single<Map<String, Note>>
 
     @GET("subscriptions")
-    fun getSubscriptions(
-        @Query("access-token") accessToken: String
-    ): Single<List<Subscription>>
+    fun getSubscriptions(@Query("access-token") accessToken: String): Single<List<Subscription>>
 
     @GET("users/current")
-    fun getProfile(
-        @Query("access-token") accessToken: String
-    ): Single<Credentials.UserFull>
+    fun getProfile(@Query("access-token") accessToken: String): Single<User>
 
     @GET("users/{id}/books")
     fun getUserBooks(@Path("id") userId: String): Single<List<FinishedBook>>
 
+    @GET("users/{id}")
+    fun getUser(@Path("id") userId: String): Single<User>
+
     @PUT("users/{id}")
     fun updateProfile(
         @Path("id") userId: String,

+ 2 - 22
app/src/main/java/me/vadik/knigopis/repository/model/Credentials.kt

@@ -1,29 +1,9 @@
 package me.vadik.knigopis.repository.model
 
 import com.google.gson.annotations.SerializedName
-import java.util.*
 
 class Credentials(
     @SerializedName("access-token")
     val accessToken: String,
-    val user: UserFull
-) {
-
-    class UserFull(
-        val id: String,
-        val lang: String,
-        val nickname: String?,
-        val photo: String,
-        val profile: String,
-        val identity: String,
-        val booksCount: Int,
-        val subscriptions: Map<String, Int>?,
-        val createdAt: Date,
-        val updatedAt: Date
-    ) {
-        // TODO https://trello.com/c/UymHYoPK
-        val fixedCreatedAt get() = Date(createdAt.time + TimeZone.getDefault().rawOffset)
-        val fixedUpdatedAt get() = Date(updatedAt.time + TimeZone.getDefault().rawOffset)
-        val fixedProfile get() = "http://www.knigopis.com/#/user/books?u=$id"
-    }
-}
+    val user: User
+)

+ 21 - 0
app/src/main/java/me/vadik/knigopis/repository/model/User.kt

@@ -0,0 +1,21 @@
+package me.vadik.knigopis.repository.model
+
+import java.util.*
+
+class User(
+    val id: String,
+    val lang: String,
+    val nickname: String?,
+    val photo: String,
+    val profile: String,
+    val identity: String,
+    val booksCount: Int,
+    val subscriptions: Map<String, Int>?,
+    val createdAt: Date,
+    val updatedAt: Date
+) {
+    // TODO https://trello.com/c/UymHYoPK
+    val fixedCreatedAt get() = Date(createdAt.time + TimeZone.getDefault().rawOffset)
+    val fixedUpdatedAt get() = Date(updatedAt.time + TimeZone.getDefault().rawOffset)
+    val fixedProfile get() = "http://www.knigopis.com/#/user/books?u=$id"
+}