From 8880fe1d37b26eb8e327cec5e74b74d1b73c8d45 Mon Sep 17 00:00:00 2001 From: KIM-JUHYEON-79 Date: Fri, 1 Sep 2023 14:16:07 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=EC=A1=B0=ED=9A=8Capi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/apis/apis.dart | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/apis/apis.dart b/lib/apis/apis.dart index 730358f0..565b4926 100644 --- a/lib/apis/apis.dart +++ b/lib/apis/apis.dart @@ -1506,6 +1506,40 @@ static Future matchingProfessData() async{ /*전체 게시판 게시글 상세 조회*/ +/*공지사항 전체조회*/ + static Future> BoardNotice() async { + final _url = 'http://3.34.2.246:8080/api/v2/notices'; + + try { + // 토큰 읽어오기 + var jwtToken = await storage.read(key: 'token'); + jwtToken = json.decode(jwtToken!)['data']['accessToken']; + + final response = await http.get( + Uri.parse(_url), + headers: { + 'Authorization': 'Bearer $jwtToken', + 'Content-Type': 'application/json', + }, + ); + + if (response.statusCode == 200) { + final responseData = json.decode(utf8.decode(response.bodyBytes)); + final data = responseData['data']; + if (data != null && data is List) { + return data; + } + } + + print('API request failed: ${response.statusCode}'); + return []; + } catch (error) { + print('Error fetching notices: $error'); + return []; + } + } + + /*공지사항 상세조회*/ } From c4f6724154f97c178bc7524cfeaa1d2df1132efd Mon Sep 17 00:00:00 2001 From: KIM-JUHYEON-79 Date: Fri, 1 Sep 2023 15:13:49 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD?= =?UTF-8?q?=EB=AA=A8=EB=8D=B8=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mockdatas/board_mockdata.dart | 15 +++--- lib/models/noticeArticle.dart | 53 +++++++++++++++++++ lib/views/components/notice_board_widget.dart | 11 ++-- lib/views/pages/board/notice_board_page.dart | 2 +- lib/views/pages/board/notice_detail_page.dart | 11 ++-- 5 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 lib/models/noticeArticle.dart diff --git a/lib/mockdatas/board_mockdata.dart b/lib/mockdatas/board_mockdata.dart index 346b2c64..84a17cf4 100644 --- a/lib/mockdatas/board_mockdata.dart +++ b/lib/mockdatas/board_mockdata.dart @@ -1,4 +1,5 @@ import 'package:aliens/models/board_model.dart'; +import 'package:aliens/models/noticeArticle.dart'; List totalBoardList = [ infoBoard1, @@ -62,7 +63,7 @@ List NotificationList=[ Notification2 ]; -List NotiList = [ +List NotiList = [ Notice1, Notice2, Notice3, @@ -378,24 +379,24 @@ Board Notification2= Board( ) ); -Board Notice1= Board( - articleId: 1, +NoticeArticle Notice1= NoticeArticle ( + noticeId: 1, title: '[Friend Ship 이용시 규칙사항]', content: "안녕하세요!! \n Friendship 관리자 ㅇㅇㅇ입니다. ~~~~", createdAt: "2023-01-31 23:53:00", ); -Board Notice2= Board( - articleId: 1, +NoticeArticle Notice2= NoticeArticle ( + noticeId: 1, title: '베타버전 안내&베타테스터 모집 ', content: "베타테스터 하실분~~~ 추첨을 통해 맥북드림", createdAt: "2023-01-31 23:53:00", ); -Board Notice3= Board( - articleId: 1, +NoticeArticle Notice3= NoticeArticle ( + noticeId: 1, title: '3.1ver 업데이트 안내', content: "업데이트 되었으니 업데이트 하시오", createdAt: "2023-01-31 23:53:00", diff --git a/lib/models/noticeArticle.dart b/lib/models/noticeArticle.dart new file mode 100644 index 00000000..22afd0bc --- /dev/null +++ b/lib/models/noticeArticle.dart @@ -0,0 +1,53 @@ +class NoticeArticle { + int? noticeId; + String? title; + String? content; + String? createdAt; + MemberDto? memberDto; + + NoticeArticle({ + this.noticeId, + this.title, + this.content, + this.createdAt, + this.memberDto, + }); + + factory NoticeArticle.fromJson(Map json) { + return NoticeArticle( + noticeId: json['noticeId'], + title: json['title'], + content: json['content'], + createdAt: json['createdAt'], + memberDto: json['memberDto'] != null + ? MemberDto.fromJson(json['memberDto']) + : null, + ); + } +} + +class MemberDto { + int? memberId; + String? email; + String? name; + String? profileImageUrl; + String? nationality; + + MemberDto({ + this.memberId, + this.email, + this.name, + this.profileImageUrl, + this.nationality, + }); + + factory MemberDto.fromJson(Map json) { + return MemberDto( + memberId: json['memberId'], + email: json['email'], + name: json['name'], + profileImageUrl: json['profileImageUrl'], + nationality: json['nationality'], + ); + } +} diff --git a/lib/views/components/notice_board_widget.dart b/lib/views/components/notice_board_widget.dart index a94bd1da..9b38e0ee 100644 --- a/lib/views/components/notice_board_widget.dart +++ b/lib/views/components/notice_board_widget.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:aliens/models/message_model.dart'; +import 'package:aliens/models/noticeArticle.dart'; import 'package:aliens/views/pages/board/article_writing_page.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; @@ -18,9 +19,9 @@ import 'board_dialog_widget.dart'; class NoticeWidget extends StatefulWidget { - NoticeWidget({super.key, required this.board, required this.screenArguments}); + NoticeWidget({super.key, required this.noticeArticle, required this.screenArguments}); final ScreenArguments screenArguments; - final Board board; + final NoticeArticle noticeArticle; @override State createState() => _NoticeWidgetState(); } @@ -39,7 +40,7 @@ class _NoticeWidgetState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => NoticeDetailPage(board: widget.board, screenArguments: widget.screenArguments)), + builder: (context) => NoticeDetailPage(noticeArticle: widget.noticeArticle, screenArguments: widget.screenArguments)), ); }, child: ListTile( @@ -49,7 +50,7 @@ class _NoticeWidgetState extends State { Padding( padding:EdgeInsets.only(), child: Text( - '${widget.board.title}', + '${widget.noticeArticle.title}', style: TextStyle( fontSize: 18.spMin, color: Colors.black, @@ -58,7 +59,7 @@ class _NoticeWidgetState extends State { ), Flexible( child: Text( - DataUtils.getTime(widget.board.createdAt), + DataUtils.getTime(widget.noticeArticle.createdAt), style: TextStyle( fontSize: 14.spMin, color: Color(0xff888888), diff --git a/lib/views/pages/board/notice_board_page.dart b/lib/views/pages/board/notice_board_page.dart index 0e7e67aa..88ae06df 100644 --- a/lib/views/pages/board/notice_board_page.dart +++ b/lib/views/pages/board/notice_board_page.dart @@ -139,7 +139,7 @@ class _NoticeBoardPageState extends State { thickness: 1.h, color: Color(0xffCECECE), ), - NoticeWidget(board: NotiList[index], screenArguments: widget.screenArguments), + NoticeWidget(noticeArticle: NotiList[index], screenArguments: widget.screenArguments), ], ); diff --git a/lib/views/pages/board/notice_detail_page.dart b/lib/views/pages/board/notice_detail_page.dart index fd0bd137..8b622f8d 100644 --- a/lib/views/pages/board/notice_detail_page.dart +++ b/lib/views/pages/board/notice_detail_page.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:aliens/mockdatas/board_mockdata.dart'; import 'package:aliens/models/board_model.dart'; import 'package:aliens/models/chatRoom_model.dart'; +import 'package:aliens/models/noticeArticle.dart'; import 'package:aliens/models/screenArgument.dart'; import 'package:aliens/repository/sql_message_database.dart'; import 'package:aliens/views/pages/chatting/chatting_page.dart'; @@ -27,9 +28,9 @@ import 'notification_page.dart'; class NoticeDetailPage extends StatefulWidget { - NoticeDetailPage({Key? key, required this.screenArguments, required this.board}) : super(key: key); + NoticeDetailPage({Key? key, required this.screenArguments, required this.noticeArticle}) : super(key: key); final ScreenArguments screenArguments; - final Board board; + final NoticeArticle noticeArticle; @override @@ -127,7 +128,7 @@ class _NoticeDetailPageState extends State { Padding( padding:EdgeInsets.only(), child: Text( - '${widget.board.title}', + '${widget.noticeArticle.title}', style: TextStyle( fontSize: 18.spMin, fontWeight: FontWeight.bold, @@ -138,7 +139,7 @@ class _NoticeDetailPageState extends State { Flexible( child: Text( - DataUtils.getTime(widget.board.createdAt), + DataUtils.getTime(widget.noticeArticle.createdAt), style: TextStyle( fontSize: 14.spMin, color: Color(0xff888888), @@ -155,7 +156,7 @@ class _NoticeDetailPageState extends State { Padding( padding: EdgeInsets.symmetric(horizontal: 21.w, vertical: 10.spMin), child: Text( - '${widget.board.content}', // 'content' from the Board object + '${widget.noticeArticle.content}', // 'content' from the Board object style: TextStyle( fontSize: 18.spMin, color: Colors.black, From 1c3ba50fb173a87e17f5bb1e653f2f97de4e8dcd Mon Sep 17 00:00:00 2001 From: KIM-JUHYEON-79 Date: Fri, 1 Sep 2023 22:42:40 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=ADapi=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/apis/apis.dart | 1 - lib/views/components/board_drawer_widget.dart | 4 ++- lib/views/components/notice_board_widget.dart | 21 ++++++++++++++ lib/views/pages/board/notice_board_page.dart | 29 +++++++++++++++++-- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/lib/apis/apis.dart b/lib/apis/apis.dart index 565b4926..2cecdd90 100644 --- a/lib/apis/apis.dart +++ b/lib/apis/apis.dart @@ -1539,7 +1539,6 @@ static Future matchingProfessData() async{ } } - /*공지사항 상세조회*/ } diff --git a/lib/views/components/board_drawer_widget.dart b/lib/views/components/board_drawer_widget.dart index 5ff223d1..c6ced437 100644 --- a/lib/views/components/board_drawer_widget.dart +++ b/lib/views/components/board_drawer_widget.dart @@ -52,13 +52,15 @@ class _BoardDrawerWidgetState extends State { child: ListView( children: [ InkWell( - onTap: (){ + onTap: () async { if(widget.isTotalBoard){ Navigator.push( context, MaterialPageRoute( builder: (context) => NoticeBoardPage(screenArguments: widget.screenArguments)), + ); + } else{ Navigator.pop(context); diff --git a/lib/views/components/notice_board_widget.dart b/lib/views/components/notice_board_widget.dart index 9b38e0ee..0e7c6ff0 100644 --- a/lib/views/components/notice_board_widget.dart +++ b/lib/views/components/notice_board_widget.dart @@ -10,6 +10,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/svg.dart'; +import '../../apis/apis.dart'; import '../../models/board_model.dart'; import '../../models/screenArgument.dart'; import '../pages/board/article_page.dart'; @@ -22,15 +23,35 @@ class NoticeWidget extends StatefulWidget { NoticeWidget({super.key, required this.noticeArticle, required this.screenArguments}); final ScreenArguments screenArguments; final NoticeArticle noticeArticle; + @override State createState() => _NoticeWidgetState(); } class _NoticeWidgetState extends State { String createdAt = ''; + List noticearticles = []; @override void initState() { super.initState(); + fetchNoticeData(); + } + + + Future fetchNoticeData() async { + try { + final response = await APIs.BoardNotice(); + final dataList = response as List; // 변환된 리스트 데이터 + + setState(() { + print('1'); + noticearticles = dataList.map((article) => + NoticeArticle.fromJson(article)).toList(); + print('2'); + }); + } catch (error) { + print('Error fetching article data: $error'); + } } @override diff --git a/lib/views/pages/board/notice_board_page.dart b/lib/views/pages/board/notice_board_page.dart index 88ae06df..3fc08687 100644 --- a/lib/views/pages/board/notice_board_page.dart +++ b/lib/views/pages/board/notice_board_page.dart @@ -10,7 +10,9 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/svg.dart'; - +import 'package:aliens/apis/apis.dart'; +import 'package:aliens/models/noticeArticle.dart'; +import '../../../apis/apis.dart'; import '../../../mockdatas/market_comment_mockdata.dart'; import '../../../models/countries.dart'; import '../../components/article_widget.dart'; @@ -35,6 +37,26 @@ class NoticeBoardPage extends StatefulWidget { class _NoticeBoardPageState extends State { bool isDrawerStart = false; + List noticearticles = []; //공지사항 저장 + + void initState() { + super.initState(); + fetchNoticeData(); + } + + Future fetchNoticeData() async { + try { + final response = await APIs.BoardNotice(); + final dataList = response as List; + + setState(() { + // API 데이터를 공지사항 목록으로 변환하여 업데이트 + noticearticles = dataList.map((article) => NoticeArticle.fromJson(article)).toList(); + }); + } catch (error) { + print('Error fetching notice data: $error'); + } + } @override Widget build(BuildContext context) { @@ -131,15 +153,16 @@ class _NoticeBoardPageState extends State { child: Container( decoration: BoxDecoration(color: Colors.white), child: ListView.builder( - itemCount: NotiList.length, + itemCount: noticearticles.length, itemBuilder: (context, index) { + final noticeArticle = noticearticles[index]; return Column( children: [ Divider( thickness: 1.h, color: Color(0xffCECECE), ), - NoticeWidget(noticeArticle: NotiList[index], screenArguments: widget.screenArguments), + NoticeWidget(noticeArticle: noticeArticle, screenArguments: widget.screenArguments), ], ); From dd65171d36e0e2fa118f4c6ad245479a9604e784 Mon Sep 17 00:00:00 2001 From: KIM-JUHYEON-79 Date: Fri, 1 Sep 2023 23:08:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EC=A3=BC=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/views/components/info_article_widget.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/views/components/info_article_widget.dart b/lib/views/components/info_article_widget.dart index 382f46b1..ab6603a3 100644 --- a/lib/views/components/info_article_widget.dart +++ b/lib/views/components/info_article_widget.dart @@ -13,7 +13,7 @@ import 'package:flutter_svg/svg.dart'; import '../../models/board_model.dart'; import '../pages/board/article_page.dart'; import 'board_dialog_widget.dart'; -class InfoArticleWidget extends StatefulWidget { +/*class InfoArticleWidget extends StatefulWidget { InfoArticleWidget({super.key, required this.board, required this.nationCode, required this.isTotal}); @@ -136,5 +136,5 @@ class _InfoArticleWidgetState extends State{ ), ); } -} +}*/