@@ -2,6 +2,8 @@ import 'dart:convert';
22import 'dart:io' ;
33
44import 'package:dio/dio.dart' ;
5+ import 'package:gsy_github_app_flutter/common/ab/provider/issue/IssueCommentDbProvider.dart' ;
6+ import 'package:gsy_github_app_flutter/common/ab/provider/issue/IssueDetailDbProvider.dart' ;
57import 'package:gsy_github_app_flutter/common/ab/provider/repos/RepositoryIssueDbProvider.dart' ;
68import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart' ;
79import 'package:gsy_github_app_flutter/common/model/Issue.dart' ;
@@ -96,37 +98,74 @@ class IssueDao {
9698 /**
9799 * issue的详请
98100 */
99- static getIssueInfoDao (userName, repository, number) async {
100- String url = Address .getIssueInfo (userName, repository, number);
101- //{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
102- var res = await HttpManager .netFetch (url, null , {"Accept" : 'application/vnd.github.VERSION.raw' }, null );
103- if (res != null && res.result) {
104- return new DataResult (Issue .fromJson (res.data), true );
105- } else {
106- return new DataResult (null , false );
101+ static getIssueInfoDao (userName, repository, number, {needDb = true }) async {
102+ String fullName = userName + "/" + repository;
103+
104+ IssueDetailDbProvider provider = new IssueDetailDbProvider ();
105+
106+ next () async {
107+ String url = Address .getIssueInfo (userName, repository, number);
108+ //{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
109+ var res = await HttpManager .netFetch (url, null , {"Accept" : 'application/vnd.github.VERSION.raw' }, null );
110+ if (res != null && res.result) {
111+ if (needDb) {
112+ provider.insert (fullName, number, json.encode (res.data));
113+ }
114+ return new DataResult (Issue .fromJson (res.data), true );
115+ } else {
116+ return new DataResult (null , false );
117+ }
107118 }
119+
120+ if (needDb) {
121+ Issue issue = await provider.getRepository (fullName, number);
122+ if (issue == null ) {
123+ return await next ();
124+ }
125+ DataResult dataResult = new DataResult (issue, true , next: next ());
126+ return dataResult;
127+ }
128+ return await next ();
108129 }
109130
110131 /**
111132 * issue的详请列表
112133 */
113- static getIssueCommentDao (userName, repository, number, {page: 0 }) async {
114- String url = Address .getIssueComment (userName, repository, number) + Address .getPageParams ("?" , page);
115- //{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
116- var res = await HttpManager .netFetch (url, null , {"Accept" : 'application/vnd.github.VERSION.raw' }, null );
117- if (res != null && res.result) {
118- List <Issue > list = new List ();
119- var data = res.data;
120- if (data == null || data.length == 0 ) {
134+ static getIssueCommentDao (userName, repository, number, {page: 0 , needDb = false }) async {
135+ String fullName = userName + "/" + repository;
136+ IssueCommentDbProvider provider = new IssueCommentDbProvider ();
137+
138+ next () async {
139+ String url = Address .getIssueComment (userName, repository, number) + Address .getPageParams ("?" , page);
140+ //{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
141+ var res = await HttpManager .netFetch (url, null , {"Accept" : 'application/vnd.github.VERSION.raw' }, null );
142+ if (res != null && res.result) {
143+ List <Issue > list = new List ();
144+ var data = res.data;
145+ if (data == null || data.length == 0 ) {
146+ return new DataResult (null , false );
147+ }
148+ if (needDb) {
149+ provider.insert (fullName, number, json.encode (res.data));
150+ }
151+ for (int i = 0 ; i < data.length; i++ ) {
152+ list.add (Issue .fromJson (data[i]));
153+ }
154+ return new DataResult (list, true );
155+ } else {
121156 return new DataResult (null , false );
122157 }
123- for (int i = 0 ; i < data.length; i++ ) {
124- list.add (Issue .fromJson (data[i]));
158+ }
159+
160+ if (needDb) {
161+ List <Issue > list = await provider.getData (fullName, number);
162+ if (list == null ) {
163+ return await next ();
125164 }
126- return new DataResult (list, true );
127- } else {
128- return new DataResult (null , false );
165+ DataResult dataResult = new DataResult (list, true , next: next ());
166+ return dataResult;
129167 }
168+ return await next ();
130169 }
131170
132171 /**
@@ -160,8 +199,8 @@ class IssueDao {
160199 */
161200 static lockIssueDao (userName, repository, number, locked) async {
162201 String url = Address .lockIssue (userName, repository, number);
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 ),
202+ var res = await HttpManager .netFetch (
203+ url, null , { "Accept" : 'application/vnd.github.VERSION.full+json' }, new Options (method: locked ? "DELETE" : 'PUT' , contentType: ContentType .TEXT ),
165204 noTip: true );
166205 if (res != null && res.result) {
167206 return new DataResult (res.data, true );
0 commit comments