-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrelationship_fetched.dart
27 lines (22 loc) · 978 Bytes
/
relationship_fetched.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import 'package:json_api/document.dart';
import 'package:json_api/src/client/response.dart';
/// A response to a relationship fetch request.
class RelationshipFetched<R extends Relationship> {
RelationshipFetched(this.rawResponse, this.relationship);
static RelationshipFetched<ToMany> many(Response response) {
final document = InboundDocument(response.document ??
(throw FormatException('The document must not be empty')));
return RelationshipFetched(response, document.asToMany())
..included.addAll(document.included());
}
static RelationshipFetched<ToOne> one(Response response) {
final document = InboundDocument(response.document ??
(throw FormatException('The document must not be empty')));
return RelationshipFetched(response, document.asToOne())
..included.addAll(document.included());
}
/// The raw JSON:API response
final Response rawResponse;
final R relationship;
final included = <Resource>[];
}