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
8 changed files
with
206 additions
and
1 deletion.
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
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:apetito_product_api_client/src/models/model.dart'; | ||
import 'package:apetito_product_api_client/src/models/product.dart'; | ||
import 'package:apetito_product_api_client/src/models/warning.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'product_warning.g.dart'; | ||
|
||
@JsonSerializable() | ||
class ProductWarning extends Model<String> { | ||
Product? product; | ||
Warning? warning; | ||
|
||
ProductWarning({ | ||
required String id, | ||
this.product, | ||
this.warning, | ||
}) : super( | ||
id: id, | ||
); | ||
|
||
factory ProductWarning.fromJson(Map<String, dynamic> json) => | ||
_$ProductWarningFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ProductWarningToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:apetito_product_api_client/src/models/model.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'warning.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Warning extends Model<String> { | ||
String? name; | ||
|
||
Warning({ | ||
required String id, | ||
this.name, | ||
}) : super( | ||
id: id, | ||
); | ||
|
||
factory Warning.fromJson(Map<String, dynamic> json) => | ||
_$WarningFromJson(json); | ||
|
||
@override | ||
String toString() => name ?? super.toString(); | ||
|
||
Map<String, dynamic> toJson() => _$WarningToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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,66 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:apetito_product_api_client/src/apetito_product_api_client_base.dart'; | ||
import 'package:apetito_product_api_client/src/constants/uri_constants.dart'; | ||
import 'package:apetito_product_api_client/src/exceptions/client_exception.dart'; | ||
import 'package:apetito_product_api_client/src/models/product.dart'; | ||
import 'package:apetito_product_api_client/src/models/product_warning.dart'; | ||
import 'package:apetito_product_api_client/src/models/warning.dart'; | ||
|
||
class WarningService { | ||
final ApetitoProductApiClientContext _context; | ||
|
||
WarningService({ | ||
required ApetitoProductApiClientContext context, | ||
}) : _context = context; | ||
|
||
/// Gets all the warnings. | ||
Future<List<Warning>> get() async { | ||
final response = await _context.client.get( | ||
Uri.https(authority, '$path/warnings'), | ||
); | ||
|
||
ClientException.checkIsSuccessStatusCode(response); | ||
|
||
return (json.decode(response.body) as List) | ||
.map((e) => Warning.fromJson(e)) | ||
.toList(); | ||
} | ||
|
||
/// Gets the warning that matches an id. | ||
Future<Warning> getById(String id) async { | ||
final response = await _context.client.get( | ||
Uri.https(authority, '$path/warnings/$id'), | ||
); | ||
|
||
ClientException.checkIsSuccessStatusCode(response); | ||
|
||
return Warning.fromJson(json.decode(response.body)); | ||
} | ||
|
||
/// Gets all the product warning information of the warning that matches an id. | ||
Future<List<ProductWarning>> getByIdProductWarnings(String id) async { | ||
final response = await _context.client.get( | ||
Uri.https(authority, '$path/warnings/$id/productwarnings'), | ||
); | ||
|
||
ClientException.checkIsSuccessStatusCode(response); | ||
|
||
return (json.decode(response.body) as List) | ||
.map((e) => ProductWarning.fromJson(e)) | ||
.toList(); | ||
} | ||
|
||
/// Gets all the products of the warning that matches an id. | ||
Future<List<Product>> getByIdProducts(String id) async { | ||
final response = await _context.client.get( | ||
Uri.https(authority, '$path/warnings/$id/products'), | ||
); | ||
|
||
ClientException.checkIsSuccessStatusCode(response); | ||
|
||
return (json.decode(response.body) as List) | ||
.map((e) => Product.fromJson(e)) | ||
.toList(); | ||
} | ||
} |