Skip to content

Commit

Permalink
[Bug] 봉투 수정시 저장 버튼이 정상적으로 눌리지 않던 버그 수정 (#612)
Browse files Browse the repository at this point in the history
* feat: 파일 분리 및, Edit Helper 객체 분리

* feat: envelope Edit 로직 수정, EnvelopeDetailProperty 수정,

S

* feat: relation수정 안되던 API 버그 수정

* feat: envelopeEditProperty를 통한 변수 및 객체 관리 로직 추가

* feat: reset custom button시 selectedItem을 reset하는 로직 생성

* chore: 포멧 수정

* feat: updateBuild version, MyPage로직 변경

* feat: LedgerDetailEditProperty에 대한 로직 수정
  • Loading branch information
MaraMincho authored Oct 3, 2024
1 parent c289946 commit 45885aa
Show file tree
Hide file tree
Showing 24 changed files with 519 additions and 424 deletions.
2 changes: 1 addition & 1 deletion Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let project = Project.makeModule(
"UILaunchStoryboardName": "LaunchScreen",
"BGTaskSchedulerPermittedIdentifiers": "com.oksusu.susu.app",
"CFBundleShortVersionString": "1.0.6",
"CFBundleVersion": "2024093034",
"CFBundleVersion": "2024100235",
"UIUserInterfaceStyle": "Light",
"ITSAppUsesNonExemptEncryption": "No",
"AppstoreAPPID": "6503701515",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct EnvelopeDetailResponse: Decodable {
public struct EnvelopeDetailResponse: Decodable, Equatable {
public let envelope: EnvelopeModel
public let category: CategoryWithCustomModel
public let relationship: RelationshipModel
Expand All @@ -21,4 +21,18 @@ public struct EnvelopeDetailResponse: Decodable {
case friendRelationship
case friend
}

public init(
envelope: EnvelopeModel,
category: CategoryWithCustomModel,
relationship: RelationshipModel,
friendRelationship: FriendRelationshipModel,
friend: FriendModel
) {
self.envelope = envelope
self.category = category
self.relationship = relationship
self.friendRelationship = friendRelationship
self.friend = friend
}
}
6 changes: 3 additions & 3 deletions Projects/Core/SSNetwork/Sources/Moya+Asynchronous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public extension MoyaProvider {
continuation.resume(returning: res)
return
}
if let isSUSUError = String(data: response.data, encoding: .utf8) {
os_log("\(isSUSUError)")
}
continuation.resume(with: .failure(MoyaError.statusCode(response)))

case let .failure(error):
if let errorDescription = error.errorDescription {
os_log("errorDescription: \(errorDescription) \n localizedDescription: \(error.localizedDescription)")
}
let willSendError: Error
switch error {
case let .statusCode(response):
Expand Down
15 changes: 12 additions & 3 deletions Projects/Feature/MyPage/Sources/MyPageEdit/MyPageEdit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ struct MyPageEdit {
}

init() {
userInfo = MyPageSharedState.shared.getMyUserInfoDTO() ?? .init(id: 0, name: "", gender: nil, birth: nil)
let userInfo = MyPageSharedState.shared.getMyUserInfoDTO() ?? .init(id: 0, name: "", gender: nil, birth: nil)
self.userInfo = userInfo
_selectedBottomSheetItem = .init(nil)
let initialSelectedGenderItem = Gender.getGenderByKey(userInfo.gender)
_genderSectionProperty = .init(
.init(
titleText: "성별",
items: .default,
isCustomItem: nil,
initialSelectedID: initialSelectedGenderItem?.id,
customTextFieldPrompt: nil,
isEssentialProperty: false
)
Expand All @@ -72,11 +75,13 @@ struct MyPageEdit {
init(_ userInfo: UserInfoResponse) {
self.userInfo = userInfo
_selectedBottomSheetItem = .init(nil)
let initialSelectedGenderItem = Gender.getGenderByKey(userInfo.gender)
_genderSectionProperty = .init(
.init(
titleText: "성별",
items: .default,
isCustomItem: nil,
initialSelectedID: initialSelectedGenderItem?.id,
customTextFieldPrompt: nil,
isEssentialProperty: false
)
Expand Down Expand Up @@ -174,7 +179,9 @@ struct MyPageEdit {
SSToastReducer()
}

Reduce { state, action in
Reduce {
state,
action in
switch action {
case let .view(currentAction):
return viewAction(&state, currentAction)
Expand Down Expand Up @@ -206,7 +213,7 @@ struct MyPageEdit {
let currentGenderID = Gender.getGenderByKey(genderString)?.id

state.nameTextFieldText = state.userInfo.name
state.genderSection = .init(singleSelectButtonHelper: state.$genderSectionProperty, initialSelectedID: currentGenderID)
state.genderSection = .init(singleSelectButtonHelper: state.$genderSectionProperty)
return .none

case .async(.updateUserInformation):
Expand Down Expand Up @@ -267,3 +274,5 @@ struct SelectYearBottomSheetItem: SSSelectBottomSheetPropertyItemable {
/// BottomSheet에 표시될 연도 입니다.
var id: Int
}

private extension UserInfoResponse {}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ struct LedgerDetailEdit: FeatureViewAction, FeatureAsyncAction, FeatureInnerActi
self.ledgerProperty = ledgerProperty
_editProperty = .init(ledgerDetailEditProperty)
categorySection = .init(
singleSelectButtonHelper: _editProperty.categoryEditProperty,
initialSelectedID: ledgerProperty.categoryID
singleSelectButtonHelper: _editProperty.categoryEditProperty
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct LedgerDetailEditProperty: Equatable {
titleText: "카테고리",
items: category,
isCustomItem: currentCustomItem,
initialSelectedID: ledgerDetailProperty.categoryID,
customTextFieldPrompt: "경조사 이름",
isEssentialProperty: true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct LedgerDetailRouter {
func handleEnvelopeDetailDelegateAction(state _: inout State, action: SpecificEnvelopeDetailReducer.Action.DelegateAction) -> Effect<Action> {
switch action {
case let .tappedEnvelopeEditButton(property):
return .ssRun { [id = property.id] _ in
return .ssRun { [id = property.envelope.id] _ in
let editState = try await SpecificEnvelopeEditReducer.State(envelopeID: id, isShowCategory: false)
LedgerDetailRouterPublisher.send(.envelopeEdit(editState))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public struct SingleSelectButtonProperty<Item: SingleSelectButtonItemable>: Equa
public var customTextFieldPrompt: String?
public var isSaved: Bool = false
public var isEssentialProperty = true
public let initialSelectedCustomTitle: String?
public let initialSelectedID: Item.ID?

public var allItems: [Item] {
return (items + [isCustomItem]).compactMap { $0 }
Expand All @@ -30,10 +32,19 @@ public struct SingleSelectButtonProperty<Item: SingleSelectButtonItemable>: Equa
return selectedItem?.id == isCustomItem?.id
}

public init(titleText: String, items: [Item], isCustomItem: Item?, customTextFieldPrompt: String?, isEssentialProperty: Bool = true) {
public init(
titleText: String,
items: [Item],
isCustomItem: Item?,
initialSelectedID: Item.ID?,
customTextFieldPrompt: String?,
isEssentialProperty: Bool = true
) {
self.titleText = titleText
self.items = items
self.isCustomItem = isCustomItem
initialSelectedCustomTitle = isCustomItem?.title
self.initialSelectedID = initialSelectedID
self.customTextFieldPrompt = customTextFieldPrompt
self.isEssentialProperty = isEssentialProperty
}
Expand Down Expand Up @@ -75,6 +86,7 @@ public struct SingleSelectButtonProperty<Item: SingleSelectButtonItemable>: Equa
}

public mutating func resetCustomTextField() {
selectedItem = nil
isCustomItem?.title = ""
isSaved = false
isStartedAddingNewCustomItem = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public struct SingleSelectButtonReducer<Item: SingleSelectButtonItemable> {
@Shared var singleSelectButtonHelper: SingleSelectButtonProperty<Item>
var customTextFieldText: String

public init(singleSelectButtonHelper: Shared<SingleSelectButtonProperty<Item>>, initialSelectedID: Item.ID?) {
public init(singleSelectButtonHelper: Shared<SingleSelectButtonProperty<Item>>) {
_singleSelectButtonHelper = singleSelectButtonHelper
customTextFieldText = ""
self.initialSelectedID = initialSelectedID

initialSelectedID = singleSelectButtonHelper.wrappedValue.initialSelectedID
setCustomTextField()
}

Expand Down
65 changes: 19 additions & 46 deletions Projects/Feature/SSEnvelope/Sources/Network/EnvelopeNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct EnvelopeNetwork {
var getEnvelopeDetailPropertyByEnvelopeID: @Sendable (_ id: Int64) async throws -> EnvelopeDetailProperty
@Sendable static func _getEnvelopeDetailPropertyByEnvelopeID(_ id: Int64) async throws -> EnvelopeDetailProperty {
let data: EnvelopeDetailResponse = try await provider.request(.searchEnvelopeByID(id))
return data.convertToEnvelopeDetailLProperty()
return data
}

var deleteEnvelope: @Sendable (_ id: Int64) async throws -> Void
Expand All @@ -37,21 +37,15 @@ struct EnvelopeNetwork {
let relations = responseRelations.sorted { $0.id < $1.id }

let envelopeDetailResponse: EnvelopeDetailResponse = try await provider.request(.searchEnvelopeByID(envelopeID))
let envelopeProperty = envelopeDetailResponse.convertToEnvelopeDetailLProperty()

guard var customCategoryItem = events.first(where: { $0.isCustom }),
var customRelationItem = relations.first(where: { $0.isCustom })
else {
throw NSError(domain: "", code: 3)
}
let customCategoryItem = events.first(where: { $0.isCustom }) ?? .editCustomDefault
let customRelationItem = relations.first(where: { $0.isCustom }) ?? .editCustomDefault

let targetCategoryItems = events.filter { $0.isCustom == false }
let targetRelationItems = relations.filter { $0.isCustom == false }

customCategoryItem.title = envelopeDetailResponse.category.customCategory ?? ""
customRelationItem.title = envelopeDetailResponse.friendRelationship.customRelation ?? ""

return .init(
envelopeDetailProperty: envelopeProperty,
envelopeDetailProperty: envelopeDetailResponse,
eventItems: targetCategoryItems,
customEventItem: customCategoryItem,
relationItems: targetRelationItems,
Expand All @@ -70,21 +64,11 @@ struct EnvelopeNetwork {
// TODO: 작업하기
let dto: CreateAndUpdateEnvelopeResponse = try await provider.request(.editEnvelopes(id: id, body))
return .init(
id: dto.envelope.id,
type: dto.envelope.type,
ledgerID: nil,
price: dto.envelope.amount,
eventName: dto.category.customCategory ?? dto.category.category,
eventID: dto.category.id,
friendID: dto.friend.id,
name: dto.friend.name,
relation: dto.friendRelationship.customRelation ?? dto.relationship.relation,
relationID: dto.relationship.id,
date: CustomDateFormatter.getDate(from: dto.envelope.handedOverAt) ?? .now,
isVisited: dto.envelope.hasVisited,
gift: dto.envelope.gift,
contacts: dto.friend.phoneNumber,
memo: dto.envelope.memo
envelope: dto.envelope,
category: dto.category,
relationship: dto.relationship,
friendRelationship: dto.friendRelationship,
friend: dto.friend
)
}

Expand Down Expand Up @@ -194,25 +178,14 @@ private extension Date {
}
}

private extension EnvelopeDetailResponse {
func convertToEnvelopeDetailLProperty() -> EnvelopeDetailProperty {
let data = self
return .init(
id: data.envelope.id,
type: data.envelope.type,
ledgerID: nil,
price: data.envelope.amount,
eventName: data.category.customCategory ?? data.category.category,
eventID: data.category.id,
friendID: data.friend.id,
name: data.friend.name,
relation: data.friendRelationship.customRelation != nil ? data.friendRelationship.customRelation! : data.relationship.relation,
relationID: data.relationship.id,
date: .getDate(from: data.envelope.handedOverAt) ?? .now,
isVisited: data.envelope.hasVisited,
gift: data.envelope.gift,
contacts: data.friend.phoneNumber,
memo: data.envelope.memo
)
private extension CreateEnvelopeEventProperty {
static var editCustomDefault: Self {
.init(id: 2048, seq: 2048, name: "", style: "blue60", isActive: true, isCustom: true, isMiscCategory: true)
}
}

extension CreateEnvelopeRelationItemProperty {
static var editCustomDefault: Self {
.init(id: 2048, relation: "", description: "", isCustom: true)
}
}
Loading

0 comments on commit 45885aa

Please sign in to comment.