Skip to content

Commit

Permalink
Merge pull request #153 from 4Ailen/feat/#139_search
Browse files Browse the repository at this point in the history
Fix/#123_marketAPI
  • Loading branch information
KIM-JUHYEON-79 authored Sep 11, 2023
2 parents 288c63f + 3a2178a commit 5efeb88
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 255 deletions.
6 changes: 3 additions & 3 deletions lib/apis/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ class APIs {
}

/*상품판매글 모두 조회*/
static Future<List<MarketBoard>> getMarketArticles(int page) async {
static Future<List<MarketBoard>> getMarketArticles(page) async {
var _url = 'http://3.34.2.246:8080/api/v2/market-articles?page=${page}&size=10&sort=createdAt,desc';

// 토큰 읽어오기
Expand Down Expand Up @@ -1799,8 +1799,8 @@ class APIs {


/* 특정 판매글 찜 등록*/
static Future<int> marketbookmark(int articleId) async {
var url = 'http://3.34.2.246:8080/api/v2/market-articles/${articleId}/bookmarks';
static Future<int> marketbookmark(int articleId, int index) async {
var url = 'http://3.34.2.246:8080/api/v2/market-articles/${articleId}/bookmarks?page=$index&size=10&sort=createdAt,desc';

// 토큰 읽어오기
var jwtToken = await storage.read(key: 'token');
Expand Down
16 changes: 16 additions & 0 deletions lib/models/market_articles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ class MarketBoard {
Member? member;
String? createdAt;

@override
String toString() {
return 'MarketBoard{'
'articleId: $articleId, '
'title: $title, '
'marketArticleStatus: $marketArticleStatus, '
'price: $price, '
'productStatus: $productStatus, '
'content: $content, '
'marketArticleBookmarkCount: $marketArticleBookmarkCount, '
'commentsCount: $commentsCount, '
'imageUrls: $imageUrls, '
'member: $member, '
'createdAt: $createdAt'
'}';
}
MarketBoard({
this.articleId,
this.title,
Expand Down
23 changes: 15 additions & 8 deletions lib/providers/bookmarks_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,36 @@ class BookmarksProvider with ChangeNotifier {
try {
//좋아요 요청
print('이건되나');
marketArticleBookmarkCount![index] = await APIs.marketbookmark(articleId);
marketArticleBookmarkCount![index] = await APIs.marketbookmark(articleId, index);
print('이건???');

} catch (e) {
if (e == "AT-C-002") {
await APIs.getAccessToken();
//좋아요 요청
marketArticleBookmarkCount![index] = await APIs.marketbookmark(articleId);
marketArticleBookmarkCount![index] = await APIs.marketbookmark(articleId, index);

} else {
}
}
loading = false;
notifyListeners();
getbookmarksCounts();
print('이것도 될라나;;');
getbookmarksCounts(0);
}

getbookmarksCounts() async {
articleList = await APIs.getMarketArticles(0);
getbookmarksCounts(int page) async {
//final index = 0; // 원하는 페이지 번호 또는 index를 설정
articleList = await APIs.getMarketArticles(page);
marketArticleBookmarkCount = articleList!.map((marketboard) => marketboard.marketArticleBookmarkCount ?? 0).toList();
//print(marketboard.marketArticleBookmarkCount ?? 0);
// print('북마크개수:${marketArticleBookmarkCount}');
print('북마크 개수: ${marketArticleBookmarkCount?.length}');
}

getMoreBookmarksCounts(int page) async {
//받아와서 교체하는 것이 아닌 추가를 해야하므로 addAll 사용
articleList!.addAll(await APIs.getMarketArticles(page));
marketArticleBookmarkCount = articleList!.map((marketboard) => marketboard.marketArticleBookmarkCount ?? 0).toList();
print('북마크 개수: ${marketArticleBookmarkCount?.length}');
}


}
2 changes: 1 addition & 1 deletion lib/views/components/total_article_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class _TotalArticleWidgetState extends State<TotalArticleWidget>{
if(widget.board.category != "장터게시판"){
boardProvider.addLike(widget.board.articleId!, widget.index);
}else{
boardProvider.likeCounts[widget.index] = await APIs.marketbookmark(widget.board.articleId!);
boardProvider.likeCounts[widget.index] = await APIs.marketbookmark(widget.board.articleId!, widget.index);
}
setState(() {});
},
Expand Down
Loading

0 comments on commit 5efeb88

Please sign in to comment.