-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename Post to Article to avoid name clash with Chopper's P…
…ost class
- Loading branch information
Showing
6 changed files
with
78 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
...lice_chopper/lib/models/example_post.dart → ...les/alice_chopper/lib/models/article.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'example_post.g.dart'; | ||
part 'article.g.dart'; | ||
|
||
@JsonSerializable() | ||
class ExamplePost { | ||
class Article { | ||
final int? id; | ||
final String title; | ||
final String body; | ||
final int userId; | ||
|
||
const ExamplePost({ | ||
const Article({ | ||
this.id, | ||
required this.title, | ||
required this.body, | ||
required this.userId, | ||
}); | ||
|
||
ExamplePost copyWith({ | ||
Article copyWith({ | ||
int? id, | ||
String? title, | ||
String? body, | ||
int? userId, | ||
}) => | ||
ExamplePost( | ||
Article( | ||
id: id ?? this.id, | ||
title: title ?? this.title, | ||
body: body ?? this.body, | ||
userId: userId ?? this.userId, | ||
); | ||
|
||
factory ExamplePost.fromJson(Map<String, dynamic> json) => | ||
_$ExamplePostFromJson(json); | ||
factory Article.fromJson(Map<String, dynamic> json) => | ||
_$ArticleFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ExamplePostToJson(this); | ||
Map<String, dynamic> toJson() => _$ArticleToJson(this); | ||
} |
7 changes: 3 additions & 4 deletions
7
...ce_chopper/lib/models/example_post.g.dart → ...s/alice_chopper/lib/models/article.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 17 additions & 17 deletions
34
...rvices/example_posts_service.chopper.dart → ...ib/services/articles_service.chopper.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:chopper/chopper.dart'; | ||
import 'package:example/models/article.dart'; | ||
|
||
// this is necessary for the generated code to find your class | ||
part 'articles_service.chopper.dart'; | ||
|
||
@ChopperApi(baseUrl: '/posts') | ||
abstract class ArticlesService extends ChopperService { | ||
// helper methods that help you instantiate your service | ||
static ArticlesService create([ChopperClient? client]) => | ||
_$ArticlesService(client); | ||
|
||
@Get(path: '/', timeout: Duration(seconds: 10)) | ||
Future<Response<List<Article>>> getAll({ | ||
@Query() int? userId, | ||
}); | ||
|
||
@Get(path: '/{id}', timeout: Duration(seconds: 10)) | ||
Future<Response<Article?>> get(@Path() int id); | ||
|
||
@Post(path: '/', timeout: Duration(seconds: 10)) | ||
Future<Response<Article?>> post(@Body() Article body); | ||
|
||
@Put(path: '/{id}', timeout: Duration(seconds: 10)) | ||
Future<Response<Article?>> put(@Path() int id, @Body() Article body); | ||
|
||
@Patch(path: '/{id}', timeout: Duration(seconds: 10)) | ||
Future<Response<Article?>> patch(@Path() int id, @Body() Article body); | ||
|
||
@Delete(path: '/{id}', timeout: Duration(seconds: 10)) | ||
Future<Response<void>> delete(@Path() int id); | ||
} |
38 changes: 0 additions & 38 deletions
38
examples/alice_chopper/lib/services/example_posts_service.dart
This file was deleted.
Oops, something went wrong.