Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pub/lints-5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki authored Oct 4, 2024
2 parents d6de3c7 + b007587 commit ec244f3
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dartdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: dart doc .

- name: Deploy API documentation to Github Pages
uses: JamesIves/[email protected].4
uses: JamesIves/[email protected].8
with:
BRANCH: gh-pages
FOLDER: doc/api/
12 changes: 6 additions & 6 deletions .github/workflows/github-projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ jobs:
label-operator: AND
- uses: actions/add-to-project@main
with:
project-url: https://github.com/orgs/openfoodfacts/projects/36 # Add issue to the open pet food facts project
project-url: https://github.com/orgs/openfoodfacts/projects/36 # Add issue to the Open Pet Food Facts project
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
labeled: 🐾 Open Pet Food Facts
label-operator: OR
- uses: actions/add-to-project@main
with:
project-url: https://github.com/orgs/openfoodfacts/projects/11 # Add issue to the open products facts project
project-url: https://github.com/orgs/openfoodfacts/projects/43 # Add issue to the Open Products Facts project
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
labeled: 📸 Open Products Facts
label-operator: OR
- uses: actions/add-to-project@main
with:
project-url: https://github.com/orgs/openfoodfacts/projects/37 # Add issue to the open beauty facts project
project-url: https://github.com/orgs/openfoodfacts/projects/37 # Add issue to the Open Beauty Facts project
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
labeled: 🧴 Open Beauty Facts
label-operator: OR
Expand All @@ -52,19 +52,19 @@ jobs:
label-operator: OR
- uses: actions/add-to-project@main
with:
project-url: https://github.com/orgs/openfoodfacts/projects/5 # Add issue to the folksonomy project
project-url: https://github.com/orgs/openfoodfacts/projects/5 # Add issue to the Folksonomy project
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
labeled: 🏷️ Folksonomy Project
label-operator: OR
- uses: actions/add-to-project@main
with:
project-url: https://github.com/orgs/openfoodfacts/projects/44 # Add issue to the data quality project
project-url: https://github.com/orgs/openfoodfacts/projects/44 # Add issue to the Data Quality project
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
labeled: 🧽 Data quality
label-operator: OR
- uses: actions/add-to-project@main
with:
project-url: https://github.com/orgs/openfoodfacts/projects/82 # Add issue to the search project
project-url: https://github.com/orgs/openfoodfacts/projects/82 # Add issue to the Search project
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
labeled: 🔎 Search
label-operator: OR
Expand Down
1 change: 1 addition & 0 deletions lib/openfoodfacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export 'src/prices/order_by.dart';
export 'src/prices/price.dart';
export 'src/prices/price_per.dart';
export 'src/prices/price_product.dart';
export 'src/prices/price_total_stats.dart';
export 'src/prices/price_user.dart';
export 'src/prices/proof.dart';
export 'src/prices/proof_type.dart';
Expand Down
26 changes: 26 additions & 0 deletions lib/src/open_prices_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'prices/get_users_result.dart';
import 'prices/location.dart';
import 'prices/location_osm_type.dart';
import 'prices/price_product.dart';
import 'prices/price_total_stats.dart';
import 'prices/proof_type.dart';
import 'prices/session.dart';
import 'prices/update_price_parameters.dart';
Expand Down Expand Up @@ -612,4 +613,29 @@ class OpenPricesAPIClient {
}
return MaybeError<GetUsersResult>.responseError(response);
}

/// Returns the total stats.
static Future<MaybeError<PriceTotalStats>> getStats({
final UriProductHelper uriHelper = uriHelperFoodProd,
}) async {
final Uri uri = getUri(
path: '/api/v1/stats',
uriHelper: uriHelper,
);
final Response response = await HttpHelper().doGetRequest(
uri,
uriHelper: uriHelper,
);
if (response.statusCode == 200) {
try {
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
return MaybeError<PriceTotalStats>.value(
PriceTotalStats.fromJson(decodedResponse),
);
} catch (e) {
//
}
}
return MaybeError<PriceTotalStats>.responseError(response);
}
}
18 changes: 15 additions & 3 deletions lib/src/prices/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part 'location.g.dart';

