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

feat: Integrate all routes from nutripatrol's API #991

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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: 24 additions & 0 deletions example/lib/main.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickly said: test your code in test files, not in main.

Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import 'dart:async';

import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:json_annotation/src/json_value.dart';
import 'package:openfoodfacts/src/nutripatrol/get_ticket.dart';

void main() {
OpenFoodAPIConfiguration.userAgent = UserAgent(
name: 'openfoodfacts-dart',
version: '1.0.0',
url: '',
);
getTickets();
}

/// Get the ticket by its ID
/// The result will be a MaybeError<Ticket> that can be parsed
void getTicket() async {
await NutripatrolApiClient.getTicket(ticketId: 2);
}

/// Get all tickets
/// The result will be a MaybeError<Tickets> that can be parsed
void getTickets() async {
await NutripatrolApiClient.getTickets(
status: TicketStatus.open, type_: TicketType.image, page: 1);
}

/// request a product from the OpenFoodFacts database
Future<Product?> getProduct() async {
Expand Down
1 change: 1 addition & 0 deletions lib/openfoodfacts.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably need to add the other nutripatrol classes.

Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ export 'src/utils/unit_helper.dart';
export 'src/utils/uri_helper.dart';
export 'src/utils/uri_reader.dart';
export 'src/robot_off_api_client.dart';
export 'src/nutripatrol_api_client.dart';
98 changes: 98 additions & 0 deletions lib/src/nutripatrol/create_flag.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'package:json_annotation/json_annotation.dart';

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

part 'create_flag.g.dart';

@JsonSerializable()
class Flag extends JsonObject {
Valimp marked this conversation as resolved.
Show resolved Hide resolved
@JsonKey()
late String id;

@JsonKey()
String? barcode;

@JsonKey()
late Type type;

@JsonKey()
String? url;

@JsonKey(name: 'user_id')
late String userId;

@JsonKey()
late Source source;

@JsonKey()
double? confidence;

@JsonKey(name: 'image_id')
String? imageId;

@JsonKey()
late Flavor flavor;

@JsonKey()
String? reason;

@JsonKey()
String? comment;

@JsonKey(name: 'created_at')
late DateTime CreatedAt;

@JsonKey(name: 'ticket_id')
late int ticketId;

@JsonKey(name: 'device_id')
late String deviceId;

Flag();

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

@override Map<String, dynamic> toJson() => _$FlagToJson(this);
}

/// Enum for ticket type
enum Type {
Valimp marked this conversation as resolved.
Show resolved Hide resolved
@JsonValue('image')
image,

@JsonValue('product')
product,

@JsonValue('search')
search
}

/// Enum for ticket type
enum Source {
Valimp marked this conversation as resolved.
Show resolved Hide resolved
@JsonValue('mobile')
mobile,

@JsonValue('web')
web,

@JsonValue('robotoff')
robotoff
}

/// Enum for ticket flavor
enum Flavor {
Valimp marked this conversation as resolved.
Show resolved Hide resolved
@JsonValue('off')
off,

@JsonValue('obf')
obf,

@JsonValue('opff')
opff,

@JsonValue('opf')
opf,

@JsonValue('off-pro')
offPro
}
60 changes: 60 additions & 0 deletions lib/src/nutripatrol/create_flag.g.dart

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

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

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

part 'get_ticket.g.dart';

@JsonSerializable()
class Ticket extends JsonObject {
/// Flag ID. Read-only.
@JsonKey()
late int id;

/// Barcode of the product. Read-only.
@JsonKey()
String? barcode;

/// Type of the ticket.
@JsonKey()
late TicketType type;

/// Url of the ticket. Read-only.
@JsonKey()
late String url;

/// Status of the ticket.
@JsonKey()
late TicketStatus status;

/// Image id of the ticket. Read-only.
@JsonKey(name: 'image_id')
String? imageId;

/// Flavor of the ticket.
@JsonKey()
late Flavor flavor;

/// created date of the ticket. Read-only.
@JsonKey(name: 'created_at')
late String CreatedAt;

Ticket();

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

@override Map<String, dynamic> toJson() => _$TicketToJson(this);
}

/// Enum for ticket type
enum TicketType {
Valimp marked this conversation as resolved.
Show resolved Hide resolved
@JsonValue('image')
image,

@JsonValue('product')
product,

@JsonValue('search')
search
}

/// Enum for ticket status
enum TicketStatus {
@JsonValue('open')
open,

@JsonValue('closed')
closed
}

/// Enum for ticket flavor
enum Flavor {
Valimp marked this conversation as resolved.
Show resolved Hide resolved
@JsonValue('off')
off,

@JsonValue('obf')
obf,

@JsonValue('opff')
opff,

@JsonValue('opf')
opf,

@JsonValue('off-pro')
offPro
}
47 changes: 47 additions & 0 deletions lib/src/nutripatrol/get_ticket.g.dart

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

23 changes: 23 additions & 0 deletions lib/src/nutripatrol/get_tickets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:json_annotation/json_annotation.dart';
import 'get_ticket.dart';

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

part 'get_tickets.g.dart';

@JsonSerializable()
class Tickets extends JsonObject {
/// List of Tickets
@JsonKey()
late List<Ticket> tickets;

/// Max Page
@JsonKey(name: 'max_page')
late int maxPage;

Tickets();

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

@override Map<String, dynamic> toJson() => _$TicketsToJson(this);
}
18 changes: 18 additions & 0 deletions lib/src/nutripatrol/get_tickets.g.dart

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

Loading
Loading