From de45e1fde92f8b02261692255e9950afc8493842 Mon Sep 17 00:00:00 2001 From: Nya128 Date: Fri, 5 Jan 2024 04:29:20 +0900 Subject: [PATCH] =?UTF-8?q?#132=20feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=20=EC=A4=91=EA=B0=84=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/chat/view/chat_screen.dart | 14 ++--- lib/model/data/chat/chat_message_model.dart | 0 lib/model/data/chat/chat_room_list_model.dart | 43 +++++++++++++++ .../data/chat/chat_room_list_model.g.dart | 54 +++++++++++++++++++ lib/presenter/chat/chat_service.dart | 15 ++++-- 5 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 lib/model/data/chat/chat_message_model.dart create mode 100644 lib/model/data/chat/chat_room_list_model.dart create mode 100644 lib/model/data/chat/chat_room_list_model.g.dart diff --git a/lib/chat/view/chat_screen.dart b/lib/chat/view/chat_screen.dart index 7f5e0ed..aacef96 100644 --- a/lib/chat/view/chat_screen.dart +++ b/lib/chat/view/chat_screen.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:psr/common/const/colors.dart'; import '../../presenter/chat/chat_service.dart'; import '../component/chat_list_item.dart'; @@ -32,7 +31,7 @@ class _ChatScreenState extends State { ]; Future fetchData() async { - return await ChatService().getChatList(); + return await ChatService().getChatRoomList(); } @override @@ -46,15 +45,18 @@ class _ChatScreenState extends State { child: FutureBuilder( future: fetchData(), builder: (context, snapshot) { - if (snapshot.hasError) { + if (snapshot.hasData) { + /// 정상 + // data = List.fromJson(snapshot.data); + } else if (snapshot.hasError) { + /// 에러 - 데이터를 불러올 수 없다고 띄우기 print("chat: ${snapshot.error.toString()}"); // return const CircularProgress(); - } else if (snapshot.hasData) { - // data = List.fromJson(snapshot.data); } else if (!snapshot.hasData) { - /* 채팅 emptyView 필요 */ + /// empty view // return const CircularProgress(); } else { + /// 필요할까? // return const CircularProgress(); } return renderBody(); diff --git a/lib/model/data/chat/chat_message_model.dart b/lib/model/data/chat/chat_message_model.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/model/data/chat/chat_room_list_model.dart b/lib/model/data/chat/chat_room_list_model.dart new file mode 100644 index 0000000..c948461 --- /dev/null +++ b/lib/model/data/chat/chat_room_list_model.dart @@ -0,0 +1,43 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:psr/model/data/general_model.dart'; + +part 'chat_room_list_model.g.dart'; + +@JsonSerializable() +class ChatRoomListModel extends GeneralModel { + final ChatRoomList? data; + + ChatRoomListModel({required super.code, required super.message, required this.data}); + factory ChatRoomListModel.fromJson(Map json) => _$ChatRoomListModelFromJson(json); +} + +@JsonSerializable() +class ChatRoomList { + final List noticeLists; + + ChatRoomList({required this.noticeLists}); + factory ChatRoomList.fromJson(Map json) => _$ChatRoomListFromJson(json); +} + +@JsonSerializable() +class ChatRoom { + final int chatRoomId; + final String profileImgUrl; + final String nickname; + final String message; + final String date; + final bool isRead; + final int numOfUnread; + + ChatRoom({ + required this.chatRoomId, + required this.profileImgUrl, + required this.nickname, + required this.message, + required this.date, + required this.isRead, + required this.numOfUnread, + }); + + factory ChatRoom.fromJson(Map json) => _$ChatRoomFromJson(json); +} diff --git a/lib/model/data/chat/chat_room_list_model.g.dart b/lib/model/data/chat/chat_room_list_model.g.dart new file mode 100644 index 0000000..92756f4 --- /dev/null +++ b/lib/model/data/chat/chat_room_list_model.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'chat_room_list_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ChatRoomListModel _$ChatRoomListModelFromJson(Map json) => + ChatRoomListModel( + code: json['code'] as int, + message: json['message'] as String, + data: json['data'] == null + ? null + : ChatRoomList.fromJson(json['data'] as Map), + ); + +Map _$ChatRoomListModelToJson(ChatRoomListModel instance) => + { + 'code': instance.code, + 'message': instance.message, + 'data': instance.data, + }; + +ChatRoomList _$ChatRoomListFromJson(Map json) => ChatRoomList( + noticeLists: (json['noticeLists'] as List) + .map((e) => ChatRoom.fromJson(e as Map)) + .toList(), + ); + +Map _$ChatRoomListToJson(ChatRoomList instance) => + { + 'noticeLists': instance.noticeLists, + }; + +ChatRoom _$ChatRoomFromJson(Map json) => ChatRoom( + chatRoomId: json['chatRoomId'] as int, + profileImgUrl: json['profileImgUrl'] as String, + nickname: json['nickname'] as String, + message: json['message'] as String, + date: json['date'] as String, + isRead: json['isRead'] as bool, + numOfUnread: json['numOfUnread'] as int, + ); + +Map _$ChatRoomToJson(ChatRoom instance) => { + 'chatRoomId': instance.chatRoomId, + 'profileImgUrl': instance.profileImgUrl, + 'nickname': instance.nickname, + 'message': instance.message, + 'date': instance.date, + 'isRead': instance.isRead, + 'numOfUnread': instance.numOfUnread, + }; diff --git a/lib/presenter/chat/chat_service.dart b/lib/presenter/chat/chat_service.dart index 3d0bdb8..8422568 100644 --- a/lib/presenter/chat/chat_service.dart +++ b/lib/presenter/chat/chat_service.dart @@ -1,11 +1,16 @@ +import '../../model/network/api_manager.dart'; class ChatService { + final CHAT_ROOM_LIST = '/chat/rooms'; - Future getChatList() async { - // final response = - // APIManager().request(RequestType.GET, MY_INFO, null, null, null); - // print('response: $response'); - // return response; + static final ChatService _chatService = ChatService._(); + ChatService._(); + factory ChatService() => _chatService; + + Future getChatRoomList() async { + final response = APIManager().request(RequestType.GET, CHAT_ROOM_LIST, null, null, null); + print('response: $response'); + return response; } getChat() {}