Skip to content

Commit

Permalink
Impl EditSchool
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Oct 7, 2024
1 parent 98faed9 commit 2306663
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ final class EditProfileViewModel: ObservableObject {
extension EditProfileViewModel {
func editProfile() {
UserService.shared.editUser(
.init(nickname: nickname)
.init(
nickname: nickname
)
)
.flow(\.editProfileFlow, on: self)
.silentSink()
Expand Down
27 changes: 21 additions & 6 deletions Graduating-iOS/Graduating/Feature/EditSchool/EditSchoolView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import MyDesignSystem
struct EditSchoolView: View {
struct Path: Hashable {}
@EnvironmentObject private var router: Router
@EnvironmentObject private var dialog: DialogProvider

@StateObject private var viewModel = SearchSchoolViewModel()
@StateObject private var searchSchoolViewModel = SearchSchoolViewModel()
@StateObject private var viewModel = EditSchoolViewModel()

private let path: Path
init(path: Path) {
Expand All @@ -22,16 +24,29 @@ extension EditSchoolView {
.foreground(Colors.Label.normal)
.frame(maxWidth: .infinity, alignment: .leading)
SearchSchoolContainer(
for: viewModel.searchedSchools,
searchText: $viewModel.searchSchoolName
) { _ in
router.toRoot()
for: searchSchoolViewModel.searchedSchools,
searchText: $searchSchoolViewModel.searchSchoolName
) { school in
viewModel.editSchool(schoolId: school.id)
}
}
.padding(insets)
}
.onAppear {
viewModel.fetchSchools()
searchSchoolViewModel.fetchSchools()
}
.onReceive(viewModel.$editSchoolFlow) { flow in
switch flow {
case .success:
router.toRoot()
case .failure:
dialog.present(
.init(title: "수정 실패")
.message("잠시 후 다시 시도해 주세요")
)
default:
break
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Author: hhhello0507
// Created: 10/7/24


import Foundation
import Data
import Model
import Combine
import Shared

final class EditSchoolViewModel: ObservableObject {
var subscription = Set<AnyCancellable>()

@Published var editSchoolFlow = Flow.idle
}

extension EditSchoolViewModel {
func editSchool(schoolId: Int) {
UserService.shared.editUser(
.init(schoolId: schoolId)
)
.flow(\.editSchoolFlow, on: self)
.silentSink()
.store(in: &subscription)
}
}
1 change: 1 addition & 0 deletions Graduating-iOS/Graduating/Feature/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extension MainView: View {
}
}
.onAppear {
print("MEAL")
fetchMeals()
}
// .onAppear {
Expand Down
13 changes: 11 additions & 2 deletions Graduating-iOS/Model/User/UserDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
import Foundation

public struct EditUserReq: ReqProtocol {
public let nickname: String
public init(nickname: String) {
public let nickname: String?
public let graduatingYear: Int?
public let schoolId: Int?

public init(
nickname: String? = nil,
graduatingYear: Int? = nil,
schoolId: Int? = nil
) {
self.nickname = nickname
self.graduatingYear = graduatingYear
self.schoolId = schoolId
}
}

Expand Down

0 comments on commit 2306663

Please sign in to comment.