Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions SampoomManagement/App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct ContentView: View {
let dependencies: AppDependencies
@StateObject private var partViewModel: PartViewModel
@State private var selectedTab: Tabs = .dashboard
@State private var navigationPath = NavigationPath()

init(dependencies: AppDependencies) {
self.dependencies = dependencies
Expand Down Expand Up @@ -43,6 +44,7 @@ struct ContentView: View {
} label: {
Label {
Text(StringResources.Tabs.dashboard)
.font(.gmarketSubheadline)
} icon: {
Image("dashboard")
.renderingMode(.template)
Expand Down Expand Up @@ -70,6 +72,7 @@ struct ContentView: View {
} label: {
Label {
Text(StringResources.Tabs.delivery)
.font(.gmarketSubheadline)
} icon: {
Image("delivery")
.renderingMode(.template)
Expand Down Expand Up @@ -97,6 +100,7 @@ struct ContentView: View {
} label: {
Label {
Text(StringResources.Tabs.cart)
.font(.gmarketSubheadline)
} icon: {
Image("cart")
.renderingMode(.template)
Expand Down Expand Up @@ -124,6 +128,7 @@ struct ContentView: View {
} label: {
Label {
Text(StringResources.Tabs.orders)
.font(.gmarketSubheadline)
} icon: {
Image("orders")
.renderingMode(.template)
Expand All @@ -133,11 +138,27 @@ struct ContentView: View {

// PartView 탭
Tab(value: .parts, role: .search) {
PartView()
.environmentObject(partViewModel)
NavigationStack(path: $navigationPath) {
PartView(
onNavigatePartList: { group in
navigationPath.append(group.id)
},
viewModel: partViewModel
Comment thread
Sangyoon98 marked this conversation as resolved.
)
.navigationDestination(for: Int.self) { groupId in
PartListView(
viewModel: PartListViewModel(
getPartUseCase: dependencies.getPartUseCase,
groupId: groupId
)
)
}
}
.environmentObject(partViewModel)
} label: {
Label {
Text(StringResources.Tabs.parts)
.font(.gmarketSubheadline)
} icon: {
Image("parts")
.renderingMode(.template)
Expand Down
2 changes: 1 addition & 1 deletion SampoomManagement/App/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct RootView: View {

var body: some View {
Group {
if isAuthenticated {
if !isAuthenticated {
// 로그인 되어있으면 메인 화면
ContentView(dependencies: dependencies)
} else {
Comment thread
Sangyoon98 marked this conversation as resolved.
Expand Down
15 changes: 14 additions & 1 deletion SampoomManagement/Core/DI/AppDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AppDependencies {
// MARK: - Part
let partAPI: PartAPI
let partRepository: PartRepository
let getCategoryUseCase: GetCategoryUseCase
let getGroupUseCase: GetGroupUseCase
let getPartUseCase: GetPartUseCase

init() {
Expand All @@ -42,6 +44,8 @@ class AppDependencies {
// Part
partAPI = PartAPI(networkManager: networkManager)
partRepository = PartRepositoryImpl(api: partAPI)
getCategoryUseCase = GetCategoryUseCase(repository: partRepository)
getGroupUseCase = GetGroupUseCase(repository: partRepository)
getPartUseCase = GetPartUseCase(repository: partRepository)
}

Expand All @@ -56,7 +60,16 @@ class AppDependencies {
}

func makePartViewModel() -> PartViewModel {
return PartViewModel(getPartUseCase: getPartUseCase)
return PartViewModel(
getCategoryUseCase: getCategoryUseCase,
getGroupUseCase: getGroupUseCase
)
}

func makePartListViewModel(groupId: Int) -> PartListViewModel {
return PartListViewModel(
getPartUseCase: getPartUseCase, groupId: groupId
)
}
}

10 changes: 1 addition & 9 deletions SampoomManagement/Core/UI/Components/EmptyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

struct EmptyStateView: View {
struct EmptyView: View {
let icon: String
let title: String
let message: String?
Expand Down Expand Up @@ -46,11 +46,3 @@ struct EmptyStateView: View {
}
}
}

#Preview {
EmptyStateView(
icon: "tray",
title: "인벤토리가 비어있습니다",
message: "새로운 부품을 추가해보세요"
)
}
17 changes: 5 additions & 12 deletions SampoomManagement/Core/UI/Components/ErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,15 @@ struct ErrorView: View {
VStack(spacing: 16) {
Spacer()

Image(systemName: "exclamationmark.triangle")
.font(.system(size: 48))
.foregroundColor(.red)

Text("오류가 발생했습니다")
.font(.headline)
.font(.gmarketHeadline)
.foregroundColor(.red)

Text(error)
.font(.caption)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
.padding(.horizontal, 32)

Button("다시 시도") {
Button {
onRetry()
} label: {
Text("다시 시도")
.font(.gmarketCaption)
}
.buttonStyle(.borderedProminent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ extension LoginResponseDTO {
id: self.userId,
name: self.userName,
role: self.role,
accessToken: self.accessToken,
refreshToken: self.refreshToken,
expiresIn: self.expiresIn
)
}
Expand Down
4 changes: 1 addition & 3 deletions SampoomManagement/Features/Auth/Domain/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import Foundation

struct User: Identifiable, Codable, Equatable {
struct User: Equatable {
let id: Int
let name: String
let role: String
let accessToken: String
let refreshToken: String
let expiresIn: Int
}
26 changes: 24 additions & 2 deletions SampoomManagement/Features/Part/Data/Mappers/PartMappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@

import Foundation

extension CategoryDTO {
func toModel() -> Category {
return Category(
id: self.id,
code: self.code,
name: self.name
)
}
}

extension GroupDTO {
func toModel() -> PartsGroup {
return PartsGroup(
id: self.id,
code: self.code,
name: self.name,
categoryId: self.categoryId
)
}
}

extension PartDTO {
func toModel() -> Part {
return Part(
id: self.id,
id: self.partId,
code: self.code,
name: self.name,
count: self.count
quantity: self.quantity
)
}
}
40 changes: 38 additions & 2 deletions SampoomManagement/Features/Part/Data/Remote/API/PartAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,46 @@ class PartAPI {
self.networkManager = networkManager
}

func getPartList() async throws -> PartList {
func getCategoryList() async throws -> CategoryList {
return try await withCheckedThrowingContinuation { continuation in
networkManager.request(
endpoint: "part",
endpoint: "agency/category",
responseType: [CategoryDTO].self
) { result in
switch result {
case .success(let response):
let categories = response.data.map { $0.toModel() }
let categoryList = CategoryList(items: categories)
continuation.resume(returning: categoryList)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

func getGroupList(categoryId: Int) async throws -> PartsGroupList {
return try await withCheckedThrowingContinuation { continuation in
networkManager.request(
endpoint: "agency/category/\(categoryId)",
responseType: [GroupDTO].self
) { result in
switch result {
case .success(let response):
let groups = response.data.map { $0.toModel() }
let groupList = PartsGroupList(items: groups)
continuation.resume(returning: groupList)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

func getPartList(groupId: Int) async throws -> PartList {
return try await withCheckedThrowingContinuation { continuation in
networkManager.request(
endpoint: "agency/1/group/\(groupId)",
responseType: [PartDTO].self
) { result in
switch result {
Expand Down
14 changes: 14 additions & 0 deletions SampoomManagement/Features/Part/Data/Remote/DTO/CategoryDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// CategoryDTO.swift
// SampoomManagement
//
// Created by 채상윤 on 10/17/25.
//

import Foundation

struct CategoryDTO: Codable {
let id: Int
let code: String
let name: String
}
15 changes: 15 additions & 0 deletions SampoomManagement/Features/Part/Data/Remote/DTO/GroupDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// GroupDTO.swift
// SampoomManagement
//
// Created by 채상윤 on 10/17/25.
//

import Foundation

struct GroupDTO: Codable {
let id: Int
let code: String
let name: String
let categoryId: Int
}
5 changes: 3 additions & 2 deletions SampoomManagement/Features/Part/Data/Remote/DTO/PartDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation

struct PartDTO: Codable {
let id: Int
let partId: Int
let code: String
let name: String
let count: Int
let quantity: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ class PartRepositoryImpl: PartRepository {
self.api = api
}

func getPartList() async throws -> PartList {
return try await api.getPartList()
func getCategoryList() async throws -> CategoryList {
return try await api.getCategoryList()
}

func getGroupList(categoryId: Int) async throws -> PartsGroupList {
return try await api.getGroupList(categoryId: categoryId)
}

func getPartList(groupId: Int) async throws -> PartList {
return try await api.getPartList(groupId: groupId)
}
}
14 changes: 14 additions & 0 deletions SampoomManagement/Features/Part/Domain/Models/Category.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Category.swift
// SampoomManagement
//
// Created by 채상윤 on 10/17/25.
//

import Foundation

struct Category: Equatable {
let id: Int
let code: String
let name: String
}
22 changes: 22 additions & 0 deletions SampoomManagement/Features/Part/Domain/Models/CategoryList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CategoryList.swift
// SampoomManagement
//
// Created by 채상윤 on 10/17/25.
//

import Foundation

struct CategoryList: Equatable {
let items: [Category]
var totalCount: Int { items.count }
var isEmpty: Bool { items.isEmpty }

init(items: [Category]) {
self.items = items
}

static func empty() -> CategoryList {
return CategoryList(items: [])
}
}
5 changes: 3 additions & 2 deletions SampoomManagement/Features/Part/Domain/Models/Part.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import Foundation

struct Part: Identifiable, Codable, Equatable {
struct Part: Equatable {
let id: Int
let code: String
let name: String
let count: Int
let quantity: Int
}
3 changes: 1 addition & 2 deletions SampoomManagement/Features/Part/Domain/Models/PartList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

struct PartList: Codable, Equatable {
struct PartList: Equatable {
let items: [Part]
var totalCount: Int { items.count }
var isEmpty: Bool { items.isEmpty }
Expand All @@ -20,4 +20,3 @@ struct PartList: Codable, Equatable {
return PartList(items: [])
}
}

Loading