-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ :: [#68] Add Expo Create ViewModel / setup Var / Expo Create Design…
… Edit
- Loading branch information
Showing
4 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
Projects/App/Sources/Feature/ExpoApplicationFeature/Sources/ExpoCreateViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// ExpoCreateViewModel.swift | ||
// Expo-iOS | ||
// | ||
// Created by 서지완 on 11/27/24. | ||
// Copyright © 2024 SchoolofCompany. All rights reserved. | ||
// | ||
|
||
import Moya | ||
import Domain | ||
import Foundation | ||
|
||
public final class ExpoCreateViewModel: ObservableObject { | ||
private let authProvider = MoyaProvider<ExpoAPI>() | ||
|
||
var userData: ExpoCreateResponse? | ||
private var title: String = "" | ||
private var description: String = "" | ||
private var startedDay: String = "" | ||
private var finishedDay: String = "" | ||
private var location: String = "" | ||
private var coverImage: String = "" | ||
private var scaleX: Float = 0.0 | ||
private var scaleY: Float = 0.0 | ||
|
||
private var passwordServe: String = "" | ||
|
||
|
||
func setupTitle(title: String) { | ||
self.title = title | ||
} | ||
|
||
func setupDescription(description: String) { | ||
self.description = description | ||
} | ||
|
||
func setupStartedDay(startedDay: String) { | ||
self.startedDay = startedDay | ||
} | ||
|
||
func setupFinishedDay(finishedDay: String) { | ||
self.finishedDay = finishedDay | ||
} | ||
|
||
func setupLocation(location: String) { | ||
self.location = location | ||
} | ||
|
||
func setupCoverImage(coverImage: String) { | ||
self.coverImage = coverImage | ||
} | ||
|
||
func setupScaleX(scaleX: Float) { | ||
self.scaleX = scaleX | ||
} | ||
|
||
func setupScaleY(scaleY: Float) { | ||
self.scaleY = scaleY | ||
} | ||
|
||
func expoCreate(completion: @escaping (Bool) -> Void) { | ||
authProvider.request(.expoCreate(param: ExpoCreateRequest( | ||
title: title, | ||
description: description, | ||
startedDay: startedDay, | ||
finishedDay: finishedDay, | ||
location: location, | ||
coverImage: coverImage, | ||
scaleX: scaleX, | ||
scaleY: scaleY | ||
))) { response in | ||
switch response { | ||
case .success(let result): | ||
do { | ||
let statusCode = result.statusCode | ||
if let responseData = try? JSONSerialization.jsonObject(with: result.data, options: []) as? [String: Any], | ||
let message = responseData["message"] as? String { | ||
print("Server message: \(message)") | ||
} else { | ||
print("Response data could not be parsed or 'message' key is missing") | ||
|
||
} | ||
|
||
switch statusCode { | ||
case 200..<300: | ||
print("OK") | ||
|
||
let decoder = JSONDecoder() | ||
if let response = try? decoder.decode(ExpoCreateResponse.self, from: result.data) { | ||
self.userData = response | ||
print("Expo ID: \(response.expoId)") | ||
} else { | ||
print("Failed to decode the response.") | ||
} | ||
|
||
completion(true) | ||
case 500: | ||
print("SERVER ERROR") | ||
completion(false) | ||
default: | ||
print(result) | ||
completion(false) | ||
} | ||
} | ||
case .failure(let err): | ||
print("Error: \(err.localizedDescription)") | ||
completion(false) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters