diff --git a/Projects/App/Sources/Application/NeedleGenerated.swift b/Projects/App/Sources/Application/NeedleGenerated.swift index ff0e9375..64bbd30e 100644 --- a/Projects/App/Sources/Application/NeedleGenerated.swift +++ b/Projects/App/Sources/Application/NeedleGenerated.swift @@ -35,6 +35,7 @@ import MainFeature import MainFeatureInterface import MajorDomain import MajorDomainInterface +import MyPageFeatureInterface import NeedleFoundation import RootFeature import SigninFeature diff --git a/Projects/Feature/InputPrizeInfoFeature/Sources/Model/InputPrizeInfoModel.swift b/Projects/Feature/InputPrizeInfoFeature/Sources/Model/InputPrizeInfoModel.swift index 8773e0be..8151ff1a 100644 --- a/Projects/Feature/InputPrizeInfoFeature/Sources/Model/InputPrizeInfoModel.swift +++ b/Projects/Feature/InputPrizeInfoFeature/Sources/Model/InputPrizeInfoModel.swift @@ -52,5 +52,4 @@ extension InputPrizeInfoModel: InputPrizeInfoActionProtocol { func updateIsPresentedPrizeAtDatePicker(isPresented: Bool) { self.isPresentedPrizeAtDatePicker = isPresented } - } diff --git a/Projects/Feature/MyPageFeature/Sources/Model/MyPageModel.swift b/Projects/Feature/MyPageFeature/Sources/Model/MyPageModel.swift index d1f8159b..35575d30 100644 --- a/Projects/Feature/MyPageFeature/Sources/Model/MyPageModel.swift +++ b/Projects/Feature/MyPageFeature/Sources/Model/MyPageModel.swift @@ -46,6 +46,12 @@ final class MyPageModel: ObservableObject, MyPageStateProtocol { @Published var isPresentedProjectStartAtDatePicker: Bool = false @Published var isPresentedProjectEndAtDatePicker: Bool = false @Published var isPresentedProjectTechStackAppend: Bool = false + + // MARK: Prize + @Published var prizeList: [PrizeModel] = [] + @Published var collapsedPrize: [Bool] = [] + @Published var isPresentedPrizeAtDatePicker: Bool = false + @Published var focusedPrizeIndex: Int = 0 } extension MyPageModel: MyPageActionProtocol {} diff --git a/Projects/Feature/MyPageFeature/Sources/Model/MyPagePrizeModel.swift b/Projects/Feature/MyPageFeature/Sources/Model/MyPagePrizeModel.swift index 954dd727..e126fe20 100644 --- a/Projects/Feature/MyPageFeature/Sources/Model/MyPagePrizeModel.swift +++ b/Projects/Feature/MyPageFeature/Sources/Model/MyPagePrizeModel.swift @@ -1,9 +1,77 @@ -// -// MyPagePrizeModel.swift -// MyPageFeature -// -// Created by 최형우 on 2023/08/02. -// Copyright © 2023 com.msg. All rights reserved. -// - import Foundation +import DateUtil + +struct PrizeModel: Equatable { + var name: String + var prize: String + var prizeAt: Date + + var prizeAtString: String { + prizeAt.toStringCustomFormat(format: "yyyy.MM") + } +} + +protocol MyPagePrizeStateProtocol { + var prizeList: [PrizeModel] { get } + var collapsedPrize: [Bool] { get } + var isPresentedPrizeAtDatePicker: Bool { get } + var focusedPrizeIndex: Int { get } +} + +protocol MyPagePrizeActionProtocol: AnyObject { + func toggleCollapsedPrize(index: Int) + func updatePrizeName(index: Int, name: String) + func updatePrizePrize(index: Int, prize: String) + func updatePrizePrizeAt(index: Int, prizeAt: Date) + func appendEmptyPrize() + func removePrize(index: Int) + func updateFocusedPrizeIndex(index: Int) + func updateIsPresentedPrizeAtDatePicker(isPresented: Bool) +} + +extension MyPageModel: MyPagePrizeActionProtocol { + func toggleCollapsedPrize(index: Int) { + guard collapsedPrize[safe: index] != nil else { return } + self.collapsedPrize[index].toggle() + } + + func updatePrizeName(index: Int, name: String) { + guard prizeList[safe: index] != nil else { return } + self.prizeList[index].name = name + } + + func updatePrizePrize(index: Int, prize: String) { + guard prizeList[safe: index] != nil else { return } + self.prizeList[index].prize = prize + } + + func updatePrizePrizeAt(index: Int, prizeAt: Date) { + guard prizeList[safe: index] != nil else { return } + self.prizeList[index].prizeAt = prizeAt + } + + func appendEmptyPrize() { + let newPrize = PrizeModel( + name: "", + prize: "", + prizeAt: Date() + ) + self.prizeList.append(newPrize) + self.collapsedPrize.append(false) + } + + func removePrize(index: Int) { + guard prizeList[safe: index] != nil, collapsedPrize[safe: index] != nil else { return } + self.prizeList.remove(at: index) + self.collapsedPrize.remove(at: index) + } + + func updateFocusedPrizeIndex(index: Int) { + self.focusedPrizeIndex = index + } + + func updateIsPresentedPrizeAtDatePicker(isPresented: Bool) { + self.isPresentedPrizeAtDatePicker = isPresented + } + +}