Skip to content

Commit

Permalink
[Pl-29] Entity 모듈 적용, 모델 프로퍼티 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
junyng committed Apr 16, 2023
1 parent 43fd31a commit a188266
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 97 deletions.
3 changes: 2 additions & 1 deletion AppPackage/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ let package = Package(
name: "TimeTableFeature",
dependencies: [
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "APIClient", package: "Planz-iOS-APIClient")
"APIClient",
"APIClientLive"
]
),
.target(
Expand Down
70 changes: 39 additions & 31 deletions AppPackage/Sources/Entity/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ public struct UpdateUsernameRequest: Encodable, Equatable {
public struct CreatePromisingRequest: Encodable, Equatable {
private enum CodingKeys: String, CodingKey {
case name = "promisingName"
case startDate = "minTime"
case endDate = "maxTime"
case minTime
case maxTime
case categoryID = "categoryId"
case availableDates
case place = "placeName"
}

public let name: String
public let startDate: Date
public let endDate: Date
public let minTime: String
public let maxTime: String
public let categoryID: Int
public let availableDates: [Date]
public let availableDates: [String]
public let place: String

public init(
name: String,
startDate: Date,
endDate: Date,
minTime: String,
maxTime: String,
categoryID: Int,
availableDates: [Date],
availableDates: [String],
place: String
) {
self.name = name
self.startDate = startDate
self.endDate = endDate
self.minTime = minTime
self.maxTime = maxTime
self.categoryID = categoryID
self.availableDates = availableDates
self.place = place
Expand All @@ -74,29 +74,21 @@ public struct CreatePromisingResponse: Decodable, Equatable {
}

public struct PromisingSessionResponse: Decodable, Equatable {
private enum CodingKeys: String, CodingKey {
case startDate = "minTime"
case endDate = "maxTime"
case totalCount
case unit
case availableDates
}

public let startDate: Date
public let endDate: Date
public let minTime: String
public let maxTime: String
public let totalCount: Int
public let unit: Int
public let availableDates: [Date]
public let unit: Double
public let availableDates: [String]

public init(
startDate: Date,
endDate: Date,
minTime: String,
maxTime: String,
totalCount: Int,
unit: Int,
availableDates: [Date]
unit: Double,
availableDates: [String]
) {
self.startDate = startDate
self.endDate = endDate
self.minTime = minTime
self.maxTime = maxTime
self.totalCount = totalCount
self.unit = unit
self.availableDates = availableDates
Expand Down Expand Up @@ -172,12 +164,28 @@ public struct PromisingSession: Codable, Equatable {
}

public struct PromisingTime: Codable, Equatable {
public let unit: Int
public let timeTable: TimeTable
public let unit: Double
public let timeTable: [TimeTable]

public struct TimeTable: Codable, Equatable {
public let date: Date
public let date: String
public let times: [Bool]

public init(
date: String,
times: [Bool]
) {
self.date = date
self.times = times
}
}

public init(
unit: Double,
timeTable: [TimeTable]
) {
self.unit = unit
self.timeTable = timeTable
}
}

Expand Down
40 changes: 8 additions & 32 deletions AppPackage/Sources/MakePromise/MakePromiseStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import APIClient
import CalendarFeature
import ComposableArchitecture
import Entity
import Foundation
import TimeTableFeature

Expand Down Expand Up @@ -104,7 +105,7 @@ public struct MakePromise: ReducerProtocol {
}
}

var timeTable: TimeTable.State? {
var timeTable: TimeTableFeature.TimeTable.State? {
get {
steps.compactMap { step in
guard case let .timeTable(state) = step else {
Expand Down Expand Up @@ -148,7 +149,7 @@ public struct MakePromise: ReducerProtocol {
case setNameAndPlace(SetNameAndPlace.State)
case calendar(CalendarCore.State)
case timeSelection(TimeSelection.State)
case timeTable(TimeTable.State)
case timeTable(TimeTableFeature.TimeTable.State)
}

var isNextButtonEnable: Bool {
Expand Down Expand Up @@ -209,13 +210,13 @@ public struct MakePromise: ReducerProtocol {
case dismiss
case nextButtonTapped
case backButtonTapped
case temporaryPromisingResponse(TaskResult<SharedModels.CreatePromisingResponse>)
case updatePromiseTimeRespose(TaskResult<SharedModels.UpdatePromiseTimeResponse>)
case temporaryPromisingResponse(TaskResult<CreatePromisingResponse>)
case updatePromiseTimeRespose(TaskResult<UpdatePromiseTimeResponse>)
case selectTheme(SelectTheme.Action)
case setNameAndPlace(SetNameAndPlace.Action)
case calendar(CalendarCore.Action)
case timeSelection(TimeSelection.Action)
case timeTable(TimeTable.Action)
case timeTable(TimeTableFeature.TimeTable.Action)
case alert(PresentationAction<AlertAction>)
}

Expand Down Expand Up @@ -268,7 +269,7 @@ public struct MakePromise: ReducerProtocol {
)
)
),
as: SharedModels.UpdatePromiseTimeResponse.self
as: UpdatePromiseTimeResponse.self
)
}
)
Expand Down Expand Up @@ -329,7 +330,7 @@ public struct MakePromise: ReducerProtocol {
)
)
),
as: SharedModels.CreatePromisingResponse.self
as: CreatePromisingResponse.self
)
}
)
Expand Down Expand Up @@ -376,31 +377,6 @@ private enum Resource {
}
}

