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

Feat/#123 market api #134

Merged
merged 6 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@

"general-board-post" : "General Board New Post",
"market-board-post": "Market Board New Post",
"Brand_New": "Brand New",
"Almost_New": "Almost New",
"Slight_Defect": "Slight Defect",
"Used": "Used",
"sale": "For sale"
"Brand_New": "BRAND_NEW",
"Almost_New": "ALMOST_NEW",
"Slight_Defect": "SLIGHT_DEFECT",
"Used": "USED",
"sale": "SELL"

}
130 changes: 63 additions & 67 deletions lib/apis/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,6 @@ class APIs {
}
}


/*μž₯ν„° κ²Œμ‹œνŒ κ²Œμ‹œκΈ€ 상세 쑰회*/
static Future<MarketBoard> getMarketArticle(int articleId) async {
final _url = 'http://3.34.2.246:8080/api/v2/market-articles/${articleId}';
Expand Down Expand Up @@ -1807,48 +1806,44 @@ class APIs {


/* νŠΉμ • νŒλ§€κΈ€ 찜 등둝*/
static Future<String> addMarketArticleBookmark(int articleId) async {
try {
var jwtToken = await storage.read(key: 'token');
final accessToken = json.decode(jwtToken!)['data']['accessToken'];
static Future<int> marketbookmark(int articleId) async {
var url = 'http://3.34.2.246:8080/api/v2/community-articles/${articleId}/bookmarks';

final url = Uri.parse(
'http://3.34.2.246:8080/api/v2/market-articles/$articleId/bookmarks');
//토큰 μ½μ–΄μ˜€κΈ°
var jwtToken = await storage.read(key: 'token');

final response = await http.post(
url,
headers: {
'Authorization': 'Bearer $accessToken',
'Content-Type': 'application/json',
},
);
//accessToken만 보내기
jwtToken = json.decode(jwtToken!)['data']['accessToken'];

if (response.statusCode == 200) {
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final message = responseBody['message'];
return message;
} else {
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final errorCode = responseBody['code'];
var response = await http.post(Uri.parse(url),
headers: {
'Authorization': 'Bearer $jwtToken',
'Content-Type': 'application/json'},
);

//success
if (response.statusCode == 200) {
print(json.decode(utf8.decode(response.bodyBytes)));
return json.decode(utf8.decode(response.bodyBytes))['data']['likeCount'];
//fail
} else {
print(json.decode(utf8.decode(response.bodyBytes)));
if(json.decode(utf8.decode(response.bodyBytes))['code'] == 'AT-C-002'){
print('μ•‘μ„ΈμŠ€ 토큰 만료');
throw 'AT-C-002';
} else if(json.decode(utf8.decode(response.bodyBytes))['code'] == 'AT-C-007'){
print('λ‘œκ·Έμ•„μ›ƒλœ 토큰');
throw 'AT-C-007';
}else{

if (errorCode == 'AT-C-002') {
throw 'μ•‘μ„ΈμŠ€ 토큰 만료';
} else if (errorCode == 'AT-C-007') {
throw 'λ‘œκ·Έμ•„μ›ƒλœ 토큰';
} else {
throw Exception('뢁마크 등둝 였λ₯˜');
}
}
} catch (error) {
print('Error adding market article bookmark: $error');
throw Exception('뢁마크 등둝 였λ₯˜');
return -1;
}
}


/*μƒν’ˆ νŒλ§€κΈ€ λŒ“κΈ€ 전체 쑰회*/
static Future<List<MarketComment>> getMarketArticleComments(
int marketArticleId) async {
static Future<List<MarketComment>> getMarketArticleComments(int marketArticleId) async {
try {
var jwtToken = await storage.read(key: 'token');
final accessToken = json.decode(jwtToken!)['data']['accessToken'];
Expand All @@ -1871,6 +1866,8 @@ class APIs {
return body.map((dynamic item) => MarketComment.fromJson(item))
.toList();
} else {
print(json.decode(utf8.decode(response.bodyBytes)));

final responseBody = json.decode(utf8.decode(response.bodyBytes));
final errorCode = responseBody['code'];

Expand All @@ -1890,42 +1887,41 @@ class APIs {


/*μƒν’ˆ νŒλ§€κΈ€ λΆ€λͺ¨ λŒ“κΈ€ 등둝*/
static Future<bool> createMarketArticleComment(int articleCommentId,
String content) async {
try {
var jwtToken = await storage.read(key: 'token');
final accessToken = json.decode(jwtToken!)['data']['accessToken'];
static Future<bool> createMarketArticleComment(String content, int articleId) async {
var url = 'http://3.34.2.246:8080/api/v2/market-articles/$articleId/market-article-comments';

final url = Uri.parse(
'http://3.34.2.246:8080/api/v2/market-articles/$articleCommentId/market-article-comments');
//토큰 μ½μ–΄μ˜€κΈ°
var jwtToken = await storage.read(key: 'token');

final response = await http.post(
url,
//accessToken만 보내기
jwtToken = json.decode(jwtToken!)['data']['accessToken'];

var response = await http.post(Uri.parse(url),
headers: {
'Authorization': 'Bearer $accessToken',
'Content-Type': 'application/json',
},
body: json.encode({'content': content}),
);
'Authorization': 'Bearer $jwtToken',
'Content-Type': 'application/json'},
body: jsonEncode({
"content": content,
}));

if (response.statusCode == 201) {
print(json.decode(utf8.decode(response.bodyBytes)));
return true;
//success
if (response.statusCode == 200) {
print(json.decode(utf8.decode(response.bodyBytes)));
return true;
//fail
} else {
print(json.decode(utf8.decode(response.bodyBytes)));
if (json.decode(utf8.decode(response.bodyBytes))['code'] == 'AT-C-002') {
print('μ•‘μ„ΈμŠ€ 토큰 만료');
throw 'AT-C-002';
} else
if (json.decode(utf8.decode(response.bodyBytes))['code'] == 'AT-C-007') {
print('λ‘œκ·Έμ•„μ›ƒλœ 토큰');
throw 'AT-C-007';
} else {
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final errorCode = responseBody['code'];

if (errorCode == 'AT-C-002') {
throw 'μ•‘μ„ΈμŠ€ 토큰 만료';
} else if (errorCode == 'AT-C-007') {
throw 'λ‘œκ·Έμ•„μ›ƒλœ 토큰';
} else {
throw Exception('λŒ“κΈ€ 생성 였λ₯˜');
}
}
} catch (error) {
print('Error creating market article comment: $error');
throw Exception('λŒ“κΈ€ 생성 였λ₯˜');
return false;
}
}

Expand All @@ -1950,7 +1946,7 @@ class APIs {
if (response.statusCode == 200) {
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final message = responseBody['message'];
return message;
return true;
} else {
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final errorCode = responseBody['code'];
Expand All @@ -1971,14 +1967,13 @@ class APIs {


/*νŠΉμ • μƒν’ˆ νŒλ§€κΈ€ λŒ“κΈ€μ— λŒ€λŒ“κΈ€ 등둝*/
static Future<bool> addMarketArticleCommentReply(int articleCommentId,
int ArticleCommentId, String content) async {
static Future<bool> addMarketArticleCommentReply(String content, int commentId, int articleId) async {
try {
var jwtToken = await storage.read(key: 'token');
final accessToken = json.decode(jwtToken!)['data']['accessToken'];

final url = Uri.parse(
'http://3.34.2.246:8080/api/v2/market-articles/$articleCommentId/market-article-comments/$ArticleCommentId');
'http://3.34.2.246:8080/api/v2/market-articles/$articleId/market-article-comments/$commentId');

final response = await http.post(
url,
Expand All @@ -1990,9 +1985,10 @@ class APIs {
);

if (response.statusCode == 200) {
print(json.decode(utf8.decode(response.bodyBytes)));
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final message = responseBody['message'];
return message;
return true;
} else {
final responseBody = json.decode(utf8.decode(response.bodyBytes));
final errorCode = responseBody['code'];
Expand Down
8 changes: 4 additions & 4 deletions lib/models/market_articles.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MarketBoard {
int? articleId;
String? title;
String? status;
String? marketArticleStatus;
int? price;
String? productStatus;
String? content;
Expand All @@ -14,7 +14,7 @@ class MarketBoard {
MarketBoard({
this.articleId,
this.title,
this.status,
this.marketArticleStatus,
this.price,
this.productStatus,
this.content,
Expand All @@ -28,7 +28,7 @@ class MarketBoard {
MarketBoard.fromJson(Map<String, dynamic> json) {
articleId = json['articleId'];
title = json['title'];
status = json['status'];
marketArticleStatus = json['marketArticleStatus'];
price = json['price'];
productStatus = json['productStatus'];
content = json['content'];
Expand All @@ -43,7 +43,7 @@ class MarketBoard {
final Map<String, dynamic> data = <String, dynamic>{};
data['articleId'] = articleId;
data['title'] = title;
data['status'] = status;
data['marketArticleStatus'] = marketArticleStatus;
data['price'] = price;
data['productStatus'] = productStatus;
data['content'] = content;
Expand Down
25 changes: 15 additions & 10 deletions lib/providers/market_comment_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ class MarketCommentProvider with ChangeNotifier {
bool loading = false;
MarketComment? marketcomment;

getMarketComments(int articleCommentId) async {
getMarketComments(int articleId) async {
loading = true;
try {
commentListData = await APIs.getMarketArticleComments(articleCommentId);
commentListData = await APIs.getMarketArticleComments(articleId);
} catch (e) {
if (e == "AT-C-002") {
await APIs.getAccessToken();
commentListData = await APIs.getMarketArticleComments(articleCommentId);
commentListData = await APIs.getMarketArticleComments(articleId);
} else {
// 였λ₯˜ 처리 둜직
}
}
loading = false;
notifyListeners();

}


addMarketComment(int articleId, String content) async {
addMarketComment(String content, int articleId) async {
try {
await APIs.createMarketArticleComment(articleId, content);
await APIs.createMarketArticleComment(content,articleId);
} catch (e) {
if (e == "AT-C-002") {
await APIs.getAccessToken();
await APIs.createMarketArticleComment(articleId, content);
await APIs.createMarketArticleComment(content,articleId);
} else {
return false;
}
Expand All @@ -46,24 +47,26 @@ class MarketCommentProvider with ChangeNotifier {


notifyListeners();
getMarketComments(articleId);
return true;
}

addNestedMarketComment(int commentId, int ArticleCommentId, String content) async {
addNestedMarketComment(String content, int commentId, int articleId) async {
try {
await APIs.addMarketArticleCommentReply(commentId, ArticleCommentId, content);
await APIs.addMarketArticleCommentReply(content, commentId,articleId );
} catch (e) {
if (e == "AT-C-002") {
await APIs.getAccessToken();
await APIs.addMarketArticleCommentReply(commentId, ArticleCommentId, content);
await APIs.addMarketArticleCommentReply(content, commentId,articleId);
} else {
return false;
}
}
//TODO fcm 전솑


notifyListeners();
getMarketComments(articleId);

return true;
}
deleteMarketComment(int articleId) async {
Expand All @@ -80,6 +83,8 @@ class MarketCommentProvider with ChangeNotifier {
}
loading = false;
notifyListeners();
getMarketComments(articleId);

return value;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/views/components/board_drawer_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:aliens/models/chatRoom_model.dart';
import 'package:aliens/models/memberDetails_model.dart';
import 'package:aliens/models/screenArgument.dart';
import 'package:aliens/repository/sql_message_database.dart';
import 'package:aliens/views/pages/board/article_writing_page.dart';
Expand Down Expand Up @@ -33,6 +34,7 @@ class BoardDrawerWidget extends StatefulWidget {

final ScreenArguments screenArguments;
final MarketBoard? marketBoard;
//final MemberDetails memberDetails;

final bool isTotalBoard;
final VoidCallback onpressd;
Expand Down Expand Up @@ -449,7 +451,7 @@ class _BoardDrawerWidgetState extends State<BoardDrawerWidget> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MarketBoardPage(screenArguments: widget.screenArguments, marketBoard: widget.marketBoard,)),
builder: (context) => MarketBoardPage(screenArguments: widget.screenArguments, marketBoard: widget.marketBoard)),

);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/views/components/marketcomment_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MarketCommentDialog extends StatelessWidget{
InkWell(
onTap: (){
//TODO λ‘œλ”© λ§Œλ“€κΈ°
// marketcommentProvider.deleteComment(marketcomment.articleCommentId!);
marketcommentProvider.deleteMarketComment(marketcomment.articleCommentId!);
},
child: Container(
padding: EdgeInsets.all(13).r,
Expand Down Expand Up @@ -155,7 +155,7 @@ class MarketCommentDialog extends StatelessWidget{
InkWell(
onTap: () {
//TODO λ‘œλ”© λ§Œλ“€κΈ°
// marketcommentProvider.deleteComment(marketcomment.articleCommentId!);
marketcommentProvider.deleteMarketComment(marketcomment.articleCommentId!);
},
child: Container(
height: 80,
Expand Down
Loading