Skip to content

Instantly share code, notes, and snippets.

@fabricenyonato
Last active August 27, 2022 15:39
Show Gist options
  • Save fabricenyonato/7dc085f0315f6daf219f264979320db4 to your computer and use it in GitHub Desktop.
Save fabricenyonato/7dc085f0315f6daf219f264979320db4 to your computer and use it in GitHub Desktop.
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:vinland/src/models/image.dart';
part 'article.freezed.dart';
part 'article.g.dart';
@freezed
class ArticleAttributes with _$ArticleAttributes {
factory ArticleAttributes({
required String title,
required String summary,
required String content,
required ImageResponse image,
})
= _ArticleAttributes;
factory ArticleAttributes.fromJson(Map<String, dynamic> json) =>
_$ArticleAttributesFromJson(json);
}
@freezed
class Article with _$Article {
factory Article({
required int id,
required ArticleAttributes attributes
})
= _Article;
factory Article.fromJson(Map<String, dynamic> json) =>
_$ArticleFromJson(json);
}
@freezed
class ArticleResponse with _$ArticleResponse {
factory ArticleResponse({
required List<Article> data,
})
= _ArticleResponse;
factory ArticleResponse.fromJson(Map<String, dynamic> json) =>
_$ArticleResponseFromJson(json);
}
@freezed
class ArticlesResponse with _$ArticlesResponse {
factory ArticlesResponse({
required List<Article> data,
})
= _ArticlesResponse;
factory ArticlesResponse.fromJson(Map<String, dynamic> json) =>
_$ArticlesResponseFromJson(json);
}
import 'package:freezed_annotation/freezed_annotation.dart';
part 'image.freezed.dart';
part 'image.g.dart';
@freezed
class ImageAttributes with _$ImageAttributes {
factory ImageAttributes({
required String url,
})
= _ImageAttributes;
factory ImageAttributes.fromJson(Map<String, dynamic> json) =>
_$ImageAttributesFromJson(json);
}
@freezed
class Image with _$Image {
factory Image({
required int id,
required ImageAttributes attributes
})
= _Image;
factory Image.fromJson(Map<String, dynamic> json) =>
_$ImageFromJson(json);
}
@freezed
class ImageResponse with _$ImageResponse {
factory ImageResponse({
required Image data,
})
= _ImageResponse;
factory ImageResponse.fromJson(Map<String, dynamic> json) =>
_$ImageResponseFromJson(json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment