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 quizAnswerSession = "/quiz/answer/session";
|
||||||
|
|
||||||
static const String userQuiz = "/quiz/user";
|
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 quizSearch = "/quiz/search";
|
||||||
|
|
||||||
static const String historyQuiz = "/history";
|
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 {
|
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) {
|
if (response.statusCode == 200) {
|
||||||
final parsedResponse = BaseResponseModel<List<QuizListingModel>>.fromJson(
|
final parsedResponse = BaseResponseModel<List<QuizListingModel>>.fromJson(
|
||||||
|
|
|
@ -39,7 +39,7 @@ class HomeController extends GetxController {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getRecomendationQuiz() async {
|
void _getRecomendationQuiz() async {
|
||||||
BaseResponseModel? response = await _quizService.recomendationQuiz();
|
BaseResponseModel? response = await _quizService.recommendationQuiz(userId: _userController.userData!.id);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
data.assignAll(response.data as List<QuizListingModel>);
|
data.assignAll(response.data as List<QuizListingModel>);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ class ListingQuizController extends GetxController {
|
||||||
|
|
||||||
isLoading.value = true;
|
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);
|
_handleResponse(response, resetPage: resetPage);
|
||||||
|
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
@ -96,7 +96,7 @@ class ListingQuizController extends GetxController {
|
||||||
if (isSearchMode && currentSubjectId != null) {
|
if (isSearchMode && currentSubjectId != null) {
|
||||||
response = await _quizService.searchQuiz("", currentPage, subjectId: currentSubjectId!);
|
response = await _quizService.searchQuiz("", currentPage, subjectId: currentSubjectId!);
|
||||||
} else {
|
} else {
|
||||||
response = await _quizService.recomendationQuiz(page: currentPage, amount: amountQuiz);
|
response = await _quizService.populerQuiz(page: currentPage, amount: amountQuiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleResponse(response, resetPage: false);
|
_handleResponse(response, resetPage: false);
|
||||||
|
|
|
@ -61,7 +61,7 @@ class RoomMakerController extends GetxController {
|
||||||
if (isOnwQuiz.value) {
|
if (isOnwQuiz.value) {
|
||||||
response = await _quizService.userQuiz(_userController.userData!.id, currentPage);
|
response = await _quizService.userQuiz(_userController.userData!.id, currentPage);
|
||||||
} else {
|
} else {
|
||||||
response = await _quizService.recomendationQuiz(page: currentPage, amount: 5);
|
response = await _quizService.populerQuiz(page: currentPage, amount: 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
|
|
@ -22,13 +22,15 @@ class SearchQuizController extends GetxController {
|
||||||
final searchText = ''.obs;
|
final searchText = ''.obs;
|
||||||
|
|
||||||
RxList<QuizListingModel> recommendationQData = <QuizListingModel>[].obs;
|
RxList<QuizListingModel> recommendationQData = <QuizListingModel>[].obs;
|
||||||
|
RxList<QuizListingModel> populerQData = <QuizListingModel>[].obs;
|
||||||
RxList<QuizListingModel> searchQData = <QuizListingModel>[].obs;
|
RxList<QuizListingModel> searchQData = <QuizListingModel>[].obs;
|
||||||
|
|
||||||
RxList<SubjectModel> subjects = <SubjectModel>[].obs;
|
RxList<SubjectModel> subjects = <SubjectModel>[].obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
getRecomendation();
|
_getRecommendation();
|
||||||
|
_getPopuler();
|
||||||
loadSubjectData();
|
loadSubjectData();
|
||||||
super.onInit();
|
super.onInit();
|
||||||
searchController.addListener(() {
|
searchController.addListener(() {
|
||||||
|
@ -41,8 +43,15 @@ class SearchQuizController extends GetxController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getRecomendation() async {
|
void _getPopuler() async {
|
||||||
BaseResponseModel? response = await _quizService.recomendationQuiz();
|
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) {
|
if (response != null) {
|
||||||
recommendationQData.assignAll(response.data as List<QuizListingModel>);
|
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/app/const/enums/listing_type.dart';
|
||||||
import 'package:quiz_app/component/quiz_container_component.dart';
|
import 'package:quiz_app/component/quiz_container_component.dart';
|
||||||
import 'package:quiz_app/component/widget/recomendation_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/data/models/subject/subject_model.dart';
|
||||||
import 'package:quiz_app/feature/search/controller/search_controller.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),
|
(e) => QuizContainerComponent(data: e, onTap: controller.goToDetailPage),
|
||||||
)
|
)
|
||||||
] else ...[
|
] else ...[
|
||||||
Obx(
|
_buildRecommendationSection(
|
||||||
() => RecomendationComponent(
|
context.tr('quiz_recommendation'),
|
||||||
title: context.tr('quiz_recommendation'),
|
controller.recommendationQData,
|
||||||
datas: controller.recommendationQData.toList(),
|
() => controller.goToListingsQuizPage(ListingType.recomendation),
|
||||||
itemOnTap: controller.goToDetailPage,
|
|
||||||
allOnTap: () => 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,
|
runSpacing: 1,
|
||||||
children: data.map((cat) {
|
children: data.map((cat) {
|
||||||
return InkWell(
|
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(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 2),
|
margin: const EdgeInsets.symmetric(vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color(0xFFD6E4FF),
|
color: const Color(0xFFD6E4FF),
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
|
@ -110,9 +108,19 @@ class SearchView extends GetView<SearchQuizController> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Widget _buildQuizList({int count = 3}) {
|
Widget _buildRecommendationSection(
|
||||||
// return Column(
|
String title,
|
||||||
// children: List.generate(count, (_) => const QuizContainerComponent()),
|
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