Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 970 - refactored around new Prices API #971

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions lib/src/open_prices_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class OpenPricesAPIClient {
uriHelper: uriHelper,
bearerToken: bearerToken,
);
if (response.statusCode == 200) {
if (response.statusCode == 204) {
return MaybeError<bool>.value(true);
}
return MaybeError<bool>.responseError(response);
Expand Down Expand Up @@ -369,7 +369,7 @@ class OpenPricesAPIClient {
///
/// This endpoint requires authentication.
/// A user can update only owned prices.
static Future<MaybeError<Price>> updatePrice(
static Future<MaybeError<bool>> updatePrice(
final int priceId, {
required final UpdatePriceParameters parameters,
final UriProductHelper uriHelper = uriHelperFoodProd,
Expand All @@ -388,14 +388,9 @@ class OpenPricesAPIClient {
addUserAgentParameters: false,
);
if (response.statusCode == 200) {
try {
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
return MaybeError<Price>.value(Price.fromJson(decodedResponse));
} catch (e) {
//
}
return MaybeError<bool>.value(true);
}
return MaybeError<Price>.responseError(response);
return MaybeError<bool>.responseError(response);
}

/// Deletes a price.
Expand Down Expand Up @@ -540,7 +535,7 @@ class OpenPricesAPIClient {
///
/// This endpoint requires authentication.
/// A user can update only owned proofs.
static Future<MaybeError<Proof>> updateProof(
static Future<MaybeError<bool>> updateProof(
final int proofId, {
required final UpdateProofParameters parameters,
final UriProductHelper uriHelper = uriHelperFoodProd,
Expand All @@ -559,14 +554,9 @@ class OpenPricesAPIClient {
addUserAgentParameters: false,
);
if (response.statusCode == 200) {
try {
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
return MaybeError<Proof>.value(Proof.fromJson(decodedResponse));
} catch (e) {
//
}
return MaybeError<bool>.value(true);
}
return MaybeError<Proof>.responseError(response);
return MaybeError<bool>.responseError(response);
}

/// Deletes a proof.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/prices/price_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PriceUser extends JsonObject {

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

PriceUser();

Expand Down
2 changes: 1 addition & 1 deletion lib/src/prices/price_user.g.dart

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

10 changes: 10 additions & 0 deletions lib/src/prices/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class Session extends JsonObject {
@override
Map<String, dynamic> toJson() => _$SessionToJson(this);

/// Status Code when the authentication fails.
static const int invalidAuthStatusCode = 401;

/// Error message when the authentication fails.
static const String invalidAuthMessage = 'Invalid authentication credentials';

/// Status Code when we try an edit operation with a wrong authentication.
static const int invalidActionWithAuthStatusCode = 403;

/// Error message when we try an edit operation with a wrong authentication.
static const String invalidActionWithAuthMessage =
'Authentication credentials were not provided.';
}
Loading