Skip to content

Commit

Permalink
#132 feat: 채팅방 리스트 조회 api 연결 중간저장
Browse files Browse the repository at this point in the history
  • Loading branch information
Nya128 committed Jan 4, 2024
1 parent b6a7865 commit de45e1f
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 11 deletions.
14 changes: 8 additions & 6 deletions lib/chat/view/chat_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,7 +31,7 @@ class _ChatScreenState extends State<ChatScreen> {
];

Future<dynamic> fetchData() async {
return await ChatService().getChatList();
return await ChatService().getChatRoomList();
}

@override
Expand All @@ -46,15 +45,18 @@ class _ChatScreenState extends State<ChatScreen> {
child: FutureBuilder(
future: fetchData(),
builder: (context, snapshot) {
if (snapshot.hasError) {
if (snapshot.hasData) {
/// 정상
// data = List<ChatModel>.fromJson(snapshot.data);
} else if (snapshot.hasError) {
/// 에러 - 데이터를 불러올 수 없다고 띄우기
print("chat: ${snapshot.error.toString()}");
// return const CircularProgress();
} else if (snapshot.hasData) {
// data = List<ChatModel>.fromJson(snapshot.data);
} else if (!snapshot.hasData) {
/* 채팅 emptyView 필요 */
/// empty view
// return const CircularProgress();
} else {
/// 필요할까?
// return const CircularProgress();
}
return renderBody();
Expand Down
Empty file.
43 changes: 43 additions & 0 deletions lib/model/data/chat/chat_room_list_model.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> json) => _$ChatRoomListModelFromJson(json);
}

@JsonSerializable()
class ChatRoomList {
final List<ChatRoom> noticeLists;

ChatRoomList({required this.noticeLists});
factory ChatRoomList.fromJson(Map<String, dynamic> 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<String, dynamic> json) => _$ChatRoomFromJson(json);
}
54 changes: 54 additions & 0 deletions lib/model/data/chat/chat_room_list_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions lib/presenter/chat/chat_service.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import '../../model/network/api_manager.dart';

class ChatService {
final CHAT_ROOM_LIST = '/chat/rooms';

Future<dynamic> 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<dynamic> getChatRoomList() async {
final response = APIManager().request(RequestType.GET, CHAT_ROOM_LIST, null, null, null);
print('response: $response');
return response;
}

getChat() {}
Expand Down

0 comments on commit de45e1f

Please sign in to comment.