1+ import 'dart:convert' ;
12import 'dart:io' ;
23
34import 'package:dio/dio.dart' ;
5+ import 'package:gsy_github_app_flutter/common/ab/provider/repos/RepositoryIssueDbProvider.dart' ;
46import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart' ;
57import 'package:gsy_github_app_flutter/common/model/Issue.dart' ;
68import 'package:gsy_github_app_flutter/common/net/Address.dart' ;
@@ -22,22 +24,41 @@ class IssueDao {
2224 * @param sort 排序类型 created updated等
2325 * @param direction 正序或者倒序
2426 */
25- static getRepositoryIssueDao (userName, repository, state, {sort, direction, page = 0 }) async {
26- String url = Address .getReposIssue (userName, repository, state, sort, direction) + Address .getPageParams ("&" , page);
27- var res = await HttpManager .netFetch (url, null , {"Accept" : 'application/vnd.github.html,application/vnd.github.VERSION.raw' }, null );
28- if (res != null && res.result) {
29- List <Issue > list = new List ();
30- var data = res.data;
31- if (data == null || data.length == 0 ) {
27+ static getRepositoryIssueDao (userName, repository, state, {sort, direction, page = 0 , needDb = false }) async {
28+ String fullName = userName + "/" + repository;
29+ String dbState = state ?? "*" ;
30+ RepositoryIssueDbProvider provider = new RepositoryIssueDbProvider ();
31+
32+ next () async {
33+ String url = Address .getReposIssue (userName, repository, state, sort, direction) + Address .getPageParams ("&" , page);
34+ var res = await HttpManager .netFetch (url, null , {"Accept" : 'application/vnd.github.html,application/vnd.github.VERSION.raw' }, null );
35+ if (res != null && res.result) {
36+ List <Issue > list = new List ();
37+ var data = res.data;
38+ if (data == null || data.length == 0 ) {
39+ return new DataResult (null , false );
40+ }
41+ for (int i = 0 ; i < data.length; i++ ) {
42+ list.add (Issue .fromJson (data[i]));
43+ }
44+ if (needDb) {
45+ provider.insert (fullName, dbState, json.encode (data));
46+ }
47+ return new DataResult (list, true );
48+ } else {
3249 return new DataResult (null , false );
3350 }
34- for (int i = 0 ; i < data.length; i++ ) {
35- list.add (Issue .fromJson (data[i]));
51+ }
52+
53+ if (needDb) {
54+ List <Issue > list = await provider.getData (fullName, dbState);
55+ if (list == null ) {
56+ return await next ();
3657 }
37- return new DataResult (list, true );
38- } else {
39- return new DataResult (null , false );
58+ DataResult dataResult = new DataResult (list, true , next: next ());
59+ return dataResult;
4060 }
61+ return await next ();
4162 }
4263
4364 /**
@@ -139,8 +160,8 @@ class IssueDao {
139160 */
140161 static lockIssueDao (userName, repository, number, locked) async {
141162 String url = Address .lockIssue (userName, repository, number);
142- var res = await HttpManager .netFetch (
143- url, null , { "Accept" : 'application/vnd.github.VERSION.full+json' }, new Options (method: locked ? "DELETE" : 'PUT' , contentType: ContentType .TEXT ),
163+ var res = await HttpManager .netFetch (url, null , { "Accept" : 'application/vnd.github.VERSION.full+json' },
164+ new Options (method: locked ? "DELETE" : 'PUT' , contentType: ContentType .TEXT ),
144165 noTip: true );
145166 if (res != null && res.result) {
146167 return new DataResult (res.data, true );
0 commit comments