-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac2c74d
commit 2374f77
Showing
48 changed files
with
1,449 additions
and
435 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/features/occupation/data/datasources/occupation_remote_data_source.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:coffeecard/core/errors/failures.dart'; | ||
import 'package:coffeecard/core/network/network_request_executor.dart'; | ||
import 'package:coffeecard/features/occupation/data/models/occupation_model.dart'; | ||
import 'package:coffeecard/generated/api/coffeecard_api.swagger.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
class OccupationRemoteDataSource { | ||
final CoffeecardApi api; | ||
final NetworkRequestExecutor executor; | ||
|
||
OccupationRemoteDataSource({ | ||
required this.api, | ||
required this.executor, | ||
}); | ||
|
||
Future<Either<NetworkFailure, List<OccupationModel>>> getOccupations() async { | ||
final result = await executor( | ||
() => api.apiV1ProgrammesGet(), | ||
); | ||
return result | ||
.map((result) => result.map(OccupationModel.fromDTOV1).toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:coffeecard/features/occupation/domain/entities/occupation.dart'; | ||
import 'package:coffeecard/generated/api/coffeecard_api.models.swagger.dart'; | ||
import 'package:coffeecard/generated/api/coffeecard_api_v2.models.swagger.dart'; | ||
|
||
class OccupationModel extends Occupation { | ||
const OccupationModel({ | ||
required super.id, | ||
required super.shortName, | ||
required super.fullName, | ||
}); | ||
|
||
factory OccupationModel.fromDTOV1(ProgrammeDto dto) { | ||
return OccupationModel( | ||
id: dto.id, | ||
shortName: dto.shortName, | ||
fullName: dto.fullName, | ||
); | ||
} | ||
|
||
factory OccupationModel.fromDTOV2(ProgrammeResponse dto) { | ||
return OccupationModel( | ||
id: dto.id, | ||
shortName: dto.shortName, | ||
fullName: dto.fullName, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
lib/features/occupation/domain/usecases/get_occupations.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:coffeecard/core/errors/failures.dart'; | ||
import 'package:coffeecard/core/usecases/usecase.dart'; | ||
import 'package:coffeecard/features/occupation/data/datasources/occupation_remote_data_source.dart'; | ||
import 'package:coffeecard/features/occupation/domain/entities/occupation.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
class GetOccupations implements UseCase<List<Occupation>, NoParams> { | ||
final OccupationRemoteDataSource dataSource; | ||
|
||
GetOccupations({required this.dataSource}); | ||
|
||
@override | ||
Future<Either<Failure, List<Occupation>>> call(NoParams params) { | ||
return dataSource.getOccupations(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/features/occupation/presentation/cubit/occupation_cubit.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:coffeecard/core/usecases/usecase.dart'; | ||
import 'package:coffeecard/features/occupation/domain/entities/occupation.dart'; | ||
import 'package:coffeecard/features/occupation/domain/usecases/get_occupations.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
part 'occupation_state.dart'; | ||
|
||
class OccupationCubit extends Cubit<OccupationState> { | ||
final GetOccupations getOccupations; | ||
|
||
OccupationCubit({required this.getOccupations}) | ||
: super(const OccupationLoading()); | ||
|
||
Future<void> fetchOccupations() async { | ||
emit(const OccupationLoading()); | ||
|
||
final either = await getOccupations(NoParams()); | ||
|
||
either.fold( | ||
(error) => emit(OccupationError(message: error.reason)), | ||
(occupations) => emit(OccupationLoaded(occupations: occupations)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lib/features/occupation/presentation/pages/change_occupation_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:coffeecard/base/strings.dart'; | ||
import 'package:coffeecard/features/occupation/presentation/cubit/occupation_cubit.dart'; | ||
import 'package:coffeecard/features/occupation/presentation/widgets/occupation_form.dart'; | ||
import 'package:coffeecard/features/user/presentation/cubit/user_cubit.dart'; | ||
import 'package:coffeecard/service_locator.dart'; | ||
import 'package:coffeecard/widgets/components/loading.dart'; | ||
import 'package:coffeecard/widgets/components/scaffold.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class ChangeOccupationPage extends StatelessWidget { | ||
const ChangeOccupationPage(); | ||
|
||
static Route get route => | ||
MaterialPageRoute(builder: (_) => const ChangeOccupationPage()); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AppScaffold.withTitle( | ||
title: Strings.changeOccupation, | ||
body: BlocProvider( | ||
create: (_) => sl<OccupationCubit>()..fetchOccupations(), | ||
child: Padding( | ||
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16), | ||
child: BlocBuilder<OccupationCubit, OccupationState>( | ||
builder: (_, occupationState) { | ||
if (occupationState is! OccupationLoaded) { | ||
return const SizedBox.shrink(); | ||
} | ||
|
||
return BlocBuilder<UserCubit, UserState>( | ||
builder: (context, userState) { | ||
return Loading( | ||
loading: userState is UserUpdating, | ||
child: OccupationForm( | ||
occupations: occupationState.occupations, | ||
selectedOccupation: userState is UserLoaded | ||
? userState.user.occupation | ||
: null, | ||
onChange: (occupation) => context | ||
.read<UserCubit>() | ||
.setUserOccupation(occupation.id), | ||
), | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ets/components/forms/occupation_form.dart → ...presentation/widgets/occupation_form.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.