generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#220] MyPgaeFeature / MyPagePrizeModel 추가
- Loading branch information
Showing
4 changed files
with
83 additions
and
9 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
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
84 changes: 76 additions & 8 deletions
84
Projects/Feature/MyPageFeature/Sources/Model/MyPagePrizeModel.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 |
---|---|---|
@@ -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 | ||
} | ||
|
||
} |