From 78503b4e1bb2ea94436c6979bcbac89cc9c4d623 Mon Sep 17 00:00:00 2001 From: Atsuhiro Muroyama Date: Sat, 12 Aug 2023 16:20:02 +0900 Subject: [PATCH] add: change view when QRcode is valid --- .../QRReaderPage/QRReaderViewController.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/DJSystemiOS/Pages/QRReaderPage/QRReaderViewController.swift b/DJSystemiOS/Pages/QRReaderPage/QRReaderViewController.swift index aba58a4..1865464 100644 --- a/DJSystemiOS/Pages/QRReaderPage/QRReaderViewController.swift +++ b/DJSystemiOS/Pages/QRReaderPage/QRReaderViewController.swift @@ -53,10 +53,19 @@ extension QRReaderViewController: QRScannerViewDelegate { let extractedRoomID = URL.extractRoomID(inputURL: code) switch extractedRoomID { case .success(let roomID): - let validURL = roomID - let roomOverViewPageView = RoomOverviewViewController(roomAPI: Room.API(), roomOverview: RoomOverview(id: validURL, name: "", description: "")) - navigationController?.pushViewController(roomOverViewPageView, animated: true) - + Task{ + let client = APIClient(baseURL: AppConfig().BaseAPIURL) + let result = await client.get(from: .getRoom(roomId: roomID), dataType: Room.API.GetRoomResponse.self) + switch result { + case .success(let response): + let roomOverViewPageView = RoomOverviewViewController(roomAPI: Room.API(), roomOverview: RoomOverview(id: response.id, name: response.name, description: response.description)) + navigationController?.pushViewController(roomOverViewPageView, animated: true) + case .failure: + let alert = UIAlertController(title: "エラー", message: "ルームが見つかりませんでした。", preferredStyle: .alert) + alert.addAction(.init(title: "OK", style: .default)) + self.present(alert, animated: true) + } + } case .failure: let alert = UIAlertController(title: "エラー", message: "このURLに対応するルームが見つかりません。", preferredStyle: .alert) alert.addAction(.init(title: "OK", style: .default))