Skip to content

Commit

Permalink
feat(study set): tạo hit cho người dùng ở chế độ học write
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Dec 13, 2024
1 parent 2f95465 commit 5189463
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 46 deletions.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 7,
"versionName": "1.6",
"versionCode": 8,
"versionName": "1.6(1)",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pwhs.quickmem.data.dto.study_set

import com.google.gson.annotations.SerializedName

data class CreateWriteHintAIRequestDto(
@SerializedName("flashcardId")
val flashcardId: String,
@SerializedName("studySetTitle")
val studySetTitle: String,
@SerializedName("studySetDescription")
val studySetDescription: String,
@SerializedName("question")
val question: String,
@SerializedName("answer")
val answer: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pwhs.quickmem.data.dto.study_set

import com.google.gson.annotations.SerializedName

data class CreateWriteHintAIResponseDto(
@SerializedName("flashcardId")
val flashcardId: String,
@SerializedName("aiHint")
val aiHint: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.pwhs.quickmem.data.mapper.study_set

import com.pwhs.quickmem.data.dto.study_set.CreateWriteHintAIRequestDto
import com.pwhs.quickmem.domain.model.study_set.CreateWriteHintAIRequestModel

fun CreateWriteHintAIRequestDto.toModel() = CreateWriteHintAIRequestModel(
flashcardId = flashcardId,
studySetTitle = studySetTitle,
studySetDescription = studySetDescription,
question = question,
answer = answer,
)

fun CreateWriteHintAIRequestModel.toDto() = CreateWriteHintAIRequestDto(
flashcardId = flashcardId,
studySetTitle = studySetTitle,
studySetDescription = studySetDescription,
question = question,
answer = answer,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pwhs.quickmem.data.mapper.study_set

import com.pwhs.quickmem.data.dto.study_set.CreateWriteHintAIResponseDto
import com.pwhs.quickmem.domain.model.study_set.CreateWriteHintAIResponseModel

fun CreateWriteHintAIResponseDto.toModel() = CreateWriteHintAIResponseModel(
flashcardId = flashcardId,
aiHint = aiHint,
)

fun CreateWriteHintAIResponseModel.toDto() = CreateWriteHintAIResponseDto(
flashcardId = flashcardId,
aiHint = aiHint,
)
8 changes: 8 additions & 0 deletions app/src/main/java/com/pwhs/quickmem/data/remote/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import com.pwhs.quickmem.data.dto.study_set.AddStudySetToFoldersRequestDto
import com.pwhs.quickmem.data.dto.study_set.CreateStudySetByAIRequestDto
import com.pwhs.quickmem.data.dto.study_set.CreateStudySetRequestDto
import com.pwhs.quickmem.data.dto.study_set.CreateStudySetResponseDto
import com.pwhs.quickmem.data.dto.study_set.CreateWriteHintAIRequestDto
import com.pwhs.quickmem.data.dto.study_set.CreateWriteHintAIResponseDto
import com.pwhs.quickmem.data.dto.study_set.GetStudySetResponseDto
import com.pwhs.quickmem.data.dto.study_set.MakeACopyStudySetRequestDto
import com.pwhs.quickmem.data.dto.study_set.SaveRecentAccessStudySetRequestDto
Expand Down Expand Up @@ -297,6 +299,12 @@ interface ApiService {
@Body createStudySetRequestDto: CreateStudySetByAIRequestDto
): CreateStudySetResponseDto

@POST("study-set/ai/write-hint")
suspend fun createWriteHintAI(
@Header("Authorization") token: String,
@Body createWriteHintAIModel: CreateWriteHintAIRequestDto
): CreateWriteHintAIResponseDto

// subject
@GET("study-set/top-subject")
suspend fun getTop5Subject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.pwhs.quickmem.domain.model.study_set.AddStudySetToFoldersRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateStudySetByAIRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateStudySetRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateStudySetResponseModel
import com.pwhs.quickmem.domain.model.study_set.CreateWriteHintAIRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateWriteHintAIResponseModel
import com.pwhs.quickmem.domain.model.study_set.GetStudySetResponseModel
import com.pwhs.quickmem.domain.model.study_set.SaveRecentAccessStudySetRequestModel
import com.pwhs.quickmem.domain.model.study_set.UpdateStudySetRequestModel
Expand Down Expand Up @@ -50,7 +52,10 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
val response = apiService.createStudySet(token, createStudySetRequestModel.toDto())
val response = apiService.createStudySet(
token = token,
createStudySetRequestDto = createStudySetRequestModel.toDto()
)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
emit(Resources.Error(e.toString()))
Expand All @@ -68,7 +73,7 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
val response = apiService.getStudySetById(token, studySetId)
val response = apiService.getStudySetById(token = token, id = studySetId)
response.flashcards = response.flashcards?.sortedByDescending { it.createdAt }
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Expand All @@ -90,7 +95,12 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
val response = apiService.getStudySetsByOwnerId(token, ownerId, classId, folderId)
val response = apiService.getStudySetsByOwnerId(
token = token,
ownerId = ownerId,
classId = classId,
folderId = folderId
)
emit(Resources.Success(response.map { it.toModel() }))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -111,7 +121,11 @@ class StudySetRepositoryImpl @Inject constructor(
emit(Resources.Loading())
try {
val response =
apiService.updateStudySet(token, studySetId, updateStudySetRequestModel.toDto())
apiService.updateStudySet(
token = token,
id = studySetId,
updateStudySetRequestDto = updateStudySetRequestModel.toDto()
)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -130,7 +144,7 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.deleteStudySet(token, studySetId)
apiService.deleteStudySet(token = token, id = studySetId)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -150,7 +164,11 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.resetStudySetProgress(token, studySetId, resetType)
apiService.resetStudySetProgress(
token = token,
id = studySetId,
resetType = resetType
)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -169,7 +187,10 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.addStudySetToFolder(token, addStudySetToFolderRequestModel.toDto())
apiService.addStudySetToFolder(
token = token,
addStudySetToFolderRequestDto = addStudySetToFolderRequestModel.toDto()
)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -188,7 +209,10 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.addStudySetToClass(token, addStudySetToClassRequestModel.toDto())
apiService.addStudySetToClass(
token = token,
addStudySetToClassRequestDto = addStudySetToClassRequestModel.toDto()
)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -207,7 +231,10 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.addStudySetToFolders(token, addStudySetToFoldersRequestModel.toDto())
apiService.addStudySetToFolders(
token = token,
addStudySetToFoldersRequestDto = addStudySetToFoldersRequestModel.toDto()
)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -226,7 +253,10 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.addStudySetToClasses(token, addStudySetToClassesRequestModel.toDto())
apiService.addStudySetToClasses(
token = token,
addStudySetToClassesRequestDto = addStudySetToClassesRequestModel.toDto()
)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand Down Expand Up @@ -255,14 +285,14 @@ class StudySetRepositoryImpl @Inject constructor(
),
pagingSourceFactory = {
StudySetPagingSource(
studySetRemoteDataSource,
token,
title,
size,
creatorType,
colorId,
subjectId,
isAIGenerated
studySetRemoteDataSource = studySetRemoteDataSource,
token = token,
title = title,
size = size,
creatorType = creatorType,
colorId = colorId,
subjectId = subjectId,
isAIGenerated = isAIGenerated
)
}
).flow
Expand All @@ -279,7 +309,7 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
val response = apiService.getStudySetByLinkCode(token, code)
val response = apiService.getStudySetByLinkCode(token = token, code = code)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -301,7 +331,7 @@ class StudySetRepositoryImpl @Inject constructor(
try {
val request =
MakeACopyStudySetRequestDto(studySetId = studySetId, newOwnerId = newOwnerId)
val response = apiService.duplicateStudySet(token, request)
val response = apiService.duplicateStudySet(token = token, request = request)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -319,7 +349,7 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
val response = apiService.getTop5Subject(token)
val response = apiService.getTop5Subject(token = token)
emit(Resources.Success(response.map { it.toModel() }))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -343,9 +373,9 @@ class StudySetRepositoryImpl @Inject constructor(
),
pagingSourceFactory = {
StudySetBySubjectPagingSource(
searchStudySetBySubjectRemoteDataSource,
token,
subjectId,
searchStudySetBySubjectRemoteDataSource = searchStudySetBySubjectRemoteDataSource,
token = token,
subjectId = subjectId,
)
}
).flow
Expand All @@ -362,7 +392,10 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
apiService.saveRecentStudySet(token, saveRecentAccessStudySetRequestModel.toDto())
apiService.saveRecentStudySet(
token = token,
saveRecentAccessStudySetRequestDto = saveRecentAccessStudySetRequestModel.toDto()
)
emit(Resources.Success(Unit))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -381,7 +414,7 @@ class StudySetRepositoryImpl @Inject constructor(
}
emit(Resources.Loading())
try {
val response = apiService.getRecentStudySet(token, userId)
val response = apiService.getRecentStudySet(token = token, userId = userId)
emit(Resources.Success(response.map { it.toModel() }))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -401,7 +434,33 @@ class StudySetRepositoryImpl @Inject constructor(
emit(Resources.Loading())
try {
val response =
apiService.createStudySetByAI(token, createStudySetByAIRequestModel.toDto())
apiService.createStudySetByAI(
token = token,
createStudySetRequestDto = createStudySetByAIRequestModel.toDto()
)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
emit(Resources.Error(e.toString()))
}
}
}

override suspend fun createWriteHintAI(
token: String,
createWriteHintAIRequestModel: CreateWriteHintAIRequestModel
): Flow<Resources<CreateWriteHintAIResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response =
apiService.createWriteHintAI(
token = token,
createWriteHintAIModel = createWriteHintAIRequestModel.toDto()
)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pwhs.quickmem.domain.model.study_set

data class CreateWriteHintAIRequestModel(
val flashcardId: String,
val studySetTitle: String,
val studySetDescription: String,
val question: String,
val answer: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.pwhs.quickmem.domain.model.study_set

data class CreateWriteHintAIResponseModel(
val flashcardId: String,
val aiHint: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.pwhs.quickmem.domain.model.study_set.AddStudySetToFoldersRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateStudySetByAIRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateStudySetRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateStudySetResponseModel
import com.pwhs.quickmem.domain.model.study_set.CreateWriteHintAIRequestModel
import com.pwhs.quickmem.domain.model.study_set.CreateWriteHintAIResponseModel
import com.pwhs.quickmem.domain.model.study_set.GetStudySetResponseModel
import com.pwhs.quickmem.domain.model.study_set.SaveRecentAccessStudySetRequestModel
import com.pwhs.quickmem.domain.model.study_set.UpdateStudySetRequestModel
Expand Down Expand Up @@ -119,4 +121,9 @@ interface StudySetRepository {
token: String,
createStudySetByAIRequestModel: CreateStudySetByAIRequestModel
): Flow<Resources<CreateStudySetResponseModel>>

suspend fun createWriteHintAI(
token: String,
createWriteHintAIRequestModel: CreateWriteHintAIRequestModel
): Flow<Resources<CreateWriteHintAIResponseModel>>
}
Loading

0 comments on commit 5189463

Please sign in to comment.