Skip to content

Commit

Permalink
network: home Qeustion Network (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe0929 committed Jun 3, 2024
1 parent cd78a70 commit 824f103
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
3663C2AD2BF9459E004C07AC /* Pretendard-Thin.otf in Resources */ = {isa = PBXBuildFile; fileRef = 3663C2A42BF9459E004C07AC /* Pretendard-Thin.otf */; };
3663C2AF2BF950AC004C07AC /* SharedInstaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3663C2AE2BF950AC004C07AC /* SharedInstaView.swift */; };
367B146B2BF8EDEA000DBA22 /* Adjust.swift in Sources */ = {isa = PBXBuildFile; fileRef = 367B146A2BF8EDEA000DBA22 /* Adjust.swift */; };
3689D5E62C0E3C260060B674 /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3689D5E52C0E3C260060B674 /* HomeViewModel.swift */; };
AF2B55F42BF939B700F382A0 /* APITarget+Members.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF2B55F32BF939B700F382A0 /* APITarget+Members.swift */; };
AF2B55FE2BF93B7800F382A0 /* APITarget+Questions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF2B55FD2BF93B7800F382A0 /* APITarget+Questions.swift */; };
AF2B56002BF93F9E00F382A0 /* APITarget+Attempts.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF2B55FF2BF93F9E00F382A0 /* APITarget+Attempts.swift */; };
Expand Down Expand Up @@ -116,6 +117,7 @@
3663C2A42BF9459E004C07AC /* Pretendard-Thin.otf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Pretendard-Thin.otf"; path = "../../../../../../../../../../Downloads/Pretendard-1.3.9 2/public/static/Pretendard-Thin.otf"; sourceTree = "<group>"; };
3663C2AE2BF950AC004C07AC /* SharedInstaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedInstaView.swift; sourceTree = "<group>"; };
367B146A2BF8EDEA000DBA22 /* Adjust.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Adjust.swift; sourceTree = "<group>"; };
3689D5E52C0E3C260060B674 /* HomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
AF2B55F32BF939B700F382A0 /* APITarget+Members.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APITarget+Members.swift"; sourceTree = "<group>"; };
AF2B55FD2BF93B7800F382A0 /* APITarget+Questions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APITarget+Questions.swift"; sourceTree = "<group>"; };
AF2B55FF2BF93F9E00F382A0 /* APITarget+Attempts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APITarget+Attempts.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -276,6 +278,7 @@
AFD35A732BF51E1600354EE5 /* Model */ = {
isa = PBXGroup;
children = (
3689D5E52C0E3C260060B674 /* HomeViewModel.swift */,
AFD35A872BF51F7900354EE5 /* MockModel.swift */,
AFB3AB1E2BF9512900D76C23 /* TodayQuiz.swift */,
);
Expand Down Expand Up @@ -563,6 +566,7 @@
AF2B55F42BF939B700F382A0 /* APITarget+Members.swift in Sources */,
AFD35A612BF51DB700354EE5 /* SceneDelegate.swift in Sources */,
2E559B1C2BF9166F000FBE89 /* CustomButton.swift in Sources */,
3689D5E62C0E3C260060B674 /* HomeViewModel.swift in Sources */,
AF6565472BF8EED4001D7D22 /* HomeView.swift in Sources */,
AFD35A802BF51F6400354EE5 /* MockImages.swift in Sources */,
AFD35A962BF5207F00354EE5 /* DTO+Namespace.swift in Sources */,
Expand Down
34 changes: 34 additions & 0 deletions SOPKATHON-iOS-TEAM2/SOPKATHON-iOS-TEAM2/Model/HomeViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// HomeViewModel.swift
// SOPKATHON-iOS-TEAM2
//
// Created by 이지희 on 6/4/24.
//

import SwiftUI

import Moya


class HomeViewModel: ObservableObject {
@State var homeQuestions: [DTO.GetQuestionsResponse.Question] = []

func getQuestionHome() {
Providers.questionProvier.request(.getQuestions) { result in
switch result {
case .success(let response):
do {
let decoder = JSONDecoder()
let response = try decoder.decode(DTO.GetQuestionsResponse.self, from: response.data)
self.homeQuestions = response.data
} catch {
print("Decoding error: \(error)")
}


case .failure(let error):
print(error)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

extension DTO {
struct GetQuestionsResponse: Codable {
let statusCode: Int
let status: Int
let data: [Question]
}
}
Expand Down

0 comments on commit 824f103

Please sign in to comment.