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
4 changes: 2 additions & 2 deletions Dietto/Dietto.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = UUYBHY988H;
DEVELOPMENT_TEAM = 5664C7G97A;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Dietto/Info.plist;
Expand Down Expand Up @@ -301,7 +301,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = UUYBHY988H;
DEVELOPMENT_TEAM = 5664C7G97A;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Dietto/Info.plist;
Expand Down
29 changes: 15 additions & 14 deletions Dietto/Dietto/Apps/DIContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@ import Observation
final class DIContainer {
private let alanUsecase: AlanUsecase
private let pedometerUsecase: PedometerUsecase
private var interestsUsecase: InterestsUsecase
private var userStorageUsecase: UserStorageUsecase
private var weightHistoryUsecase: WeightHistoryUsecase
private let interestsUsecase: InterestsUsecase
private let userStorageUsecase: UserStorageUsecase
private let weightHistoryUsecase: WeightHistoryUsecase
private let ingredientUsecase: IngredientUsecase

init() {
self.alanUsecase = AlanUsecaseImpl(repository: NetworkRepositoryImpl())
self.pedometerUsecase = PedometerUsecaseImpl(pedometer: PedometerRepositoryImpl())

// self.interestsUsecase = InterestsUsecaseImpl(repository: StorageRepositoryImpl<InterestsDTO>())
// self.userStorageUsecase = UserStorageUsecaseImpl(storage: StorageRepositoryImpl<UserDTO>())
// self.weightHistoryUsecase = WeightHistoryUsecaseImpl(repository: StorageRepositoryImpl<WeightDTO>())

self.interestsUsecase = InterestsUsecaseImpl(repository: AnotherStorageRepositoryImpl<InterestsDTO>())
self.userStorageUsecase = UserStorageUsecaseImpl(storage: AnotherStorageRepositoryImpl<UserDTO>())
self.weightHistoryUsecase = WeightHistoryUsecaseImpl(repository: AnotherStorageRepositoryImpl<WeightDTO>())
self.ingredientUsecase = IngredientUsecaseImpl(repository: AnotherStorageRepositoryImpl<IngredientDTO>())

// Task.detached(priority: .background) { [weak self] in
// self?.interestsUsecase = InterestsUsecaseImpl(repository: AnotherStorageRepositoryImpl<InterestsDTO>())
// self?.userStorageUsecase = UserStorageUsecaseImpl(storage: AnotherStorageRepositoryImpl<UserDTO>())
// self?.weightHistoryUsecase = WeightHistoryUsecaseImpl(repository: AnotherStorageRepositoryImpl<WeightDTO>())
// }

// Task.detached(priority: .background) { [weak self] in
// self?.interestsUsecase = InterestsUsecaseImpl(repository: AnotherStorageRepositoryImpl<InterestsDTO>())
// self?.userStorageUsecase = UserStorageUsecaseImpl(storage: AnotherStorageRepositoryImpl<UserDTO>())
// self?.weightHistoryUsecase = WeightHistoryUsecaseImpl(repository: AnotherStorageRepositoryImpl<WeightDTO>())
// }

}

func getHomeViewModel() -> HomeViewModel {
Expand All @@ -51,7 +49,10 @@ final class DIContainer {
}

func getDietaryViewModel() -> DietaryViewModel {
DietaryViewModel(usecase: alanUsecase)
DietaryViewModel(
alanUsecase: alanUsecase,
ingredientUsecase: ingredientUsecase
)
}

func getOnboardingViewModel() -> OnboardingViewModel {
Expand Down
21 changes: 21 additions & 0 deletions Dietto/Dietto/Data/DTO/IngredientDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// IngredientDTO.swift
// Dietto
//
// Created by 안정흠 on 6/9/25.
//


import Foundation
import SwiftData

@Model
final class IngredientDTO {
var id: UUID
var ingredient: String

init(id: UUID, ingredient: String) {
self.id = id
self.ingredient = ingredient
}
}
2 changes: 1 addition & 1 deletion Dietto/Dietto/Data/Network/NetworkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension NetworkError {
return ToastEntity(
type: .error,
title: "오류 발생",
message: self.errorDescription ?? "알 수 없는 오류입니다.",
message: self.errorDescription ?? "알 수 없는 에러가 발생했습니다.",
duration: 3
)
}
Expand Down
7 changes: 6 additions & 1 deletion Dietto/Dietto/Domain/Entities/IngredientEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import Foundation

//MARK: - 식재료는 저장합니다.
struct IngredientEntity: Identifiable, Hashable {
let id = UUID()
let id: UUID
let ingredient: String

init(id: UUID = UUID(), ingredient: String) {
self.id = id
self.ingredient = ingredient
}
}
59 changes: 59 additions & 0 deletions Dietto/Dietto/Domain/Usecases/IngredientUsecase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// IngredientUsecase.swift
// Dietto
//
// Created by 안세훈 on 6/9/25.
//
import Foundation

//MARK: - Interface
protocol IngredientUsecase{
func insertIngredient(_ ingredient: IngredientEntity) async throws
func deleteIngredient(_ ingredient: IngredientEntity) async throws
func fetchIngredient() async throws -> [IngredientEntity]
}

//MARK: - Implement
final class IngredientUsecaseImpl<Repository: AnotherStorageRepository>: IngredientUsecase where Repository.T == IngredientDTO {
private let repository: Repository

init(repository: Repository) {
self.repository = repository
}

func insertIngredient(_ ingredient: IngredientEntity) async throws {
do {
try await repository.insertData(
data: IngredientDTO(id: ingredient.id, ingredient: ingredient.ingredient)
)
}
catch {
print(#function, error.localizedDescription)
throw StorageError.insertError
}
}

func deleteIngredient(_ ingredient: IngredientEntity) async throws {
let id = ingredient.id
let predicate = #Predicate<IngredientDTO> { $0.id == id }
do { try await repository.deleteData(where: predicate) }
catch {
print(#function, error.localizedDescription)
throw StorageError.deleteError
}
}

func fetchIngredient() async throws -> [IngredientEntity] {
do {
let result = try await repository.fetchData(where: nil, sort: [])
return result.map{ IngredientEntity(id: $0.id, ingredient: $0.ingredient) }
}
catch {
print(#function, error.localizedDescription)
throw StorageError.fetchError
}
}


}

2 changes: 1 addition & 1 deletion Dietto/Dietto/Presentation/Common/LogoProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct LogoProgressModifier: ViewModifier {
if isPresented {
Rectangle()
.fill(Color.black.opacity(0.3))
// .ignoresSafeArea()
.ignoresSafeArea()

LogoProgress(isAnimated: $isAnimated, message: message)
.onAppear {
Expand Down
39 changes: 18 additions & 21 deletions Dietto/Dietto/Presentation/Dietary/View/DietaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ struct DietaryView: View {
@State private var myRefrigerlatorflowlayout : CGFloat = 0 //마이냉장고
@State private var isFoldMyRefrigerlator : Bool = false //마이냉장고 펼쳤다 접었다.

@State private var PushToRecommandView : Bool = false // 화면이동

var body: some View {
NavigationStack{
ZStack{
Expand Down Expand Up @@ -136,16 +134,20 @@ struct DietaryView: View {

Spacer()

Button{
withAnimation(.bouncy) {
isFoldMyRefrigerlator.toggle()
if !dietartViewModel.pastIngredients.isEmpty{
Button{
withAnimation(.bouncy) {
isFoldMyRefrigerlator.toggle()
}
}label: {
Image(systemName: isFoldMyRefrigerlator ? "chevron.down" : "chevron.up")
.frame(width: 10, height: 10)
.font(.pretendardBold20)
}
}label: {
Image(systemName: isFoldMyRefrigerlator ? "chevron.down" : "chevron.up")
.frame(width: 10, height: 10)
.font(.pretendardBold20)
.foregroundStyle(.appMain)
.padding(.bottom, 8)
}
.padding(.bottom, 8)

}
}
.padding()
Expand All @@ -154,13 +156,8 @@ struct DietaryView: View {
}
HStack {
Button("식단 추천받기") {
print("식단 추천 받기 버튼이 클릭댐")
if !dietartViewModel.presentIngredients.isEmpty {
dietartViewModel.fetchRecommendations(ingredients: dietartViewModel.presentIngredients)
PushToRecommandView = true
}else{
print("비어있음 현재 식재료가 ")
}
dietartViewModel.fetchRecommendations(ingredients: dietartViewModel.presentIngredients)

}
.font(.pretendardBold16)
.foregroundStyle(.white)
Expand All @@ -174,13 +171,13 @@ struct DietaryView: View {

}
}
.navigationDestination(isPresented: $PushToRecommandView) {
.navigationDestination(isPresented: $dietartViewModel.pushToRecommend) {
RecommendView().environmentObject(dietartViewModel)
}
}
}
}

#Preview {
DietaryView(dietartViewModel: DietaryViewModel())
}
//#Preview {
// DietaryView(dietartViewModel: DietaryViewModel())
//}
25 changes: 4 additions & 21 deletions Dietto/Dietto/Presentation/Dietary/View/RecommendView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ struct RecommendView: View {
// @StateObject private var viewModel = DietaryViewModel() //디버깅용

@State private var isFoldRecommand : Bool = false // true : 펼친상태로 시작 , false: 가려진 채로 시작.
// @State private var contentHeight : CGFloat = 0
// @State private var contentHeight : CGFloat = 0

var body: some View {
ZStack {
Color(.backGround).ignoresSafeArea(edges: .all)

VStack {
ContainerView(paddingSize: 16) {
HStack {
VStack {
Text("추천 레시피에 등록된 재료를 이용해 식사를 추천합니다.")
.font(.pretendardSemiBold10)
.foregroundStyle(.textFieldGray)

ScrollView {
LazyVStack(alignment: .leading, spacing: 16) {
ForEach(viewModel.recommendList, id: \.title) { item in
Expand All @@ -46,36 +45,20 @@ struct RecommendView: View {
.padding(.horizontal)
}
.clipped()

// Spacer()
//
// Button {
// withAnimation(.bouncy) {
// isFoldRecommand.toggle()
// }
// } label: {
// Image(systemName: isFoldRecommand ? "chevron.up" : "chevron.down")
// .frame(width: 10, height: 10)
// .font(.pretendardBold20)
// }
// .padding(.bottom, 8)
// .border(.black)
}
}
.padding()
}
.padding(.bottom, 10)
}
.padding(.top, 16)


.opacity(viewModel.recommendList.isEmpty ? 0 : 1)
}
.navigationTitle("추천 식사")
.navigationBarTitleDisplayMode(.inline)
.font(.pretendardBold16)
.progressOverlay(isPresented: $viewModel.isPresneted, message: "Alan이 식단을 생성하고 있어요 !")
.toastView(toast: $viewModel.toast)

.progressOverlay(isPresented: $viewModel.isPresneted, message: "Alan이 식단을 생성하고 있어요 !")
}
}
////디버깅용
Expand Down
Loading