-
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
443 additions
and
151 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
23 changes: 23 additions & 0 deletions
23
lib/app/services/converters/door_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,23 @@ | ||
part of '../converters.dart'; | ||
|
||
extension DoorCreateModelParsing on DoorCreateModel { | ||
DoorDetailModel transformToDoorDetailModel(String temporaryId) { | ||
return DoorDetailModel( | ||
id: temporaryId, | ||
address: address, | ||
closedDoors: closedDoors, | ||
openedDoors: openedDoors, | ||
location: location, | ||
createdAt: '${DateTime.now().getAsLocalDateTimeString()}*', // should mark this as preliminary | ||
isCached: true, | ||
); | ||
} | ||
|
||
MarkerItemModel transformToVirtualMarkerItem(int temporaryId) { | ||
return MarkerItemModel.virtual( | ||
id: temporaryId, | ||
status: PoiServiceType.door.name, | ||
location: location, | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
lib/app/services/converters/door_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,21 @@ | ||
part of '../converters.dart'; | ||
|
||
extension DoorUpdateModelParsing on DoorUpdateModel { | ||
DoorDetailModel transformToDoorDetailModel() { | ||
var newDoorDetail = oldDoorDetail.copyWith( | ||
address: address, | ||
closedDoors: closedDoors, | ||
openedDoors: openedDoors, | ||
isCached: true, | ||
); | ||
return newDoorDetail; | ||
} | ||
|
||
MarkerItemModel transformToVirtualMarkerItem() { | ||
return MarkerItemModel.virtual( | ||
id: int.parse(id), | ||
status: PoiServiceType.door.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
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
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,45 @@ | ||
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/doors/door_create_model.dart'; | ||
import 'package:gruene_app/features/campaigns/models/doors/door_detail_model.dart'; | ||
import 'package:gruene_app/features/campaigns/models/doors/door_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 GrueneApiDoorService extends GrueneApiCampaignsService { | ||
GrueneApiDoorService() : super(poiType: PoiServiceType.door); | ||
|
||
Future<MarkerItemModel> createNewDoor(DoorCreateModel newDoor) async { | ||
final requestParam = CreatePoi( | ||
coords: newDoor.location.transformToGeoJsonCoords(), | ||
type: poiType.transformToApiCreateType(), | ||
address: newDoor.address.transformToPoiAddress(), | ||
house: PoiHouse( | ||
countOpenedDoors: newDoor.openedDoors.toDouble(), | ||
countClosedDoors: newDoor.closedDoors.toDouble(), | ||
), | ||
); | ||
// saving POI | ||
final newPoiResponse = await grueneApi.v1CampaignsPoisPost(body: requestParam); | ||
|
||
return newPoiResponse.body!.transformToMarkerItem(); | ||
} | ||
|
||
Future<MarkerItemModel> updateDoor(DoorUpdateModel doorUpdate) async { | ||
var dtoUpdate = UpdatePoi( | ||
address: doorUpdate.address.transformToPoiAddress(), | ||
house: PoiHouse( | ||
countOpenedDoors: doorUpdate.openedDoors.toDouble(), | ||
countClosedDoors: doorUpdate.closedDoors.toDouble(), | ||
), | ||
); | ||
var updatePoiResponse = await grueneApi.v1CampaignsPoisPoiIdPut(poiId: doorUpdate.id, body: dtoUpdate); | ||
|
||
return updatePoiResponse.body!.transformToMarkerItem(); | ||
} | ||
|
||
Future<DoorDetailModel> getPoiAsDoorDetail(String poiId) { | ||
return getPoi(poiId, (p) => p.transformPoiToDoorDetail()); | ||
} | ||
} |
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.