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

Commit c7bc7f5

Browse files
authored
Merge branch 'dev' into user_profile
2 parents 3ae3c72 + d976d2b commit c7bc7f5

20 files changed

+681
-6
lines changed

app/build.gradle

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ dependencies {
8282
def coroutines_version = "1.7.3"
8383
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
8484
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
85-
def lifecycle_version = "2.6.2"
85+
// - - Coroutine test
86+
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
87+
8688
// - - ViewModel
89+
def lifecycle_version = "2.6.2"
8790
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
8891
// - - LiveData
8992
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
@@ -105,4 +108,6 @@ dependencies {
105108
// - - MockWebServer
106109
def mock_web_server_version = "4.3.1"
107110
testImplementation "com.squareup.okhttp3:mockwebserver:$mock_web_server_version"
111+
112+
testImplementation "org.mockito:mockito-core:5.10.0"
108113
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class DetailedEventResponse(
4+
val url: String,
5+
val eventInfo: String,
6+
val disciplineType: TDiscipline,
7+
val disciplineInfo: String,
8+
val period: TEventPeriod,
9+
val teachers: List<Teacher>
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class DisciplineTypeDTO(
4+
val id: String,
5+
val disciplineId: String,
6+
val name: TDiscipline
7+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class EventDTO(
4+
val id: String,
5+
val name: String,
6+
val startTime: String,
7+
val endTime: String,
8+
val disciplineType: DisciplineTypeDTO?
9+
)
10+
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class GetEventResponse (
4+
val week: String,
5+
val events: List<EventDTO>,
6+
val startTime: String,
7+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class PatchEventDTO(
4+
val week: Int,
5+
val changeStartDate: Boolean,
6+
val changeEndDate: Boolean,
7+
val disciplineType: String? = null,
8+
val url: String,
9+
val eventInfo: String,
10+
val disciplineInfo: String,
11+
val period: TEventPeriod,
12+
val teachers: List<String>,
13+
val disciplineId: String
14+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class PostEventDTO (
4+
val groupId: String,
5+
val teachers: List<String>,
6+
val disciplineId: String,
7+
val url: String,
8+
val eventInfo: String,
9+
val disciplineType: TDiscipline,
10+
val disciplineInfo: String,
11+
val period: TEventPeriod,
12+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
enum class TDiscipline {
4+
LECTURE,
5+
PRACTICE,
6+
LABORATORY,
7+
CONSULTATION,
8+
WORKOUT,
9+
EXAM
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
enum class TEventPeriod {
4+
NO_PERIOD,
5+
EVERY_WEEK,
6+
EVERY_FORTNIGHT
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.fictadvisor.android.data.dto.schedule
2+
3+
data class Teacher(
4+
val id: String,
5+
val firstName: String,
6+
val middleName: String,
7+
val lastName: String
8+
)

app/src/main/java/com/fictadvisor/android/data/remote/RetrofitClient.kt

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.fictadvisor.android.data.remote
22

33
import com.fictadvisor.android.data.remote.api.AuthApi
44
import com.fictadvisor.android.data.remote.api.GroupApi
5+
import com.fictadvisor.android.data.remote.api.ScheduleApi
56
import okhttp3.Interceptor
67
import okhttp3.OkHttpClient
78
import okhttp3.logging.HttpLoggingInterceptor
@@ -66,4 +67,10 @@ object RetrofitClient {
6667
.create(GroupApi::class.java)
6768
}
6869

70+
val scheduleApi: ScheduleApi by lazy {
71+
retrofitClient
72+
.build()
73+
.create(ScheduleApi::class.java)
74+
}
75+
6976
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.fictadvisor.android.data.remote.api
2+
3+
import com.fictadvisor.android.data.dto.schedule.DetailedEventResponse
4+
import com.fictadvisor.android.data.dto.schedule.GetEventResponse
5+
import com.fictadvisor.android.data.dto.schedule.PatchEventDTO
6+
import com.fictadvisor.android.data.dto.schedule.PostEventDTO
7+
import retrofit2.Response
8+
import retrofit2.http.Body
9+
import retrofit2.http.DELETE
10+
import retrofit2.http.GET
11+
import retrofit2.http.PATCH
12+
import retrofit2.http.POST
13+
import retrofit2.http.Path
14+
import retrofit2.http.Query
15+
16+
interface ScheduleApi {
17+
@GET("/v2/schedule/groups/{groupId}/general")
18+
suspend fun getEvents(
19+
@Path("groupId") groupId: String,
20+
@Query("week") week: Int,
21+
@Query("addLecture") addLecture: Boolean = true,
22+
@Query("addLaboratory") addLaboratory: Boolean = true,
23+
@Query("addPractice") addPractice: Boolean = true
24+
): Response<GetEventResponse>
25+
26+
@GET("/v2/schedule/groups/{groupId}/events")
27+
suspend fun getEventsAuthorized(
28+
@Path("groupId") groupId: String,
29+
@Query("week") week: Int,
30+
@Query("showOwnSelective") showOwnSelective: Boolean,
31+
@Query("addLecture") addLecture: Boolean = true,
32+
@Query("addLaboratory") addLaboratory: Boolean = true,
33+
@Query("addPractice") addPractice: Boolean = true,
34+
@Query("otherEvents") otherEvents: Boolean = true
35+
): Response<GetEventResponse>
36+
37+
@GET("/v2/schedule/events/{eventId}")
38+
suspend fun getEventInfo(
39+
@Path("eventId") eventId: String,
40+
@Query("week") week: Any // You can define the type accordingly
41+
): Response<DetailedEventResponse>
42+
43+
@DELETE("/v2/schedule/groups/{groupId}/events/{eventId}")
44+
suspend fun deleteEventById(
45+
@Path("groupId") groupId: String,
46+
@Path("eventId") eventId: String
47+
): Response<DetailedEventResponse>
48+
49+
@POST("/v2/schedule/events")
50+
suspend fun addEvent(
51+
@Body body: PostEventDTO,
52+
@Query("groupId") groupId: String
53+
): Response<DetailedEventResponse>
54+
55+
@PATCH("/v2/schedule/groups/{groupId}/events/{eventId}")
56+
suspend fun editEvent(
57+
@Body body: PatchEventDTO,
58+
@Path("groupId") groupId: String,
59+
@Path("eventId") eventId: String
60+
): Response<DetailedEventResponse>
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fictadvisor.android.repository
2+
3+
import com.fictadvisor.android.data.dto.schedule.DetailedEventResponse
4+
import com.fictadvisor.android.data.dto.schedule.GetEventResponse
5+
import com.fictadvisor.android.data.dto.schedule.PatchEventDTO
6+
import com.fictadvisor.android.data.dto.schedule.PostEventDTO
7+
import com.fictadvisor.android.data.remote.RetrofitClient
8+
import retrofit2.Response
9+
10+
class ScheduleRepository {
11+
private val scheduleService = RetrofitClient.scheduleApi
12+
13+
suspend fun getEvents(groupId: String, week: Int): Response<GetEventResponse> {
14+
return scheduleService.getEvents(groupId, week)
15+
}
16+
17+
suspend fun getEventsAuthorized(groupId: String, week: Int, showOwnSelective: Boolean): Response<GetEventResponse> {
18+
return scheduleService.getEventsAuthorized(groupId, week, showOwnSelective)
19+
}
20+
21+
suspend fun getEventInfo(eventId: String, week: Any): Response<DetailedEventResponse> {
22+
return scheduleService.getEventInfo(eventId, week)
23+
}
24+
25+
suspend fun deleteEventById(groupId: String, eventId: String): Response<DetailedEventResponse> {
26+
return scheduleService.deleteEventById(groupId, eventId)
27+
}
28+
29+
suspend fun addEvent(body: PostEventDTO, groupId: String): Response<DetailedEventResponse> {
30+
return scheduleService.addEvent(body, groupId)
31+
}
32+
33+
suspend fun editEvent(body: PatchEventDTO, groupId: String, eventId: String): Response<DetailedEventResponse> {
34+
return scheduleService.editEvent(body, groupId, eventId)
35+
}
36+
}
37+

app/src/main/java/com/fictadvisor/android/ui/ContinueRegistrationFragment.kt

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.navigation.Navigation
1212
import com.fictadvisor.android.data.dto.*
1313
import com.fictadvisor.android.databinding.FragmentContinueRegistrationBinding
1414
import com.fictadvisor.android.repository.AuthRepository
15+
import com.fictadvisor.android.utils.StorageUtil
1516
import com.fictadvisor.android.validator.RegistrationInputValidator
1617
import com.fictadvisor.android.viewmodel.AuthViewModel
1718
import com.fictadvisor.android.viewmodel.AuthViewModelFactory
@@ -25,6 +26,7 @@ class ContinueRegistrationFragment : Fragment() {
2526
private lateinit var authViewModel: AuthViewModel
2627
private val authRepository = AuthRepository()
2728
private lateinit var inputValidator: RegistrationInputValidator
29+
private lateinit var storageUtil: StorageUtil
2830

2931

3032
override fun onCreateView(
@@ -36,6 +38,8 @@ class ContinueRegistrationFragment : Fragment() {
3638

3739
inputValidator = RegistrationInputValidator(requireContext())
3840

41+
storageUtil = StorageUtil(requireActivity())
42+
3943
authViewModel = ViewModelProvider(
4044
this,
4145
AuthViewModelFactory(authRepository)
@@ -188,6 +192,7 @@ class ContinueRegistrationFragment : Fragment() {
188192
when (registerResponse) {
189193
is BaseResponse.Success -> {
190194
showSuccessLog("Реєстрація успішна")
195+
storageUtil.setEmail(binding.editTextTextEmail.text.toString())
191196
val action = ContinueRegistrationFragmentDirections.actionContinueRegistrationFragmentToVerifyEmailFragment()
192197
Navigation.findNavController(requireView()).navigate(action)
193198
}

app/src/main/java/com/fictadvisor/android/ui/VerifyEmailFragment.kt

+32-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class VerifyEmailFragment : Fragment() {
3939
binding = FragmentVerifyEmailBinding.inflate(inflater, container, false)
4040
val view = binding.root
4141

42-
storageUtil = StorageUtil(requireContext())
42+
storageUtil = StorageUtil(requireActivity())
4343

4444
authViewModel = ViewModelProvider(
4545
this,
@@ -53,9 +53,18 @@ class VerifyEmailFragment : Fragment() {
5353
sendEmailVerificationRequest(token)
5454
}
5555

56+
setResendButtonOnClickListener()
57+
5658
return view
5759
}
5860

61+
private fun setResendButtonOnClickListener() {
62+
binding.resendEmailButton.setOnClickListener {
63+
val email = storageUtil.getEmail()!!
64+
resendEmailVerificationRequest(email)
65+
}
66+
}
67+
5968
private fun sendEmailVerificationRequest(token: String) {
6069
CoroutineScope(Dispatchers.IO).launch {
6170
authViewModel.verifyEmailToken(token)
@@ -68,6 +77,28 @@ class VerifyEmailFragment : Fragment() {
6877
}
6978
}
7079

80+
private fun resendEmailVerificationRequest(email: String) {
81+
CoroutineScope(Dispatchers.IO).launch {
82+
authViewModel.verifyEmail(email)
83+
}
84+
85+
authViewModel.authVerifyEmailResponse.observe(viewLifecycleOwner) { response ->
86+
response?.let {
87+
when (response) {
88+
is BaseResponse.Success -> {
89+
binding.messageTV.text = "Повторний запит на підтвердження email відправлено на адресу $email"
90+
}
91+
92+
is BaseResponse.Error -> {
93+
binding.messageTV.text = "Помилка при повторному відправленні email: ${response.error?.message}"
94+
}
95+
96+
is BaseResponse.Loading -> {}
97+
}
98+
}
99+
}
100+
}
101+
71102
private fun handleVerificationEmailResponse(response: BaseResponse<AuthLoginResponse>) {
72103
when (response) {
73104
is BaseResponse.Success -> {

app/src/main/java/com/fictadvisor/android/utils/StorageUtil.kt

+12
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,16 @@ class StorageUtil(private val context: Context) {
159159
null
160160
}
161161
}
162+
163+
fun setEmail(email: String) {
164+
context.getSharedPreferences(prefName, Context.MODE_PRIVATE).edit().apply {
165+
putString(StorageKeys.EMAIL.name, email)
166+
apply()
167+
}
168+
}
169+
170+
fun getEmail(): String? {
171+
val prefs = context.getSharedPreferences(prefName, Context.MODE_PRIVATE)
172+
return prefs.getString(StorageKeys.EMAIL.name, null)
173+
}
162174
}

0 commit comments

Comments
 (0)