Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

リクエスト回数を増やす、マイページ投稿ページネーション #43

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions qiita_app/lib/repository/qiita_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ class QiitaRepository {
// 検索クエリが空の場合、クエリパラメータを含まないURLを構築
url = Uri.parse('${Urls.qiitaBaseUrl}/items?page=$page');
}
final accessToken = await _getAccessToken();

try {
final response = await http.get(url);
final response = await http.get(url,
headers: accessToken.isNotEmpty
? {'Authorization': 'Bearer $accessToken'}
: null);
Comment on lines +49 to +51
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

三項演算子上手に使えていて素晴らしいです!!🙌


if (response.statusCode == 200) {
final List<dynamic> jsonResponse = jsonDecode(response.body);
Expand Down Expand Up @@ -88,7 +92,11 @@ class QiitaRepository {
static Future<List<Tag>> fetchQiitaTags() async {
final url =
Uri.parse('${Urls.qiitaBaseUrl}/tags?page=1&per_page=20&sort=count');
final response = await http.get(url);
final accessToken = await _getAccessToken();
final response = await http.get(url,
headers: accessToken.isNotEmpty
? {'Authorization': 'Bearer $accessToken'}
: null);

if (response.statusCode == 200) {
final List<dynamic> jsonResponse = jsonDecode(response.body);
Expand All @@ -106,8 +114,12 @@ class QiitaRepository {
String tagId, int page) async {
final url = Uri.parse(
'${Urls.qiitaBaseUrl}/tags/$tagId/items?page=$page&per_page=20');
final accessToken = await _getAccessToken();
try {
final response = await http.get(url);
final response = await http.get(url,
headers: accessToken.isNotEmpty
? {'Authorization': 'Bearer $accessToken'}
: null);

if (response.statusCode == 200) {
final List<dynamic> jsonResponse = jsonDecode(response.body);
Expand Down
Loading