Skip to content

Commit 5f50f59

Browse files
authored
feat: v3 use latest api (#217)
* feat: search notice with locale data * fix: change v3 api base url * fix: remove try-catch in notice list bloc * feat: use latest api * fix: additional notice deadline * fix: onEnglish condition * fix: write foreign if only needed * fix: fill missing deadline * fix: persist content * fix: show bell icon only remindable notice * fix: persist content in notice bloc * fix: put current deadline
1 parent ca4b27a commit 5f50f59

22 files changed

+201
-169
lines changed

lib/app/modules/core/domain/enums/api_channel.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'package:flutter/foundation.dart';
22

33
enum ApiChannel {
4-
staging('https://api.stg.ziggle.gistory.me/v1', 'https://stg.idp.gistory.me'),
5-
production('https://api.ziggle.gistory.me', 'https://idp.gistory.me');
4+
staging(
5+
'https://api.stg.ziggle.gistory.me/v3/', 'https://stg.idp.gistory.me'),
6+
production('https://api.ziggle.gistory.me/v3/', 'https://idp.gistory.me');
67

78
final String baseUrl;
89
final String idpBaseUrl;

lib/app/modules/notices/data/data_sources/remote/notice_api.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class NoticeApi {
3636
@GET('{id}')
3737
Future<NoticeModel> getNotice(
3838
@Path('id') int id, {
39+
@Query('lang') AppLocale? lang,
3940
@Query('isViewed') bool isViewed = false,
4041
});
4142

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:freezed_annotation/freezed_annotation.dart';
2+
3+
import '../../domain/entities/author_entity.dart';
4+
5+
part 'author_model.freezed.dart';
6+
part 'author_model.g.dart';
7+
8+
@freezed
9+
class AuthorModel with _$AuthorModel implements AuthorEntity {
10+
const factory AuthorModel({required String name, required String uuid}) =
11+
_AuthorModel;
12+
13+
factory AuthorModel.fromJson(Map<String, dynamic> json) =>
14+
_$AuthorModelFromJson(json);
15+
factory AuthorModel.fromEntity(AuthorEntity entity) =>
16+
AuthorModel(name: entity.name, uuid: entity.uuid);
17+
}

lib/app/modules/notices/data/models/notice_content_model.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class NoticeContentModel
1515
const factory NoticeContentModel({
1616
required int id,
1717
required AppLocale lang,
18-
@Default('') String title,
19-
required String body,
18+
required String content,
2019
DateTime? deadline,
2120
required DateTime createdAt,
2221
}) = _NoticeModel;
@@ -27,8 +26,7 @@ class NoticeContentModel
2726
NoticeContentModel(
2827
id: entity.id,
2928
lang: entity.lang,
30-
title: entity.title,
31-
body: entity.body,
29+
content: entity.content,
3230
deadline: entity.deadline,
3331
createdAt: entity.createdAt,
3432
);
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:freezed_annotation/freezed_annotation.dart';
2+
import 'package:ziggle/gen/strings.g.dart';
23

34
import '../../domain/entities/notice_entity.dart';
5+
import 'author_model.dart';
46
import 'notice_content_model.dart';
57
import 'notice_reaction_model.dart';
68

@@ -14,37 +16,43 @@ class NoticeModel with _$NoticeModel implements NoticeEntity {
1416
const factory NoticeModel({
1517
required int id,
1618
required int views,
19+
@Default([AppLocale.ko]) List<AppLocale> langs,
20+
DateTime? deadline,
1721
DateTime? currentDeadline,
1822
required DateTime createdAt,
19-
required DateTime updatedAt,
2023
DateTime? deletedAt,
21-
@Default([]) List tags,
22-
required List<NoticeContentModel> contents,
24+
@Default([]) List<String> tags,
25+
required String title,
26+
required String content,
27+
@Default([]) List<NoticeContentModel> additionalContents,
2328
required List<NoticeReactionModel> reactions,
24-
required String author,
25-
@Default('') String authorId,
26-
@Default([]) List<String> imagesUrl,
27-
@Default([]) List<String> documentsUrl,
28-
@Default(false) bool reminder,
29+
required AuthorModel author,
30+
@Default([]) List<String> imageUrls,
31+
@Default([]) List<String> documentUrls,
32+
@Default(false) bool isReminded,
2933
}) = _NoticeModel;
3034

3135
factory NoticeModel.fromJson(Map<String, dynamic> json) =>
3236
_$NoticeModelFromJson(json);
3337
factory NoticeModel.fromEntity(NoticeEntity entity) => NoticeModel(
3438
id: entity.id,
3539
views: entity.views,
40+
langs: entity.langs,
41+
deadline: entity.deadline,
3642
currentDeadline: entity.currentDeadline,
3743
createdAt: entity.createdAt,
38-
updatedAt: entity.updatedAt,
3944
deletedAt: entity.deletedAt,
4045
tags: entity.tags,
41-
contents: entity.contents.map(NoticeContentModel.fromEntity).toList(),
46+
title: entity.title,
47+
content: entity.content,
4248
reactions:
4349
entity.reactions.map(NoticeReactionModel.fromEntity).toList(),
44-
author: entity.author,
45-
authorId: entity.authorId,
46-
imagesUrl: entity.imagesUrl,
47-
documentsUrl: entity.documentsUrl,
48-
reminder: entity.reminder,
50+
additionalContents: entity.additionalContents
51+
.map(NoticeContentModel.fromEntity)
52+
.toList(),
53+
author: AuthorModel.fromEntity(entity.author),
54+
imageUrls: entity.imageUrls,
55+
documentUrls: entity.documentUrls,
56+
isReminded: entity.isReminded,
4957
);
5058
}

lib/app/modules/notices/data/models/notice_reaction_model.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@ class NoticeReactionModel
1313

1414
const factory NoticeReactionModel({
1515
required String emoji,
16-
required DateTime createdAt,
17-
DateTime? deletedAt,
18-
required int noticeId,
19-
required String userId,
16+
required int count,
17+
required bool isReacted,
2018
}) = _NoticeReactionModel;
2119

2220
factory NoticeReactionModel.fromJson(Map<String, dynamic> json) =>
2321
_$NoticeReactionModelFromJson(json);
2422
factory NoticeReactionModel.fromEntity(NoticeReactionEntity entity) =>
2523
NoticeReactionModel(
2624
emoji: entity.emoji,
27-
createdAt: entity.createdAt,
28-
deletedAt: entity.deletedAt,
29-
noticeId: entity.noticeId,
30-
userId: entity.userId,
25+
count: entity.count,
26+
isReacted: entity.isReacted,
3127
);
3228
}

lib/app/modules/notices/data/repositories/remote_notice_repository.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ class RemoteNoticeRepository implements NoticeRepository {
4646
limit: limit,
4747
search: search,
4848
tags: [if (type.isTag) type.name, ...tags],
49-
// lang: LocaleSettings.currentLocale,
49+
lang: LocaleSettings.currentLocale,
5050
orderBy: type.defaultSort,
5151
my: NoticeMy.fromType(type),
5252
);
5353
}
5454

5555
@override
5656
Future<NoticeEntity> getNotice(int id) {
57-
return _api.getNotice(id, isViewed: true);
57+
return _api.getNotice(
58+
id,
59+
lang: LocaleSettings.currentLocale,
60+
isViewed: true,
61+
);
5862
}
5963

6064
@override

lib/app/modules/notices/data/repositories/share_plus_notice_share_repository.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:injectable/injectable.dart';
22
import 'package:share_plus/share_plus.dart';
33
import 'package:ziggle/gen/strings.g.dart';
44

5-
import '../../domain/entities/notice_content_entity.dart';
65
import '../../domain/entities/notice_entity.dart';
76
import '../../domain/repositories/notice_share_repository.dart';
87

@@ -11,7 +10,7 @@ class SharePlusNoticeShareRepository implements NoticeShareRepository {
1110
@override
1211
Future<bool> shareNotice(NoticeEntity notice) async {
1312
final result = await Share.shareWithResult(t.notice.shareContent(
14-
title: notice.contents.main.title,
13+
title: notice.title,
1514
link: 'https://ziggle.gistory.me/notice/${notice.id}',
1615
));
1716
return result.status == ShareResultStatus.success;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AuthorEntity {
2+
final String name;
3+
final String uuid;
4+
5+
AuthorEntity({required this.name, required this.uuid});
6+
}

lib/app/modules/notices/domain/entities/notice_content_entity.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ class NoticeContentEntity {
55
const NoticeContentEntity({
66
required this.id,
77
required this.lang,
8-
required this.title,
9-
required this.body,
8+
required this.content,
109
this.deadline,
1110
required this.createdAt,
1211
});
1312

1413
final int id;
1514
final AppLocale lang;
16-
final String title;
17-
final String body;
15+
final String content;
1816
final DateTime? deadline;
1917
final DateTime createdAt;
2018
}

0 commit comments

Comments
 (0)