-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
23 changed files
with
324 additions
and
126 deletions.
There are no files selected for viewing
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 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
22 changes: 22 additions & 0 deletions
22
lib/app/services/converters/flyer_create_model_parsing.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,22 @@ | ||
part of '../converters.dart'; | ||
|
||
extension FlyerCreateModelParsing on FlyerCreateModel { | ||
FlyerDetailModel transformToFlyerDetailModel(String temporaryId) { | ||
return FlyerDetailModel( | ||
id: temporaryId, | ||
address: address, | ||
flyerCount: flyerCount, | ||
location: location, | ||
createdAt: '${DateTime.now().getAsLocalDateTimeString()}*', // should mark this as preliminary | ||
isCached: true, | ||
); | ||
} | ||
|
||
MarkerItemModel transformToVirtualMarkerItem(int temporaryId) { | ||
return MarkerItemModel.virtual( | ||
id: temporaryId, | ||
status: PoiServiceType.flyer.name, | ||
location: location, | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/app/services/converters/flyer_update_model_parsing.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,20 @@ | ||
part of '../converters.dart'; | ||
|
||
extension FlyerUpdateModelParsing on FlyerUpdateModel { | ||
FlyerDetailModel transformToFlyerDetailModel() { | ||
var newFlyerDetail = oldFlyerDetail.copyWith( | ||
address: address, | ||
flyerCount: flyerCount, | ||
isCached: true, | ||
); | ||
return newFlyerDetail; | ||
} | ||
|
||
MarkerItemModel transformToVirtualMarkerItem() { | ||
return MarkerItemModel.virtual( | ||
id: int.parse(id), | ||
status: PoiServiceType.flyer.name, | ||
location: location, | ||
); | ||
} | ||
} |
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 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 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,43 @@ | ||
import 'package:gruene_app/app/services/converters.dart'; | ||
import 'package:gruene_app/app/services/enums.dart'; | ||
import 'package:gruene_app/app/services/gruene_api_campaigns_service.dart'; | ||
import 'package:gruene_app/features/campaigns/models/flyer/flyer_create_model.dart'; | ||
import 'package:gruene_app/features/campaigns/models/flyer/flyer_detail_model.dart'; | ||
import 'package:gruene_app/features/campaigns/models/flyer/flyer_update_model.dart'; | ||
import 'package:gruene_app/features/campaigns/models/marker_item_model.dart'; | ||
import 'package:gruene_app/swagger_generated_code/gruene_api.swagger.dart'; | ||
|
||
class GrueneApiFlyerService extends GrueneApiCampaignsService { | ||
GrueneApiFlyerService() : super(poiType: PoiServiceType.flyer); | ||
|
||
Future<MarkerItemModel> createNewFlyer(FlyerCreateModel newFlyer) async { | ||
final requestParam = CreatePoi( | ||
coords: newFlyer.location.transformToGeoJsonCoords(), | ||
type: poiType.transformToApiCreateType(), | ||
address: newFlyer.address.transformToPoiAddress(), | ||
flyerSpot: PoiFlyerSpot( | ||
flyerCount: newFlyer.flyerCount.toDouble(), | ||
), | ||
); | ||
// saving POI | ||
final newPoiResponse = await grueneApi.v1CampaignsPoisPost(body: requestParam); | ||
|
||
return newPoiResponse.body!.transformToMarkerItem(); | ||
} | ||
|
||
Future<FlyerDetailModel> getPoiAsFlyerDetail(String poiId) { | ||
return getPoi(poiId, (p) => p.transformPoiToFlyerDetail()); | ||
} | ||
|
||
Future<MarkerItemModel> updateFlyer(FlyerUpdateModel flyerUpdate) async { | ||
var dtoUpdate = UpdatePoi( | ||
address: flyerUpdate.address.transformToPoiAddress(), | ||
flyerSpot: PoiFlyerSpot( | ||
flyerCount: flyerUpdate.flyerCount.toDouble(), | ||
), | ||
); | ||
var updatePoiResponse = await grueneApi.v1CampaignsPoisPoiIdPut(poiId: flyerUpdate.id, body: dtoUpdate); | ||
|
||
return updatePoiResponse.body!.transformToMarkerItem(); | ||
} | ||
} |
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 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.