Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Merge pull request #16 from fictadvisor/user_api
Browse files Browse the repository at this point in the history
User api
  • Loading branch information
vita133 authored Apr 11, 2024
2 parents e9a1e39 + 58aa5f0 commit 1558b5e
Show file tree
Hide file tree
Showing 27 changed files with 755 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.fictadvisor.android.data.dto.user

data class AddContactBody(
val name: ContactType,
val displayName: String,
val link: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.fictadvisor.android.data.dto.user

data class ChangeAvatarResponse(
val id: String,
val email: String,
val username: String,
val telegramId: Long,
val avatar: String,
val state: UserGroupState
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fictadvisor.android.data.dto.user

data class ChangeInfoBody(
val firstName: String?,
val lastName: String?,
val middleName: String?,
val groupId: String?,
val state: UserGroupState?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fictadvisor.android.data.dto.user

data class ChangeRoleBody(
val roleId: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.fictadvisor.android.data.dto.user

data class ChangeUserBody(
val email: String?,
val username: String?,
val state: UserGroupState?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fictadvisor.android.data.dto.user

data class Contact(
val link: String,
val id: String,
val name: ContactType,
val displayName: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fictadvisor.android.data.dto.user

enum class ContactType {
YOUTUBE,
DISCORD,
TELEGRAM,
INSTAGRAM,
FACEBOOK,
GITHUB,
TWITTER,
MAIL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fictadvisor.android.data.dto.user

data class GetContactsResponse(
val contacts: List<Contact>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fictadvisor.android.data.dto.user

data class GetSelectiveDisciplinesBySemesterResponse(
val selective: List<UserSelective>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fictadvisor.android.data.dto.user

data class GetSelectiveDisciplinesResponse(
val availableSelectiveAmount: Int,
val year: Int,
val semester: Int,
val remainingSelective: List<UserRemainingSelective>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fictadvisor.android.data.dto.user

data class GetSelectiveResponse(
val disciplines: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fictadvisor.android.data.dto.user

data class PostSelectiveDisciplinesBody(
val disciplines: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.fictadvisor.android.data.dto.user

data class RequestNewGroupBody(
val groupId: String,
val isCaptain: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.fictadvisor.android.data.dto.user

data class SimplifiedUser(
val id: String,
val email: String,
val username: String,
val telegramId: Long?,
val avatar: String?,
val state: UserGroupState
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fictadvisor.android.data.dto.user

data class UserDTOResponse(
val id: String,
val firstName: String,
val middleName: String,
val lastName: String,
val state: UserGroupState,
val username: String,
val email: String,
val avatar: String,
val telegramId: Long,
val group: UserGroup
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fictadvisor.android.data.dto.user

data class UserGroup(
val id: String,
val code: String,
val role: UserGroupRole?,
val state: UserGroupState
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.fictadvisor.android.data.dto.user

enum class UserGroupRole {
CAPTAIN,
MODERATOR,
STUDENT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.fictadvisor.android.data.dto.user

enum class UserGroupState {
APPROVED,
DECLINED,
PENDING
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.fictadvisor.android.data.dto.user

data class UserRemainingSelective(
val disciplineId: String,
val subjectName: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fictadvisor.android.data.dto.user

data class UserSelective(
val semester: Int,
val year: Int,
val disciplines: List<String>,
val amount: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.fictadvisor.android.data.dto.user

data class VerifyStudentBody(
val state: UserGroupState,
val isCaptain: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fictadvisor.android.data.dto.user

data class VerifyStudentResponse(
val students: List<UserDTOResponse>
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.fictadvisor.android.data.remote
import com.fictadvisor.android.data.remote.api.AuthApi
import com.fictadvisor.android.data.remote.api.GroupApi
import com.fictadvisor.android.data.remote.api.ScheduleApi
import com.fictadvisor.android.data.remote.api.UserApi
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -73,4 +74,10 @@ object RetrofitClient {
.create(ScheduleApi::class.java)
}

val userApi: UserApi by lazy {
retrofitClient
.build()
.create(UserApi::class.java)
}

}
137 changes: 137 additions & 0 deletions app/src/main/java/com/fictadvisor/android/data/remote/api/UserApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.fictadvisor.android.data.remote.api

import com.fictadvisor.android.data.dto.TelegramDTO
import com.fictadvisor.android.data.dto.user.AddContactBody
import com.fictadvisor.android.data.dto.user.ChangeAvatarResponse
import com.fictadvisor.android.data.dto.user.ChangeInfoBody
import com.fictadvisor.android.data.dto.user.UserDTOResponse
import com.fictadvisor.android.data.dto.user.ChangeRoleBody
import com.fictadvisor.android.data.dto.user.ChangeUserBody
import com.fictadvisor.android.data.dto.user.Contact
import com.fictadvisor.android.data.dto.user.GetContactsResponse
import com.fictadvisor.android.data.dto.user.GetSelectiveDisciplinesBySemesterResponse
import com.fictadvisor.android.data.dto.user.GetSelectiveDisciplinesResponse
import com.fictadvisor.android.data.dto.user.GetSelectiveResponse
import com.fictadvisor.android.data.dto.user.PostSelectiveDisciplinesBody
import com.fictadvisor.android.data.dto.user.RequestNewGroupBody
import com.fictadvisor.android.data.dto.user.SimplifiedUser
import com.fictadvisor.android.data.dto.user.VerifyStudentBody
import com.fictadvisor.android.data.dto.user.VerifyStudentResponse
import okhttp3.MultipartBody
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

interface UserApi {
@GET("/v2/users/{userId}")
suspend fun getUser(
@Header("Authorization") token: String,
@Path("userId") userId: String
): Response<SimplifiedUser>

@PATCH("/v2/users/{userId}")
suspend fun editUser(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: ChangeUserBody
): Response<SimplifiedUser>

@PATCH("/v2/users/{userId}/student")
suspend fun changeInfo(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: ChangeInfoBody
): Response<UserDTOResponse>

@POST("/v2/users/{userId}/telegram")
suspend fun linkTelegram(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: TelegramDTO
): Response<UserDTOResponse>

@POST("/v2/users/{userId}/contacts")
suspend fun addContact(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: AddContactBody
): Response<Contact>

@GET("/v2/users/{userId}/contacts")
suspend fun getContacts(
@Header("Authorization") token: String,
@Path("userId") userId: String
): Response<GetContactsResponse>

@DELETE("/v2/users/{userId}/contacts/{id}")
suspend fun deleteContact(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Path("id") id: String
): Response<ResponseBody>

@PATCH("/v2/users/{userId}/requestNewGroup")
suspend fun requestNewGroup(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: RequestNewGroupBody
): Response<ResponseBody>

@GET("/v2/users/{userId}/selectiveBySemesters")
suspend fun getSelectiveDisciplinesBySemester(
@Header("Authorization") token: String,
@Path("userId") userId: String
): Response<GetSelectiveDisciplinesBySemesterResponse>

@POST("/v2/users/{userId}/selectiveDisciplines")
suspend fun postSelectiveDisciplines(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: PostSelectiveDisciplinesBody
): Response<ResponseBody>

@GET("/v2/users/{userId}/selectiveDisciplines")
suspend fun getSelectiveDisciplines(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Query("year") year: Int,
@Query("semester") semester: Int
): Response<GetSelectiveDisciplinesResponse>

@Multipart
@PATCH("/v2/users/{userId}/")
suspend fun changeAvatar(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Part avatar: MultipartBody.Part
): Response<ChangeAvatarResponse>

@POST("/v2/users/{userId}/roles")
suspend fun setRole(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: ChangeRoleBody
): Response<ResponseBody>

@GET("/v2/users/{userId}/selective")
suspend fun getSelective(
@Header("Authorization") token: String,
@Path("userId") userId: String
): Response<GetSelectiveResponse>

@PATCH("/v2/users/{userId}/verifyStudent")
suspend fun verifyStudent(
@Header("Authorization") token: String,
@Path("userId") userId: String,
@Body body: VerifyStudentBody
): Response<VerifyStudentResponse>
}
Loading

0 comments on commit 1558b5e

Please sign in to comment.