/// Location object in the Prices API.
///
/// cf. `LocationBase` in https://prices.openfoodfacts.net/docs
/// cf. `Location` in https://prices.openfoodfacts.org/api/docs
@JsonSerializable()
class Location extends JsonObject {
/// ID of the location in OpenStreetMap: the store where the product was bought.
Expand All @@ -25,7 +25,19 @@ class Location extends JsonObject {

/// Number of prices for this location.
@JsonKey(name: 'price_count')
late int priceCount;
int? priceCount;

/// Number of users for this location.
@JsonKey(name: 'user_count')
int? userCount;

/// Number of products for this location.
@JsonKey(name: 'product_count')
int? productCount;

/// Number of proofs for this location.
@JsonKey(name: 'proof_count')
int? proofCount;

/// ID in the Prices API.
@JsonKey(name: 'id')
Expand Down Expand Up @@ -65,7 +77,7 @@ class Location extends JsonObject {
@JsonKey(fromJson: JsonHelper.stringTimestampToDate)
late DateTime created;

/// Date when the product was bought.
/// Latest update timestamp.
@JsonKey(fromJson: JsonHelper.nullableStringTimestampToDate)
DateTime? updated;

Expand Down
8 changes: 7 additions & 1 deletion lib/src/prices/location.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions lib/src/prices/price_product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part 'price_product.g.dart';

/// Product object in the Prices API.
///
/// cf. `ProductFull` in https://prices.openfoodfacts.net/docs
/// cf. `ProductFull` in https://prices.openfoodfacts.org/api/docs
@JsonSerializable()
class PriceProduct extends JsonObject {
/// Barcode (EAN) of the product, as a string.
Expand All @@ -17,7 +17,19 @@ class PriceProduct extends JsonObject {

/// Number of prices for this product.
@JsonKey(name: 'price_count')
late int priceCount;
int? priceCount;

/// Number of locations for this product.
@JsonKey(name: 'location_count')
int? locationCount;

/// Number of users for this product.
@JsonKey(name: 'user_count')
int? userCount;

/// Number of proofs for this product.
@JsonKey(name: 'proof_count')
int? proofCount;

@JsonKey(name: 'id')
late int productId;
Expand Down
8 changes: 7 additions & 1 deletion lib/src/prices/price_product.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions lib/src/prices/price_total_stats.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'package:json_annotation/json_annotation.dart';

import '../interface/json_object.dart';
import '../utils/json_helper.dart';

part 'price_total_stats.g.dart';

/// Total stats for Prices.
///
/// cf. `TotalStats` in https://prices.openfoodfacts.org/api/docs
@JsonSerializable()
class PriceTotalStats extends JsonObject {
@JsonKey(name: 'price_count')
int? priceCount;

@JsonKey(name: 'price_type_product_code_count')
int? priceTypeProductCodeCount;

@JsonKey(name: 'price_type_category_tag_count')
int? priceTypeCategoryTagCount;

@JsonKey(name: 'product_count')
int? productCount;

@JsonKey(name: 'product_with_price_count')
int? productWithPriceCount;

@JsonKey(name: 'location_count')
int? locationCount;

@JsonKey(name: 'location_with_price_count')
int? locationWithPriceCount;

@JsonKey(name: 'proof_count')
int? proofCount;

@JsonKey(name: 'proof_with_price_count')
int? proofWithPriceCount;

@JsonKey(name: 'proof_type_price_tag_count')
int? proofTypePriceTagCount;

@JsonKey(name: 'proof_type_receipt_count')
int? proofTypeReceiptCount;

@JsonKey(name: 'user_count')
int? userCount;

@JsonKey(name: 'user_with_price_count')
int? userWithPriceCount;

@JsonKey(fromJson: JsonHelper.nullableStringTimestampToDate)
DateTime? updated;

PriceTotalStats();

factory PriceTotalStats.fromJson(Map<String, dynamic> json) =>
_$PriceTotalStatsFromJson(json);

@override
Map<String, dynamic> toJson() => _$PriceTotalStatsToJson(this);
}
48 changes: 48 additions & 0 deletions lib/src/prices/price_total_stats.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions lib/src/prices/price_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ part 'price_user.g.dart';

/// Price user object.
///
/// cf. `UserBase` in https://prices.openfoodfacts.org/api/docs
/// cf. `User` in https://prices.openfoodfacts.org/api/docs
@JsonSerializable()
class PriceUser extends JsonObject {
@JsonKey(name: 'user_id')
late String userId;

/// Number of prices for this user.
@JsonKey(name: 'price_count')
late int priceCount;
int? priceCount;

/// Number of prices for this user.
@JsonKey(name: 'is_moderator')
bool? isModerator;
/// Number of locations for this user.
@JsonKey(name: 'location_count')
int? locationCount;

/// Number of products for this user.
@JsonKey(name: 'product_count')
int? productCount;

/// Number of proofs for this user.
@JsonKey(name: 'proof_count')
int? proofCount;

PriceUser();

Expand Down
10 changes: 7 additions & 3 deletions lib/src/prices/price_user.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec244f3

Please sign in to comment.