Skip to content

Commit

Permalink
✨ :: [#68] Add Expo Create ViewModel / setup Var / Expo Create Design…
Browse files Browse the repository at this point in the history
… Edit
  • Loading branch information
Xixn2 committed Nov 27, 2024
1 parent ae64171 commit 92e6f75
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ struct ExpoCreateView: View {
@State private var trainingCount: [String] = [""]
@State private var selectedImage: UIImage? = nil
@State private var isImagePickerPresented = false
@StateObject var viewModel: ExpoCreateViewModel

var body: some View {

Text("박람회 생성하기")
.expoFont(.body1R)

ScrollView {
VStack(alignment: .leading, spacing: 0) {
Text("사진")
Expand Down Expand Up @@ -213,8 +218,8 @@ struct ExpoCreateView: View {
HStack(spacing: 0) {
Spacer()
ExpoButton(
text: "수정 완료",
horizontalPadding: 156,
text: "확인",
horizontalPadding: 170,
verticalPadding: 14,
backColor: ExpoColor.main.swiftUIColor,
actionColor: ExpoColor.main300.swiftUIColor
Expand Down Expand Up @@ -245,5 +250,5 @@ struct ExpoCreateView: View {
}

#Preview {
ExpoCreateView()
ExpoCreateView(viewModel: ExpoCreateViewModel())
}
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct TabBarView: View {
}
.tag(2)

ExpoCreateView()
ExpoCreateView(viewModel: ExpoCreateViewModel())
.tabItem {
Image(selectedTab == 3 ? "onExpo" : "offExpo")
Text("박람회 생성")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

struct ExpoCreateResponse: Codable {
let expoId: String
public struct ExpoCreateResponse: Codable {
public let expoId: String
}

0 comments on commit 92e6f75

Please sign in to comment.