feat: adding populer quiz logic and fix the interface
This commit is contained in:
parent
5e27f09921
commit
e5f84ee727
|
@ -14,7 +14,8 @@ class APIEndpoint {
|
|||
static const String quizAnswerSession = "/quiz/answer/session";
|
||||
|
||||
static const String userQuiz = "/quiz/user";
|
||||
static const String quizRecomendation = "/quiz/recomendation";
|
||||
static const String quizPopuler = "/quiz/populer";
|
||||
static const String quizRecommendation = "/quiz/recommendation";
|
||||
static const String quizSearch = "/quiz/search";
|
||||
|
||||
static const String historyQuiz = "/history";
|
||||
|
|
|
@ -80,9 +80,29 @@ class QuizService extends GetxService {
|
|||
}
|
||||
}
|
||||
|
||||
Future<BaseResponseModel<List<QuizListingModel>>?> recomendationQuiz({int page = 1, int amount = 3}) async {
|
||||
Future<BaseResponseModel<List<QuizListingModel>>?> populerQuiz({int page = 1, int amount = 3}) async {
|
||||
try {
|
||||
final response = await dio.get("${APIEndpoint.quizRecomendation}?page=$page&limit=$amount");
|
||||
final response = await dio.get("${APIEndpoint.quizPopuler}?page=$page&limit=$amount");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final parsedResponse = BaseResponseModel<List<QuizListingModel>>.fromJson(
|
||||
response.data,
|
||||
(data) => (data as List).map((e) => QuizListingModel.fromJson(e as Map<String, dynamic>)).toList(),
|
||||
);
|
||||
return parsedResponse;
|
||||
} else {
|
||||
logC.e("Failed to fetch recommendation quizzes. Status: ${response.statusCode}");
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
logC.e("Error fetching recommendation quizzes: $e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<BaseResponseModel<List<QuizListingModel>>?> recommendationQuiz({int page = 1, int amount = 3, String userId = ""}) async {
|
||||
try {
|
||||
final response = await dio.get("${APIEndpoint.quizRecommendation}?page=$page&limit=$amount&user_id$userId");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final parsedResponse = BaseResponseModel<List<QuizListingModel>>.fromJson(
|
||||
|
|
|
@ -39,7 +39,7 @@ class HomeController extends GetxController {
|
|||
}
|
||||
|
||||
void _getRecomendationQuiz() async {
|
||||
BaseResponseModel? response = await _quizService.recomendationQuiz();
|
||||
BaseResponseModel? response = await _quizService.recommendationQuiz(userId: _userController.userData!.id);
|
||||
if (response != null) {
|
||||
data.assignAll(response.data as List<QuizListingModel>);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class ListingQuizController extends GetxController {
|
|||
|
||||
isLoading.value = true;
|
||||
|
||||
final response = await _quizService.recomendationQuiz(page: currentPage, amount: amountQuiz);
|
||||
final response = await _quizService.populerQuiz(page: currentPage, amount: amountQuiz);
|
||||
_handleResponse(response, resetPage: resetPage);
|
||||
|
||||
isLoading.value = false;
|
||||
|
@ -96,7 +96,7 @@ class ListingQuizController extends GetxController {
|
|||
if (isSearchMode && currentSubjectId != null) {
|
||||
response = await _quizService.searchQuiz("", currentPage, subjectId: currentSubjectId!);
|
||||
} else {
|
||||
response = await _quizService.recomendationQuiz(page: currentPage, amount: amountQuiz);
|
||||
response = await _quizService.populerQuiz(page: currentPage, amount: amountQuiz);
|
||||
}
|
||||
|
||||
_handleResponse(response, resetPage: false);
|
||||
|
|
|
@ -61,7 +61,7 @@ class RoomMakerController extends GetxController {
|
|||
if (isOnwQuiz.value) {
|
||||
response = await _quizService.userQuiz(_userController.userData!.id, currentPage);
|
||||
} else {
|
||||
response = await _quizService.recomendationQuiz(page: currentPage, amount: 5);
|
||||
response = await _quizService.populerQuiz(page: currentPage, amount: 5);
|
||||
}
|
||||
|
||||
if (response != null) {
|
||||
|
|
|
@ -22,13 +22,15 @@ class SearchQuizController extends GetxController {
|
|||
final searchText = ''.obs;
|
||||
|
||||
RxList<QuizListingModel> recommendationQData = <QuizListingModel>[].obs;
|
||||
RxList<QuizListingModel> populerQData = <QuizListingModel>[].obs;
|
||||
RxList<QuizListingModel> searchQData = <QuizListingModel>[].obs;
|
||||
|
||||
RxList<SubjectModel> subjects = <SubjectModel>[].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getRecomendation();
|
||||
_getRecommendation();
|
||||
_getPopuler();
|
||||
loadSubjectData();
|
||||
super.onInit();
|
||||
searchController.addListener(() {
|
||||
|
@ -41,8 +43,15 @@ class SearchQuizController extends GetxController {
|
|||
);
|
||||
}
|
||||
|
||||
void getRecomendation() async {
|
||||
BaseResponseModel? response = await _quizService.recomendationQuiz();
|
||||
void _getPopuler() async {
|
||||
BaseResponseModel? response = await _quizService.populerQuiz();
|
||||
if (response != null) {
|
||||
populerQData.assignAll(response.data as List<QuizListingModel>);
|
||||
}
|
||||
}
|
||||
|
||||
void _getRecommendation() async {
|
||||
BaseResponseModel? response = await _quizService.recommendationQuiz();
|
||||
if (response != null) {
|
||||
recommendationQData.assignAll(response.data as List<QuizListingModel>);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:quiz_app/app/const/colors/app_colors.dart';
|
|||
import 'package:quiz_app/app/const/enums/listing_type.dart';
|
||||
import 'package:quiz_app/component/quiz_container_component.dart';
|
||||
import 'package:quiz_app/component/widget/recomendation_component.dart';
|
||||
import 'package:quiz_app/data/models/quiz/quiz_listing_model.dart';
|
||||
import 'package:quiz_app/data/models/subject/subject_model.dart';
|
||||
import 'package:quiz_app/feature/search/controller/search_controller.dart';
|
||||
|
||||
|
@ -31,22 +32,15 @@ class SearchView extends GetView<SearchQuizController> {
|
|||
(e) => QuizContainerComponent(data: e, onTap: controller.goToDetailPage),
|
||||
)
|
||||
] else ...[
|
||||
Obx(
|
||||
() => RecomendationComponent(
|
||||
title: context.tr('quiz_recommendation'),
|
||||
datas: controller.recommendationQData.toList(),
|
||||
itemOnTap: controller.goToDetailPage,
|
||||
allOnTap: () => controller.goToListingsQuizPage(ListingType.recomendation),
|
||||
),
|
||||
_buildRecommendationSection(
|
||||
context.tr('quiz_recommendation'),
|
||||
controller.recommendationQData,
|
||||
() => controller.goToListingsQuizPage(ListingType.recomendation),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Obx(
|
||||
() => RecomendationComponent(
|
||||
title: context.tr('quiz_popular'),
|
||||
datas: controller.recommendationQData.toList(),
|
||||
itemOnTap: controller.goToDetailPage,
|
||||
allOnTap: () => controller.goToListingsQuizPage(ListingType.populer),
|
||||
),
|
||||
_buildRecommendationSection(
|
||||
context.tr('quiz_popular'),
|
||||
controller.populerQData,
|
||||
() => controller.goToListingsQuizPage(ListingType.populer),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
@ -88,12 +82,16 @@ class SearchView extends GetView<SearchQuizController> {
|
|||
runSpacing: 1,
|
||||
children: data.map((cat) {
|
||||
return InkWell(
|
||||
onTap: () => controller.goToListingsQuizPage(ListingType.subject, subjectId: cat.id, subjecName: cat.alias),
|
||||
onTap: () => controller.goToListingsQuizPage(
|
||||
ListingType.subject,
|
||||
subjectId: cat.id,
|
||||
subjecName: cat.alias,
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
margin: const EdgeInsets.symmetric(vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFD6E4FF),
|
||||
color: const Color(0xFFD6E4FF),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Text(
|
||||
|
@ -110,9 +108,19 @@ class SearchView extends GetView<SearchQuizController> {
|
|||
);
|
||||
}
|
||||
|
||||
// Widget _buildQuizList({int count = 3}) {
|
||||
// return Column(
|
||||
// children: List.generate(count, (_) => const QuizContainerComponent()),
|
||||
// );
|
||||
// }
|
||||
Widget _buildRecommendationSection(
|
||||
String title,
|
||||
RxList<QuizListingModel> data,
|
||||
VoidCallback onAllTap,
|
||||
) {
|
||||
return SizedBox(
|
||||
height: 410,
|
||||
child: Obx(() => RecomendationComponent(
|
||||
title: title,
|
||||
datas: data.toList(),
|
||||
itemOnTap: controller.goToDetailPage,
|
||||
allOnTap: onAllTap,
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue