Skip to content

Commit

Permalink
Merge pull request #383 from School-of-Company/380-input-company-feature
Browse files Browse the repository at this point in the history
🔀 :: [#380] 기업 등록 페이지
  • Loading branch information
uuuunseo authored Jul 23, 2024
2 parents 5657a50 + 6151539 commit f19a284
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 50 deletions.
2 changes: 1 addition & 1 deletion App/Sources/Application/BitgouelApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI

@main
struct BitgouelApp: App {
@StateObject private var sceneState = SceneState(sceneFlow: .main)
@StateObject private var sceneState = SceneState(sceneFlow: .login)
@StateObject private var adminPageState = AdminPageState(adminPageFlow: .user)

init() {
Expand Down
4 changes: 4 additions & 0 deletions App/Sources/Application/DI/AppComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,8 @@ public extension AppComponent {
var governmentListFactory: any GovernmentListFactory {
GovernmentListComponent(parent: self)
}

var inputCompanyFactory: any InputCompanyFactory {
InputCompanyComponent(parent: self)
}
}
24 changes: 24 additions & 0 deletions App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ private class SignUpDependencyf83ac0c64026320e6dc2Provider: SignUpDependency {
private func factory306e8ce5cfdf41304709f47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return SignUpDependencyf83ac0c64026320e6dc2Provider(appComponent: parent1(component) as! AppComponent)
}
private class InputCompanyDependencyc9d68514782dbceb6f25Provider: InputCompanyDependency {
var createdCompanyUseCase: any CreatedCompanyUseCase {
return appComponent.createdCompanyUseCase
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
}
}
/// ^->AppComponent->InputCompanyComponent
private func factoryb7c98d723f97530cea08f47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return InputCompanyDependencyc9d68514782dbceb6f25Provider(appComponent: parent1(component) as! AppComponent)
}
private class ActivityDetailSettingDependency0b98c5f90168b920a8b8Provider: ActivityDetailSettingDependency {


Expand Down Expand Up @@ -531,6 +544,9 @@ private class CompanyListDependencyc27b560afc0e29f1887dProvider: CompanyListDepe
var deleteCompanyUseCase: any DeleteCompanyUseCase {
return appComponent.deleteCompanyUseCase
}
var inputCompanyFactory: any InputCompanyFactory {
return appComponent.inputCompanyFactory
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
Expand Down Expand Up @@ -971,6 +987,11 @@ extension SignUpComponent: Registration {
keyPathToName[\SignUpDependency.successSignUpFactory] = "successSignUpFactory-any SuccessSignUpFactory"
}
}
extension InputCompanyComponent: Registration {
public func registerItems() {
keyPathToName[\InputCompanyDependency.createdCompanyUseCase] = "createdCompanyUseCase-any CreatedCompanyUseCase"
}
}
extension ActivityDetailSettingComponent: Registration {
public func registerItems() {

Expand Down Expand Up @@ -1109,6 +1130,7 @@ extension CompanyListComponent: Registration {
public func registerItems() {
keyPathToName[\CompanyListDependency.fetchCompanyListUseCase] = "fetchCompanyListUseCase-any FetchCompanyListUseCase"
keyPathToName[\CompanyListDependency.deleteCompanyUseCase] = "deleteCompanyUseCase-any DeleteCompanyUseCase"
keyPathToName[\CompanyListDependency.inputCompanyFactory] = "inputCompanyFactory-any InputCompanyFactory"
}
}
extension FindPasswordComponent: Registration {
Expand Down Expand Up @@ -1389,6 +1411,7 @@ extension AppComponent: Registration {
localTable["companyListFactory-any CompanyListFactory"] = { [unowned self] in self.companyListFactory as Any }
localTable["universityListFactory-any UniversityListFactory"] = { [unowned self] in self.universityListFactory as Any }
localTable["governmentListFactory-any GovernmentListFactory"] = { [unowned self] in self.governmentListFactory as Any }
localTable["inputCompanyFactory-any InputCompanyFactory"] = { [unowned self] in self.inputCompanyFactory as Any }
localTable["remoteWithdrawDataSource-any RemoteWithdrawDataSource"] = { [unowned self] in self.remoteWithdrawDataSource as Any }
localTable["withdrawRepository-any WithdrawRepository"] = { [unowned self] in self.withdrawRepository as Any }
localTable["fetchWithdrawUserListUseCase-any FetchWithdrawUserListUseCase"] = { [unowned self] in self.fetchWithdrawUserListUseCase as Any }
Expand Down Expand Up @@ -1438,6 +1461,7 @@ private func registerProviderFactory(_ componentPath: String, _ factory: @escapi
registerProviderFactory("^->AppComponent->LectureListDetailComponent", factory22af859a70aa8ba0b346f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->NoticeListComponent", factorye14e687c08985bdffcd0f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->SignUpComponent", factory306e8ce5cfdf41304709f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->InputCompanyComponent", factoryb7c98d723f97530cea08f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->ActivityDetailSettingComponent", factoryfd595280dea209e217b9e3b0c44298fc1c149afb)
registerProviderFactory("^->AppComponent->MainTabComponent", factory1ab5a747ddf21e1393f9f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->NoticeDetailSettingComponent", factory24d19202afbef2333be9e3b0c44298fc1c149afb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import Service

public struct FieldBottomSheet: View {
let fieldList: [FieldType] = FieldType.allCases
let selectedField: FieldType
let selectedField: FieldType?
@State var keyword: String = ""
let selecteField: (FieldType) -> Void

public var body: some View {
VStack(alignment: .leading, spacing: 8) {
SearchTextField(text: $keyword)

ScrollView {
LazyVStack(alignment: .leading) {
ForEach(fieldList, id: \.self) { field in
fieldRow(
field: field.display(),
isSelected: Binding(
get: { selectedField == field },
set: { _ in selecteField(field) }
)
ScrollView {
LazyVStack(alignment: .leading) {
ForEach(fieldList, id: \.self) { field in
fieldRow(
field: field.display(),
isSelected: Binding(
get: { selectedField == field },
set: { _ in selecteField(field) }
)
}
)
.onTapGesture { selecteField(field) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Service
public struct InputDataView: View {
let epic: String
let state: String
@Binding var selectedField: FieldType
@Binding var selectedField: FieldType?
@Binding var name: String
@State var isShowingFieldBottomSheet: Bool = false
let finalButtonAction: () -> Void

public init(
epic: String,
state: String,
selectedField: Binding<FieldType>,
selectedField: Binding<FieldType?>,
name: Binding<String>,
isShowingFieldBottomSheet: Bool = false,
finalButtonAction: @escaping () -> Void
Expand All @@ -24,41 +24,41 @@ public struct InputDataView: View {
self.isShowingFieldBottomSheet = isShowingFieldBottomSheet
self.finalButtonAction = finalButtonAction
}

public var body: some View {
NavigationView {
VStack(alignment: .leading) {
VStack(spacing: 16) {
BitgouelTextField(
"\(epic) 이름 입력",
text: $name
)

PickerTextField(
"분야 선택",
text: selectedField.display()
) {
isShowingFieldBottomSheet = true
}
VStack(alignment: .leading) {
VStack(spacing: 0) {
BitgouelTextField(
"\(epic) 이름 입력",
text: $name
)

PickerTextField(
"분야 선택",
text: selectedField?.display() ?? ""
) {
isShowingFieldBottomSheet = true
}

Spacer()
}
.overlay(alignment: .bottom) {
finalButton()
}
.padding(.horizontal, 28)
.navigationTitle("\(epic) \(state)")
.bitgouelBottomSheet(isShowing: $isShowingFieldBottomSheet) {
FieldBottomSheet(
selectedField: selectedField
) { field in
selectedField = field
}
.padding(.top, 32)

Spacer()
}
.navigationTitle("\(epic) \(state)")
.overlay(alignment: .bottom) {
finalButton()
}
.padding(.horizontal, 28)
.bitgouelBottomSheet(isShowing: $isShowingFieldBottomSheet) {
FieldBottomSheet(
selectedField: selectedField
) { field in
selectedField = field
isShowingFieldBottomSheet = false
}
}
}

@ViewBuilder
func finalButton() -> some View {
if state == "수정" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Service
public protocol CompanyListDependency: Dependency {
var fetchCompanyListUseCase: any FetchCompanyListUseCase { get }
var deleteCompanyUseCase: any DeleteCompanyUseCase { get }
var inputCompanyFactory: any InputCompanyFactory { get }
}

public final class CompanyListComponent: Component<CompanyListDependency>, CompanyListFactory {
Expand All @@ -13,7 +14,8 @@ public final class CompanyListComponent: Component<CompanyListDependency>, Compa
viewModel: .init(
fetchCompanyListUseCase: dependency.fetchCompanyListUseCase,
deleteCompanyUseCase: dependency.deleteCompanyUseCase
)
),
inputCompanyFactory: dependency.inputCompanyFactory
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ struct CompanyListView: View {
@EnvironmentObject var adminPageState: AdminPageState
@StateObject var viewModel: CompanyListViewModel

init(viewModel: CompanyListViewModel) {
private let inputCompanyFactory: any InputCompanyFactory

init(
viewModel: CompanyListViewModel,
inputCompanyFactory: any InputCompanyFactory
) {
_viewModel = StateObject(wrappedValue: viewModel)
self.inputCompanyFactory = inputCompanyFactory
}

var body: some View {
Expand Down Expand Up @@ -89,5 +95,14 @@ struct CompanyListView: View {
text: viewModel.errorMessage,
isShowing: $viewModel.isErrorOccurred
)
.navigate(
to: inputCompanyFactory.makeView().eraseToAnyView(),
when: Binding(
get: { viewModel.isPresentedInputCompanyPage },
set: { isPresented in
viewModel.updateIsPresentedInputCompanyPage(isPresented: isPresented)
}
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import SwiftUI

public protocol InputCompanyFactory {
associatedtype SomeView: View
func makeView() -> SomeView
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import NeedleFoundation
import SwiftUI
import Service

public protocol InputCompanyDependency: Dependency {
var createdCompanyUseCase: any CreatedCompanyUseCase { get }
}

public final class InputCompanyComponent: Component<InputCompanyDependency>, InputCompanyFactory {
public func makeView() -> some View {
InputCompanyView(
viewModel: .init(
createdCompanyUseCase: dependency.createdCompanyUseCase
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import SwiftUI

struct InputCompanyView: View {
@StateObject var viewModel: InputCompanyViewModel
@Environment(\.dismiss) var dismiss

init(viewModel: InputCompanyViewModel) {
_viewModel = StateObject(wrappedValue: viewModel)
}

var body: some View {
VStack(spacing: 0) {
InputDataView(
epic: "기업",
state: "등록",
selectedField: $viewModel.selectedFieldType,
name: $viewModel.companyName
) {
viewModel.createCompany {
dismiss()
}
}
}
.bitgouelToast(
text: viewModel.errorMessage,
isShowing: $viewModel.isErrorOccurred
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Foundation
import Service

final class InputCompanyViewModel: BaseViewModel {
@Published var selectedFieldType: FieldType?
@Published var companyName: String = ""

private let createdCompanyUseCase: any CreatedCompanyUseCase

init(createdCompanyUseCase: any CreatedCompanyUseCase) {
self.createdCompanyUseCase = createdCompanyUseCase
}

@MainActor
func createCompany(_ success: @escaping () -> Void) {
guard let field = selectedFieldType else { return }

Task {
do {
try await createdCompanyUseCase(
req: CreatedCompanyRequestDTO(
companyName: companyName,
field: field
)
)

success()
} catch {
errorMessage = error.companyDomainErrorMessage()
isErrorOccurred = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct PickerTextField: View {

Spacer()
}
.padding(.vertical, 16)
}
}
.background(backgroundColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ import Foundation
public struct CreatedCompanyRequestDTO: Encodable {
public let companyName: String
public let field: FieldType

public init(
companyName: String,
field: FieldType
) {
self.companyName = companyName
self.field = field
}
}

0 comments on commit f19a284

Please sign in to comment.