From ba8d5ed98293fcf4cbd53f940eb8d7e14aa041b9 Mon Sep 17 00:00:00 2001 From: AmirrezaChegini Date: Sat, 18 Oct 2025 11:29:38 +0330 Subject: [PATCH] add: awards page --- lib/core/params/awards_params.dart | 13 +++++ .../data/datasource/awards_datasource.dart | 28 ++++++++++ .../awards/data/model/awards_model.dart | 13 +++++ .../awards_repository_impl.dart | 29 ++++++++++ .../awards/domain/entity/awards_entity.dart | 14 +++++ .../domain/repository/awards_repository.dart | 8 +++ .../presentation/binding/awards_binding.dart | 20 +++++++ .../controller/awards_controller.dart | 54 +++++++++++++++++++ .../awards/presentation/ui/awards_page.dart | 14 +++++ 9 files changed, 193 insertions(+) create mode 100644 lib/core/params/awards_params.dart create mode 100644 lib/features/awards/data/datasource/awards_datasource.dart create mode 100644 lib/features/awards/data/model/awards_model.dart create mode 100644 lib/features/awards/data/repository_impl/awards_repository_impl.dart create mode 100644 lib/features/awards/domain/entity/awards_entity.dart create mode 100644 lib/features/awards/domain/repository/awards_repository.dart create mode 100644 lib/features/awards/presentation/binding/awards_binding.dart create mode 100644 lib/features/awards/presentation/controller/awards_controller.dart create mode 100644 lib/features/awards/presentation/ui/awards_page.dart diff --git a/lib/core/params/awards_params.dart b/lib/core/params/awards_params.dart new file mode 100644 index 0000000..63bc3a0 --- /dev/null +++ b/lib/core/params/awards_params.dart @@ -0,0 +1,13 @@ +class AwardsParams { + int? id; + + AwardsParams({this.id}); + + AwardsParams copyWith({ + int? id, + }) { + return AwardsParams( + id: id ?? this.id, + ); + } +} diff --git a/lib/features/awards/data/datasource/awards_datasource.dart b/lib/features/awards/data/datasource/awards_datasource.dart new file mode 100644 index 0000000..33ebc37 --- /dev/null +++ b/lib/features/awards/data/datasource/awards_datasource.dart @@ -0,0 +1,28 @@ +import 'package:shia_game_flutter/core/constants/my_api.dart'; +import 'package:shia_game_flutter/core/network/http_request.dart'; +import 'package:shia_game_flutter/core/params/awards_params.dart'; +import 'package:shia_game_flutter/core/response/base_response.dart'; +import 'package:shia_game_flutter/features/awards/data/model/awards_model.dart'; +import 'package:shia_game_flutter/features/awards/domain/entity/awards_entity.dart'; + +abstract class IAwardsDatasource { + Future getData({required AwardsParams params}); +} + +class AwardsDatasourceImpl implements IAwardsDatasource { + final IHttpRequest httpRequest; + + const AwardsDatasourceImpl(this.httpRequest); + + @override + Future getData({required AwardsParams params}) async { + final response = await httpRequest.get( + path: MyApi.baseUrl, + ); + + return BaseResponse.getData( + response?['data'], + (json) => AwardsModel.fromJson(json), + ); + } +} diff --git a/lib/features/awards/data/model/awards_model.dart b/lib/features/awards/data/model/awards_model.dart new file mode 100644 index 0000000..5002ffc --- /dev/null +++ b/lib/features/awards/data/model/awards_model.dart @@ -0,0 +1,13 @@ +import 'package:shia_game_flutter/features/awards/domain/entity/awards_entity.dart'; + +class AwardsModel extends AwardsEntity { + const AwardsModel({ + super.id, + }); + + factory AwardsModel.fromJson(Map json) { + return AwardsModel( + id: json['id'], + ); + } +} diff --git a/lib/features/awards/data/repository_impl/awards_repository_impl.dart b/lib/features/awards/data/repository_impl/awards_repository_impl.dart new file mode 100644 index 0000000..91f3ab9 --- /dev/null +++ b/lib/features/awards/data/repository_impl/awards_repository_impl.dart @@ -0,0 +1,29 @@ +import 'package:flutter/foundation.dart'; +import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; +import 'package:shia_game_flutter/core/params/awards_params.dart'; +import 'package:shia_game_flutter/core/utils/data_state.dart'; +import 'package:shia_game_flutter/features/awards/data/datasource/awards_datasource.dart'; +import 'package:shia_game_flutter/features/awards/domain/entity/awards_entity.dart'; +import 'package:shia_game_flutter/features/awards/domain/repository/awards_repository.dart'; + +class AwardsRepositoryImpl implements IAwardsRepository { + final IAwardsDatasource datasource; + + const AwardsRepositoryImpl(this.datasource); + + @override + Future> getData({required AwardsParams params}) async { + try { + final AwardsEntity response = await datasource.getData(params: params); + return DataState.success(response); + } on MyException catch (e) { + return DataState.error(e); + } catch (e) { + if (kDebugMode) { + rethrow; + } else { + return DataState.error(MyException(errorMessage: '$e')); + } + } + } +} diff --git a/lib/features/awards/domain/entity/awards_entity.dart b/lib/features/awards/domain/entity/awards_entity.dart new file mode 100644 index 0000000..edfb882 --- /dev/null +++ b/lib/features/awards/domain/entity/awards_entity.dart @@ -0,0 +1,14 @@ +import 'package:equatable/equatable.dart'; + +class AwardsEntity extends Equatable { + final int? id; + + const AwardsEntity({ + this.id, + }); + + @override + List get props => [ + id, + ]; +} diff --git a/lib/features/awards/domain/repository/awards_repository.dart b/lib/features/awards/domain/repository/awards_repository.dart new file mode 100644 index 0000000..4a603d1 --- /dev/null +++ b/lib/features/awards/domain/repository/awards_repository.dart @@ -0,0 +1,8 @@ +import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; +import 'package:shia_game_flutter/core/params/awards_params.dart'; +import 'package:shia_game_flutter/core/utils/data_state.dart'; +import 'package:shia_game_flutter/features/awards/domain/entity/awards_entity.dart'; + +abstract class IAwardsRepository { + Future> getData({required AwardsParams params}); +} diff --git a/lib/features/awards/presentation/binding/awards_binding.dart b/lib/features/awards/presentation/binding/awards_binding.dart new file mode 100644 index 0000000..585c409 --- /dev/null +++ b/lib/features/awards/presentation/binding/awards_binding.dart @@ -0,0 +1,20 @@ +import 'package:shia_game_flutter/features/awards/presentation/controller/awards_controller.dart'; +import 'package:get/get.dart'; + +class AwardsBinding extends Bindings { + @override + void dependencies() { + Get.put(AwardsController(Get.find())); + } + + Future deleteBindings() async { + await Future.wait([ + Get.delete(), + ]); + } + + Future refreshBinding() async { + await deleteBindings(); + dependencies(); + } +} diff --git a/lib/features/awards/presentation/controller/awards_controller.dart b/lib/features/awards/presentation/controller/awards_controller.dart new file mode 100644 index 0000000..e1b0bb4 --- /dev/null +++ b/lib/features/awards/presentation/controller/awards_controller.dart @@ -0,0 +1,54 @@ +import 'package:flutter/cupertino.dart'; +import 'package:shia_game_flutter/core/params/awards_params.dart'; +import 'package:shia_game_flutter/core/status/base_status.dart'; +import 'package:shia_game_flutter/features/awards/domain/entity/awards_entity.dart'; +import 'package:shia_game_flutter/features/awards/domain/usecases/get_awards_usecase.dart'; +import 'package:get/get.dart'; + +class AwardsController extends GetxController with StateMixin { + /// ----- Constructor ----- + AwardsController(this.getAwardsUseCase); + + @override + void onInit() { + super.onInit(); + change('', status: RxStatus.success()); + } + + @override + void onClose() { + textEditingController.dispose(); + super.onClose(); + } + + /// ----- UseCases ----- + final GetAwardsUseCase getAwardsUseCase; + + /// ----- Variables ----- + final Rx awardsParams = Rx(AwardsParams()); + final Rx awardsEntity = Rx(const AwardsEntity()); + + /// ------ Controllers ------ + final TextEditingController textEditingController = TextEditingController(); + + /// ------ Statuses ------ + final Rx getAwardsStatus = Rx(const BaseInit()); + + /// ------ Functions ------ + + /// ------ Api Calls ------ + Future getAwards() async { + change('', status: RxStatus.loading()); + await getAwardsUseCase(awardsParams.value).then( + (value) => value.fold( + (data) { + awardsEntity.value = data; + change('', status: RxStatus.success()); + }, + (error) { + change('', status: RxStatus.error(error.errorMessage)); + }, + ), + ); + } +} diff --git a/lib/features/awards/presentation/ui/awards_page.dart b/lib/features/awards/presentation/ui/awards_page.dart new file mode 100644 index 0000000..f7d27b5 --- /dev/null +++ b/lib/features/awards/presentation/ui/awards_page.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; +import 'package:shia_game_flutter/features/awards/presentation/controller/awards_controller.dart'; +import 'package:get/get.dart'; + +class AwardsPage extends GetView { + const AwardsPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Center( + child: Text('Awards Page'), + ); + } +}