extension SharedModels.CreatePromisingResponse: Equatable {
public static func == (lhs: SharedModels.CreatePromisingResponse, rhs: SharedModels.CreatePromisingResponse) -> Bool {
lhs.id == rhs.id
}
}

extension SharedModels.PromisingTime: Equatable {
public static func == (
lhs: SharedModels.PromisingTime,
rhs: SharedModels.PromisingTime
) -> Bool {
lhs.unit == rhs.unit
&& lhs.timeTable.count == rhs.timeTable.count
}
}

extension SharedModels.UpdatePromiseTimeResponse: Equatable {
public static func == (
lhs: SharedModels.UpdatePromiseTimeResponse,
rhs: SharedModels.UpdatePromiseTimeResponse
) -> Bool {
lhs.promiseID == rhs.promiseID
}
}

private var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
Expand Down
13 changes: 3 additions & 10 deletions AppPackage/Sources/MakePromise/SubViews/SelectThemeStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import APIClient
import APIClientLive
import ComposableArchitecture
import Entity
import Foundation
import SwiftUI

Expand All @@ -25,7 +26,7 @@ public struct SelectTheme: ReducerProtocol {

public enum Action: Equatable {
case task
case categoriesResponse(TaskResult<[SharedModels.Category]>)
case categoriesResponse(TaskResult<[Entity.Category]>)
case selectThemeItem(id: Int, action: SelectThemeItem.Action)
}

Expand All @@ -40,7 +41,7 @@ public struct SelectTheme: ReducerProtocol {
TaskResult {
try await apiClient.request(
route: .promising(.fetchCategories),
as: [SharedModels.Category].self
as: [Entity.Category].self
)
}
)
Expand Down Expand Up @@ -69,11 +70,3 @@ public struct SelectTheme: ReducerProtocol {
}
}
}

extension SharedModels.Category: Equatable {
public static func == (lhs: SharedModels.Category, rhs: SharedModels.Category) -> Bool {
lhs.id == rhs.id
&& lhs.keyword == rhs.keyword
&& lhs.type == rhs.type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import APIClient
import APIClientLive
import ComposableArchitecture
import Entity
import Foundation

public struct SetNameAndPlace: ReducerProtocol {
Expand Down Expand Up @@ -64,7 +65,7 @@ public struct SetNameAndPlace: ReducerProtocol {

public enum Action: Equatable {
case task
case placeHintResponse(TaskResult<SharedModels.CategoryName>)
case placeHintResponse(TaskResult<CategoryName>)
case filledPromiseName(String)
case filledPromisePlace(String)
}
Expand All @@ -80,7 +81,7 @@ public struct SetNameAndPlace: ReducerProtocol {
TaskResult {
try await apiClient.request(
route: .promising(.randomName(id)),
as: SharedModels.CategoryName.self
as: CategoryName.self
)
}
)
Expand All @@ -100,9 +101,3 @@ public struct SetNameAndPlace: ReducerProtocol {
}
}
}

extension SharedModels.CategoryName: Equatable {
public static func == (lhs: SharedModels.CategoryName, rhs: SharedModels.CategoryName) -> Bool {
lhs.name == rhs.name
}
}
18 changes: 3 additions & 15 deletions AppPackage/Sources/TimeTableFeature/TimeTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import APIClient
import APIClientLive
import ComposableArchitecture
import Entity
import SwiftUI

public struct TimeTable: ReducerProtocol {
Expand Down Expand Up @@ -98,7 +99,7 @@ public struct TimeTable: ReducerProtocol {

public enum Action: Equatable {
case task
case fetchSessionResponse(TaskResult<SharedModels.PromisingSessionResponse>)
case fetchSessionResponse(TaskResult<PromisingSessionResponse>)
case timeCellTapped(row: Int, column: Int)
}

Expand All @@ -116,7 +117,7 @@ public struct TimeTable: ReducerProtocol {
TaskResult {
try await apiClient.request(
route: .promising(.fetchSession(id)),
as: SharedModels.PromisingSessionResponse.self
as: PromisingSessionResponse.self
)
}
)
Expand Down Expand Up @@ -382,16 +383,3 @@ private var dateFormatter: DateFormatter = {
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
return dateFormatter
}()

extension SharedModels.PromisingSessionResponse: Equatable {
public static func == (
lhs: SharedModels.PromisingSessionResponse,
rhs: SharedModels.PromisingSessionResponse
) -> Bool {
lhs.minTime == rhs.minTime
&& lhs.maxTime == rhs.maxTime
&& lhs.totalCount == rhs.totalCount
&& lhs.unit == rhs.unit
&& lhs.availableDates == rhs.availableDates
}
}

0 comments on commit a188266

Please sign in to comment.