diff --git a/iOS/RollTheDice/.DS_Store b/iOS/RollTheDice/.DS_Store index c839e815..01b0d693 100644 Binary files a/iOS/RollTheDice/.DS_Store and b/iOS/RollTheDice/.DS_Store differ diff --git a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj index 21b33357..d7ffd3e1 100644 --- a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj +++ b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj @@ -13,6 +13,11 @@ 3544D7462C229436007DBD18 /* ChatService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3544D7452C229436007DBD18 /* ChatService.swift */; }; 35710D732C23D9030041ECD2 /* EndDebateViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D722C23D9030041ECD2 /* EndDebateViewModel.swift */; }; 35710D752C23D9350041ECD2 /* EndDebateService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D742C23D9350041ECD2 /* EndDebateService.swift */; }; + 35710D772C23DBEA0041ECD2 /* DebateSummaryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D762C23DBEA0041ECD2 /* DebateSummaryViewModel.swift */; }; + 35710D7B2C23DC360041ECD2 /* DebateSummaryService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D7A2C23DC360041ECD2 /* DebateSummaryService.swift */; }; + 35710D7D2C23DC6A0041ECD2 /* GetDebateRoomViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D7C2C23DC6A0041ECD2 /* GetDebateRoomViewModel.swift */; }; + 35710D7F2C23DC830041ECD2 /* GetDebateRoomService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D7E2C23DC830041ECD2 /* GetDebateRoomService.swift */; }; + 35710D822C23DCA40041ECD2 /* GetDebateRoom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35710D812C23DCA40041ECD2 /* GetDebateRoom.swift */; }; 357666102BBD4BF6002C226A /* ReportListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3576660F2BBD4BF6002C226A /* ReportListView.swift */; }; 357666132BBD54AA002C226A /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357666122BBD54AA002C226A /* SplashView.swift */; }; 3576993A2C09C1EB00AD2DA4 /* KakaoSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 357699392C09C1EB00AD2DA4 /* KakaoSDK */; }; @@ -118,6 +123,11 @@ 3544D7452C229436007DBD18 /* ChatService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatService.swift; sourceTree = ""; }; 35710D722C23D9030041ECD2 /* EndDebateViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndDebateViewModel.swift; sourceTree = ""; }; 35710D742C23D9350041ECD2 /* EndDebateService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndDebateService.swift; sourceTree = ""; }; + 35710D762C23DBEA0041ECD2 /* DebateSummaryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebateSummaryViewModel.swift; sourceTree = ""; }; + 35710D7A2C23DC360041ECD2 /* DebateSummaryService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebateSummaryService.swift; sourceTree = ""; }; + 35710D7C2C23DC6A0041ECD2 /* GetDebateRoomViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetDebateRoomViewModel.swift; sourceTree = ""; }; + 35710D7E2C23DC830041ECD2 /* GetDebateRoomService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetDebateRoomService.swift; sourceTree = ""; }; + 35710D812C23DCA40041ECD2 /* GetDebateRoom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetDebateRoom.swift; sourceTree = ""; }; 3576660F2BBD4BF6002C226A /* ReportListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportListView.swift; sourceTree = ""; }; 357666122BBD54AA002C226A /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = ""; }; 357699432C09C7B900AD2DA4 /* LoginService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginService.swift; sourceTree = ""; }; @@ -235,6 +245,7 @@ children = ( 3544D73F2C228EFC007DBD18 /* CreateDebateRoomService.swift */, 3586B5572C23D27C006B1458 /* RecentNewsService.swift */, + 35710D7E2C23DC830041ECD2 /* GetDebateRoomService.swift */, ); path = Service; sourceTree = ""; @@ -244,6 +255,7 @@ children = ( 3544D7422C228F54007DBD18 /* CreateDebateRoomViewModel.swift */, 3586B5592C23D296006B1458 /* RecentNewsViewModel.swift */, + 35710D7C2C23DC6A0041ECD2 /* GetDebateRoomViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -265,6 +277,30 @@ path = ViewModel; sourceTree = ""; }; + 35710D782C23DC100041ECD2 /* ViewModel */ = { + isa = PBXGroup; + children = ( + 35710D762C23DBEA0041ECD2 /* DebateSummaryViewModel.swift */, + ); + path = ViewModel; + sourceTree = ""; + }; + 35710D792C23DC250041ECD2 /* Service */ = { + isa = PBXGroup; + children = ( + 35710D7A2C23DC360041ECD2 /* DebateSummaryService.swift */, + ); + path = Service; + sourceTree = ""; + }; + 35710D802C23DC970041ECD2 /* GetDebateRoomModel */ = { + isa = PBXGroup; + children = ( + 35710D812C23DCA40041ECD2 /* GetDebateRoom.swift */, + ); + path = GetDebateRoomModel; + sourceTree = ""; + }; 357666112BBD5494002C226A /* Splah */ = { isa = PBXGroup; children = ( @@ -312,6 +348,7 @@ 6C41B8D62BE1048500274FA4 /* ChatList */ = { isa = PBXGroup; children = ( + 35710D802C23DC970041ECD2 /* GetDebateRoomModel */, 3586B5542C23D246006B1458 /* RecentNewsModel */, 3544D7412C228F39007DBD18 /* ViewModel */, 3544D73E2C228EDB007DBD18 /* Service */, @@ -621,6 +658,8 @@ 6CE103182BD57A1600498AA4 /* Summary */ = { isa = PBXGroup; children = ( + 35710D792C23DC250041ECD2 /* Service */, + 35710D782C23DC100041ECD2 /* ViewModel */, 6CE103192BD57A2500498AA4 /* DebateSummaryView.swift */, ); path = Summary; @@ -813,6 +852,7 @@ 6CE103102BD56A5B00498AA4 /* TypeReportViewModel.swift in Sources */, 6C5B0C8A2C1C308A00A0D5F4 /* ScoopAPIBookmarks.swift in Sources */, 6CF130C52BAB79DE00A437B6 /* ScoopAPI.swift in Sources */, + 35710D822C23DCA40041ECD2 /* GetDebateRoom.swift in Sources */, 6CE103132BD56B1200498AA4 /* DailyReportView.swift in Sources */, 6C454A7A2B9DA67C006FD9D0 /* SignUpViewModel.swift in Sources */, 6CC6737A2C217C4B009FB30E /* ScoopAPILogin.swift in Sources */, @@ -829,6 +869,7 @@ 6C41B8D22BDE696200274FA4 /* NewsType.swift in Sources */, 357666102BBD4BF6002C226A /* ReportListView.swift in Sources */, 6C41B8D42BDE6D2500274FA4 /* TypePieChartView.swift in Sources */, + 35710D772C23DBEA0041ECD2 /* DebateSummaryViewModel.swift in Sources */, 6C3237A12B7C377600B699AB /* BookmarkViewModel.swift in Sources */, 6C7651462BF5B45A00196536 /* DetailNews.swift in Sources */, 6C3237AC2B7C382200B699AB /* NewsList.swift in Sources */, @@ -873,9 +914,12 @@ 6C454A7C2B9DA71C006FD9D0 /* SignUpView.swift in Sources */, 6C41B8DA2BE104A800274FA4 /* RecentNewsCardView.swift in Sources */, 3509091A2C1C1248007D76A1 /* TokenManager.swift in Sources */, + 35710D7D2C23DC6A0041ECD2 /* GetDebateRoomViewModel.swift in Sources */, + 35710D7B2C23DC360041ECD2 /* DebateSummaryService.swift in Sources */, 35710D732C23D9030041ECD2 /* EndDebateViewModel.swift in Sources */, 6CF130C72BAB7B9800A437B6 /* ScoopAPINews.swift in Sources */, 6CC6737E2C233443009FB30E /* StatisticsService.swift in Sources */, + 35710D7F2C23DC830041ECD2 /* GetDebateRoomService.swift in Sources */, 6C7651402BF37F3400196536 /* Log.swift in Sources */, 6CE1031A2BD57A2500498AA4 /* DebateSummaryView.swift in Sources */, 6CE1030C2BD56A4000498AA4 /* TypeReportView.swift in Sources */, diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ChatListView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ChatListView.swift index 19e20b2b..17357ea8 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ChatListView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ChatListView.swift @@ -11,7 +11,12 @@ struct ChatListView: View { @EnvironmentObject var pathModel: PathModel @StateObject private var newsViewModel = RecentNewsViewModel() - + @StateObject private var viewModel = DebateSummaryViewModel() + @StateObject private var endDebateViewModel = EndDebateViewModel() + @State private var roomId: String = "" // EndDebateViewModel로부터 받아올 roomId + @StateObject private var getdebateroomviewModel = GetDebateRoomViewModel() + + var body: some View { ZStack { Color.backgroundDark.ignoresSafeArea(.all) @@ -32,28 +37,28 @@ struct ChatListView: View { Text("최근 본 뉴스") .foregroundStyle(.basicWhite) .font(.pretendardBold32) -// HStack { -// RecentNewsCardView() -// Spacer() -// RecentNewsCardView() -// Spacer() -// RecentNewsCardView() -// } + // HStack { + // RecentNewsCardView() + // Spacer() + // RecentNewsCardView() + // Spacer() + // RecentNewsCardView() + // } HStack { - if newsViewModel.news.isEmpty { - Text("최근 읽은 뉴스를 불러오는 중...") - .onAppear { - print("뷰가 나타남 - 최근 읽은 뉴스 조회 시작") - newsViewModel.fetchViewedHistory() - } - } else { - ForEach(newsViewModel.news.prefix(3), id: \.id) { news in - RecentNewsCardView(news: news) - Spacer() + if newsViewModel.news.isEmpty { + Text("최근 읽은 뉴스를 불러오는 중...") + .onAppear { + print("뷰가 나타남 - 최근 읽은 뉴스 조회 시작") + newsViewModel.fetchViewedHistory() } + } else { + ForEach(newsViewModel.news.prefix(3), id: \.id) { news in + RecentNewsCardView(news: news) + Spacer() } } - .padding() + } + .padding() } } @@ -63,174 +68,228 @@ struct ChatListView: View { Text("채팅방") .foregroundStyle(.basicWhite) .font(.pretendardBold32) - debateChatCellView - debateChatCellView2 - debateChatCellView3 - debateChatCellView4 - debateChatCellView5 + // debateChatCellView + // debateChatCellView2 + // debateChatCellView3 + // debateChatCellView4 + // debateChatCellView5 + ForEach(getdebateroomviewModel.debates) { debate in + DebateChatCellView(debate: debate) + } + } + .onAppear { + print("채팅방 불러와짐") + getdebateroomviewModel.fetchDebates(page: 5, size: 10) } } - var debateChatCellView: some View { - HStack { - HStack(alignment: .center, spacing: 16) { - Text("🏛️") - .padding(.leading, 26) - .font(.pretendardBold32) - Text("삼성, 갤럭시Z플립6 두뇌 전량 퀄컴칩 탑재하나") - .foregroundStyle(.gray07) - .font(.pretendardBold24) - .padding(.vertical, 24) - - Spacer() + struct DebateChatCellView: View { + let debate: GetDebateRoom + let emojis = ["🏛️", "🔥", "📌", "⭐️", "🧬", "👩🏼‍💻", "🎨", "🎬", "💌", "🔗", "👀"] + + @EnvironmentObject var pathModel: PathModel + + var body: some View { + let randomEmoji = emojis.randomElement() ?? "🏛️" // 이모지가 선택되지 않으면 기본값을 설정합니다. + + HStack { + HStack(alignment: .center, spacing: 16) { +// Text("🏛️") +// .padding(.leading, 26) +// .font(.pretendardBold32) + Text(randomEmoji) + .padding(.leading, 26) + .font(.pretendardBold32) + Text(debate.topic.isEmpty ? "토론을 시작해주세요!" : debate.topic) + .foregroundStyle(.gray07) + .font(.pretendardBold24) + .padding(.vertical, 24) + + Spacer() + Button { + pathModel.paths.append(.chatView(isAiMode: true)) + } label: { + Image(systemName: "chevronRight") + .foregroundColor(.gray01) + } + } + .background(.gray01) + .clipShape(RoundedRectangle(cornerRadius: 8)) + .padding(.trailing, 16) + Button { - pathModel.paths.append(.chatView(isAiMode: true)) + pathModel.paths.append(.debateSummaryView) } label: { - Image(systemName: "quote.bubble") - .background(.gray01) + Image("quote.bubble") + .foregroundColor(.gray01) + } + .frame(width: 80, height: 80) + .background(.gray01) + .clipShape(RoundedRectangle(cornerRadius: 8)) } - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .padding(.trailing, 16) - - //TODO: 버튼 영역 수정하기 - Button { - pathModel.paths.append(.debateSummaryView) - } label: { - Image(.chevronLeft) -// .background(.gray01) - - } - .frame(width: 80, height: 80) - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) } } - var debateChatCellView2: some View { - HStack { - HStack(alignment: .center, spacing: 16) { - Text("📱") - .padding(.leading, 26) - .font(.pretendardBold32) - Text("모친 내친 한미약품 형제… 2644억 상속세 마련방안은 `아직`") - .foregroundStyle(.gray07) - .font(.pretendardBold24) - .padding(.vertical, 24) - - Spacer() - Image(.chevronRight) - } - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .padding(.trailing, 16) - - //TODO: 버튼 영역 수정하기 - Button { - pathModel.paths.append(.debateSummaryView) - } label: { - Image(.chevronLeft) -// .background(.gray01) - - } - .frame(width: 80, height: 80) - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - } - } - var debateChatCellView3: some View { - HStack { - HStack(alignment: .center, spacing: 16) { - Text("💌") - .padding(.leading, 26) - .font(.pretendardBold32) - Text("[ET단상]한바탕 휩쓴 방산 해킹 사건, 보안의 다른 \'답\'을 찾아야 할 때") - .foregroundStyle(.gray07) - .font(.pretendardBold24) - .padding(.vertical, 24) - - Spacer() - Image(.chevronRight) - } - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .padding(.trailing, 16) - - //TODO: 버튼 영역 수정하기 - Button { - pathModel.paths.append(.debateSummaryView) - } label: { - Image(.chevronLeft) -// .background(.gray01) - - } - .frame(width: 80, height: 80) - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - } - } - var debateChatCellView4: some View { - HStack { - HStack(alignment: .center, spacing: 16) { - Text("📱") - .padding(.leading, 26) - .font(.pretendardBold32) - Text("삼성, 갤럭시Z플립6 두뇌 전량 퀄컴칩 탑재하나") - .foregroundStyle(.gray07) - .font(.pretendardBold24) - .padding(.vertical, 24) - - Spacer() - Image(.chevronRight) - } - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .padding(.trailing, 16) - - //TODO: 버튼 영역 수정하기 - Button { - pathModel.paths.append(.debateSummaryView) - } label: { - Image(.chevronLeft) +// var debateChatCellView: some View { +// HStack { +// HStack(alignment: .center, spacing: 16) { +// Text("🏛️") +// .padding(.leading, 26) +// .font(.pretendardBold32) +// Text("삼성, 갤럭시Z플립6 두뇌 전량 퀄컴칩 탑재하나") +// .foregroundStyle(.gray07) +// .font(.pretendardBold24) +// .padding(.vertical, 24) +// +// Spacer() +// Button { +// pathModel.paths.append(.chatView(isAiMode: true)) +// } label: { +// Image(systemName: "chevronRight") +// .foregroundColor(.gray01) +// } +// } +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .padding(.trailing, 16) +// +// //TODO: 버튼 영역 수정하기 +// Button { +// pathModel.paths.append(.debateSummaryView) +// } label: { +// Image("quote.bubble") +// .foregroundColor(.gray01) +// +// } +// .frame(width: 80, height: 80) +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// } +// } +// var debateChatCellView2: some View { +// HStack { +// HStack(alignment: .center, spacing: 16) { +// Text("📱") +// .padding(.leading, 26) +// .font(.pretendardBold32) +// Text("모친 내친 한미약품 형제… 2644억 상속세 마련방안은 `아직`") +// .foregroundStyle(.gray07) +// .font(.pretendardBold24) +// .padding(.vertical, 24) +// +// Spacer() +// Image(.chevronRight) +// } +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .padding(.trailing, 16) +// +// //TODO: 버튼 영역 수정하기 +// Button { +// pathModel.paths.append(.debateSummaryView) +// } label: { +// Image(.chevronLeft) +//// .background(.gray01) +// +// } +// .frame(width: 80, height: 80) +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// } +// } +// var debateChatCellView3: some View { +// HStack { +// HStack(alignment: .center, spacing: 16) { +// Text("💌") +// .padding(.leading, 26) +// .font(.pretendardBold32) +// Text("[ET단상]한바탕 휩쓴 방산 해킹 사건, 보안의 다른 \'답\'을 찾아야 할 때") +// .foregroundStyle(.gray07) +// .font(.pretendardBold24) +// .padding(.vertical, 24) +// +// Spacer() +// Image(.chevronRight) +// } +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .padding(.trailing, 16) +// +// //TODO: 버튼 영역 수정하기 +// Button { +// pathModel.paths.append(.debateSummaryView) +// } label: { +// Image(.chevronLeft) +//// .background(.gray01) +// +// } +// .frame(width: 80, height: 80) +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// } +// } +// var debateChatCellView4: some View { +// HStack { +// HStack(alignment: .center, spacing: 16) { +// Text("📱") +// .padding(.leading, 26) +// .font(.pretendardBold32) +// Text("삼성, 갤럭시Z플립6 두뇌 전량 퀄컴칩 탑재하나") +// .foregroundStyle(.gray07) +// .font(.pretendardBold24) +// .padding(.vertical, 24) +// +// Spacer() +// Image(.chevronRight) +// } +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .padding(.trailing, 16) +// +// //TODO: 버튼 영역 수정하기 +// Button { +// pathModel.paths.append(.debateSummaryView) +// } label: { +// Image(.chevronLeft) +//// .background(.gray01) +// +// } +// .frame(width: 80, height: 80) +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// } +// } +// var debateChatCellView5: some View { +// HStack { +// HStack(alignment: .center, spacing: 16) { +// Text("🏛️") +// .padding(.leading, 26) +// .font(.pretendardBold32) +// Text("삼성, 갤럭시Z플립6 두뇌 전량 퀄컴칩 탑재하나") +// .foregroundStyle(.gray07) +// .font(.pretendardBold24) +// .padding(.vertical, 24) +// +// Spacer() +// Image(.chevronRight) +// } +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .padding(.trailing, 16) +// +// //TODO: 버튼 영역 수정하기 +// Button { +// pathModel.paths.append(.debateSummaryView) +// } label: { +// Image(systemName: "quote.bubble") // .background(.gray01) - - } - .frame(width: 80, height: 80) - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - } - } - var debateChatCellView5: some View { - HStack { - HStack(alignment: .center, spacing: 16) { - Text("🏛️") - .padding(.leading, 26) - .font(.pretendardBold32) - Text("삼성, 갤럭시Z플립6 두뇌 전량 퀄컴칩 탑재하나") - .foregroundStyle(.gray07) - .font(.pretendardBold24) - .padding(.vertical, 24) - - Spacer() - Image(.chevronRight) - } - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .padding(.trailing, 16) - - //TODO: 버튼 영역 수정하기 - Button { - pathModel.paths.append(.debateSummaryView) - } label: { - Image(systemName: "quote.bubble") - .background(.gray01) - - } - .frame(width: 80, height: 80) - .background(.gray01) - .clipShape(RoundedRectangle(cornerRadius: 8)) - } - } +// +// } +// .frame(width: 80, height: 80) +// .background(.gray01) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// } +// } } #Preview { diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/GetDebateRoomModel/GetDebateRoom.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/GetDebateRoomModel/GetDebateRoom.swift new file mode 100644 index 00000000..a24fbd01 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/GetDebateRoomModel/GetDebateRoom.swift @@ -0,0 +1,15 @@ +// +// GetDebateRoom.swift +// RollTheDice +// +// Created by 신예진 on 6/20/24. +// + +import Foundation + + +struct GetDebateRoom: Identifiable, Codable { + let id: Int + let topic: String + let isClosed: Bool? +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/Service/GetDebateRoomService.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/Service/GetDebateRoomService.swift new file mode 100644 index 00000000..49601d7d --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/Service/GetDebateRoomService.swift @@ -0,0 +1,50 @@ +// +// GetDebateRoomService.swift +// RollTheDice +// +// Created by 신예진 on 6/20/24. +// + +//MARK : 토론방 전체 조회 +import Foundation +import Moya + +enum GetDebateRoomService { + case getDebates(page: Int, size: Int) +} + +extension GetDebateRoomService: TargetType { + var baseURL: URL { + return URL(string: "http://roll-the-dice.store:8080")! + } + + var path: String { + switch self { + case .getDebates: + return "/debates" + } + } + + var method: Moya.Method { + switch self { + case .getDebates: + return .get + } + } + + var task: Task { + switch self { + case let .getDebates(page, size): + return .requestParameters(parameters: ["page": page, "size": size], encoding: URLEncoding.queryString) + } + } + + var headers: [String: String]? { + guard let token = TokenManager.shared.accessToken else { return nil } + return ["Authorization": "Bearer \(token)"] + } + + var sampleData: Data { + return Data() + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ViewModel/GetDebateRoomViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ViewModel/GetDebateRoomViewModel.swift new file mode 100644 index 00000000..b003450b --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/ChatList/ViewModel/GetDebateRoomViewModel.swift @@ -0,0 +1,34 @@ +// +// GetDebateRoomViewModel.swift +// RollTheDice +// +// Created by 신예진 on 6/20/24. +// + +import Foundation +import Combine +import Moya + +class GetDebateRoomViewModel: ObservableObject { + @Published var debates: [GetDebateRoom] = [] + private var cancellables = Set() + private let provider = MoyaProvider() + + func fetchDebates(page: Int, size: Int) { + provider.requestPublisher(.getDebates(page: page, size: size)) + .map(\.data) + .decode(type: [GetDebateRoom].self, decoder: JSONDecoder()) + .sink(receiveCompletion: { completion in + switch completion { + case .failure(let error): + print("Error fetching debates: \(error)") + case .finished: + break + } + }, receiveValue: { [weak self] debates in + self?.debates = debates + print("Fetched debates: \(debates)") // 로그 확인용 + }) + .store(in: &cancellables) + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/DebateSummaryView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/DebateSummaryView.swift index 62319d1e..55ba3742 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/DebateSummaryView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/DebateSummaryView.swift @@ -9,6 +9,9 @@ import SwiftUI struct DebateSummaryView: View { @EnvironmentObject var pathModel: PathModel + @StateObject private var viewModel = DebateSummaryViewModel() + @StateObject private var endDebateViewModel = EndDebateViewModel() + @State private var roomId: String = "" // EndDebateViewModel로부터 받아오는 roomid var body: some View { ZStack { @@ -53,7 +56,7 @@ struct DebateSummaryView: View { } - // TODO: 말풍선 수정하기 + // TODO: 말풍선 수정하기 .overlay { VStack(spacing: 20) { Rectangle() @@ -115,3 +118,4 @@ struct DebateSummaryView: View { #Preview { DebateSummaryView() } + diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/Service/DebateSummaryService.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/Service/DebateSummaryService.swift new file mode 100644 index 00000000..b161bd3d --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/Service/DebateSummaryService.swift @@ -0,0 +1,43 @@ +// +// DebateSummaryService.swift +// RollTheDice +// +// Created by 신예진 on 6/20/24. +// + +import Foundation +import Moya + +enum DebateSummaryService { + case getSummary(roomId: Int) +} + +extension DebateSummaryService: TargetType { + var baseURL: URL { + return URL(string: "http://roll-the-dice.store:8080")! + } + + var path: String { + switch self { + case .getSummary(let roomId): + return "/debates/summary/\(roomId)" + } + } + + var method: Moya.Method { + return .post + } + + var task: Task { + return .requestPlain + } + + var headers: [String : String]? { + guard let token = TokenManager.shared.accessToken else { return nil } + return ["Authorization": "Bearer \(token)"] + } + + var sampleData: Data { + return Data() + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/ViewModel/DebateSummaryViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/ViewModel/DebateSummaryViewModel.swift new file mode 100644 index 00000000..638529c4 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Debate/Summary/ViewModel/DebateSummaryViewModel.swift @@ -0,0 +1,46 @@ +// +// DebateSummaryViewModel.swift +// RollTheDice +// +// Created by 신예진 on 6/20/24. +// + +import Foundation +import Combine +import Moya + +class DebateSummaryViewModel: ObservableObject { + @Published var summary: String? + @Published var roomId: Int? + @Published var isLoading: Bool = false + @Published var errorMessage: String? + + private let provider = MoyaProvider() + + func fetchSummary(roomId: Int) { + isLoading = true + provider.request(.getSummary(roomId: roomId)) { result in + self.isLoading = false + switch result { + case .success(let response): + do { + let json = try JSONSerialization.jsonObject(with: response.data, options: []) + if let dict = json as? [String: Any], let summary = dict["summary"] as? String { + self.summary = summary + self.roomId = roomId + print("토론 요약 성공") + } else { + self.errorMessage = "Invalid response format" + print("토론 요약 유효하지 않은 포맷") + } + } catch { + self.errorMessage = "Failed to parse response" + print("토론 요약 reponse 못 받아옴") + } + case .failure(let error): + self.errorMessage = error.localizedDescription + print("토론 요약 오류/실패") + } + } + } +}