Skip to content

Commit

Permalink
✨ [#220] MyPgaeFeature / MyPagePrizeModel 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsh153 committed Aug 3, 2023
1 parent d802102 commit 8730195
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
1 change: 1 addition & 0 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import MainFeature
import MainFeatureInterface
import MajorDomain
import MajorDomainInterface
import MyPageFeatureInterface
import NeedleFoundation
import RootFeature
import SigninFeature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ extension InputPrizeInfoModel: InputPrizeInfoActionProtocol {
func updateIsPresentedPrizeAtDatePicker(isPresented: Bool) {
self.isPresentedPrizeAtDatePicker = isPresented
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
@@ -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
}

}

0 comments on commit 8730195

Please sign in to comment.