-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#129 경고문 구현 #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/#129 경고문 구현 #144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ enum HomeAPI { | |
| } | ||
|
|
||
| extension HomeAPI: EndPoint { | ||
|
|
||
| var basePath: String { | ||
| "/api" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // | ||
| // TreatmentInputWarning.swift | ||
| // Cherrish-iOS | ||
| // | ||
| // Created by 어재선 on 1/21/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| enum TreatmentInputWarning { | ||
| case none | ||
| case pastDate | ||
| case invalidFormat | ||
| case beforeProcedureDate | ||
|
|
||
| var message: String { | ||
| switch self { | ||
| case .none: | ||
| return "" | ||
| case .pastDate: | ||
| return "이미 지난 날짜는 입력할 수 없어요." | ||
| case .invalidFormat: | ||
| return "올바른 날짜 형식이 아니에요." | ||
| case .beforeProcedureDate: | ||
| return "목표일은 시술 날짜 이후로만 설정할 수 있어요." | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // TreatmentWarningMessgeView.swift | ||
| // Cherrish-iOS | ||
| // | ||
| // Created by 어재선 on 1/21/26. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| struct TreatmentWarningMessgeView: View { | ||
| let text: String | ||
| var body: some View { | ||
| HStack(spacing: 0) { | ||
| TypographyText(text, style: .body1_r_14, color: .red700) | ||
| .frame(height: 20.adjustedH) | ||
| Spacer() | ||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ final class NoTreatmentViewModel: ObservableObject{ | |
| @Published var year: String = "" | ||
| @Published var month: String = "" | ||
| @Published var day: String = "" | ||
| @Published private(set) var warning: TreatmentInputWarning = .none | ||
|
|
||
| private let fetchCategoriesUseCase: FetchTreatmentCategoriesUseCase | ||
| private let fetchTreatmentsUseCase: FetchTreatmentsUseCase | ||
|
|
@@ -113,25 +114,42 @@ final class NoTreatmentViewModel: ObservableObject{ | |
|
|
||
| func isDateTextFieldNotEmpty() -> Bool { | ||
| guard !year.isEmpty, !month.isEmpty, !day.isEmpty else { | ||
| Task { @MainActor in | ||
| updateWarning(state: .none) | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| guard let yearInt = Int(year), yearInt >= 2020, | ||
| let monthInt = Int(month), (1...12).contains(monthInt), | ||
| let dayInt = Int(day), (1...31).contains(dayInt) else { | ||
| guard let y = Int(year), let m = Int(month), let d = Int(day) else { | ||
| updateWarning(state: .invalidFormat) | ||
| return false | ||
| } | ||
|
|
||
| let components = DateComponents(year: yearInt, month: monthInt, day: dayInt) | ||
| let components = DateComponents(year: y, month: m, day: d) | ||
|
|
||
| guard let date = Calendar.current.date(from: components), | ||
| Calendar.current.dateComponents([.year, .month, .day], from: date) == components else { | ||
| updateWarning(state: .invalidFormat) | ||
| return false | ||
| } | ||
|
Comment on lines
+123
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "NoTreatmentViewModel.swift" | head -5Repository: TEAM-Cherrish/Cherrish-iOS Length of output: 186 🏁 Script executed: fd "NoTreatmentViewModel.swift" --type fRepository: TEAM-Cherrish/Cherrish-iOS Length of output: 184 🏁 Script executed: wc -l Cherrish-iOS/Cherrish-iOS/Presentation/Feature/Calendar/Treatment/ViewModel/NoTreatment/NoTreatmentViewModel.swiftRepository: TEAM-Cherrish/Cherrish-iOS Length of output: 188 🏁 Script executed: sed -n '120,140p' Cherrish-iOS/Cherrish-iOS/Presentation/Feature/Calendar/Treatment/ViewModel/NoTreatment/NoTreatmentViewModel.swift | cat -nRepository: TEAM-Cherrish/Cherrish-iOS Length of output: 936 🌐 Web query:
💡 Result: Short answer
Why this happens (brief)
What to do (recommended)
Sources
현재 코드의 제안된 수정안처럼 날짜 생성과 필드 추출을 분리하고 연/월/일 필드를 직접 비교하세요. 🛠️ 제안 수정안- let components = DateComponents(year: y, month: m, day: d)
- guard let date = Calendar.current.date(from: components),
- Calendar.current.dateComponents([.year, .month, .day], from: date) == components else {
- updateWarning(state: .invalidFormat)
- return false
- }
+ let calendar = Calendar.current
+ let components = DateComponents(year: y, month: m, day: d)
+ guard let date = calendar.date(from: components) else {
+ updateWarning(state: .invalidFormat)
+ return false
+ }
+ let normalized = calendar.dateComponents([.year, .month, .day], from: date)
+ guard normalized.year == y, normalized.month == m, normalized.day == d else {
+ updateWarning(state: .invalidFormat)
+ return false
+ }🤖 Prompt for AI Agents |
||
|
|
||
| let today = Calendar.current.startOfDay(for: Date()) | ||
| if date < today { | ||
| updateWarning(state: .pastDate) | ||
| return false | ||
| } | ||
|
|
||
| updateWarning(state: .none) | ||
| return true | ||
| } | ||
|
|
||
|
|
||
| private func updateWarning(state: TreatmentInputWarning) { | ||
| Task { @MainActor in | ||
| warning = state | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ final class TreatmentViewModel: ObservableObject{ | |||||||||||||||||||||||||||||||||||||
| @Published var month: String = "" | ||||||||||||||||||||||||||||||||||||||
| @Published var day: String = "" | ||||||||||||||||||||||||||||||||||||||
| @Published var searchText = "" | ||||||||||||||||||||||||||||||||||||||
| @Published private(set) var warning: TreatmentInputWarning = .none | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private let fetchTreatmentsUseCase: FetchTreatmentsUseCase | ||||||||||||||||||||||||||||||||||||||
| private let createUserProcedureUseCase: CreateUserProcedureUseCase | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,6 +59,8 @@ final class TreatmentViewModel: ObservableObject{ | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||||||
| func fetchTreatments() async throws { | ||||||||||||||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -98,24 +101,42 @@ final class TreatmentViewModel: ObservableObject{ | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func isDateTextFieldNotEmpty() -> Bool { | ||||||||||||||||||||||||||||||||||||||
| guard !year.isEmpty, !month.isEmpty, !day.isEmpty else { | ||||||||||||||||||||||||||||||||||||||
| Task { @MainActor in | ||||||||||||||||||||||||||||||||||||||
| updateWarning(state: .none) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| guard let yearInt = Int(year), yearInt >= 2020, | ||||||||||||||||||||||||||||||||||||||
| let monthInt = Int(month), (1...12).contains(monthInt), | ||||||||||||||||||||||||||||||||||||||
| let dayInt = Int(day), (1...31).contains(dayInt) else { | ||||||||||||||||||||||||||||||||||||||
| guard let y = Int(year), let m = Int(month), let d = Int(day) else { | ||||||||||||||||||||||||||||||||||||||
| updateWarning(state: .invalidFormat) | ||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| let components = DateComponents(year: yearInt, month: monthInt, day: dayInt) | ||||||||||||||||||||||||||||||||||||||
| let components = DateComponents(year: y, month: m, day: d) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| guard let date = Calendar.current.date(from: components), | ||||||||||||||||||||||||||||||||||||||
| Calendar.current.dateComponents([.year, .month, .day], from: date) == components else { | ||||||||||||||||||||||||||||||||||||||
| updateWarning(state: .invalidFormat) | ||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+115
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Short answer
What that means in practice
Recommended approaches
If you want, I can:
Citations:
🏁 Script executed: find . -name "TreatmentViewModel.swift" -type fRepository: TEAM-Cherrish/Cherrish-iOS Length of output: 182 🏁 Script executed: cat -n ./Cherrish-iOS/Cherrish-iOS/Presentation/Feature/Calendar/Treatment/ViewModel/Treatment/TreatmentViewModel.swift | sed -n '105,130p'Repository: TEAM-Cherrish/Cherrish-iOS Length of output: 1094 DateComponents 동등성 비교가 유효한 날짜를 invalid로 처리할 수 있습니다. 라인 115에서 생성한 🔧 제안 수정안- guard let date = Calendar.current.date(from: components),
- Calendar.current.dateComponents([.year, .month, .day], from: date) == components else {
+ guard let date = Calendar.current.date(from: components) else {
+ updateWarning(state: .invalidFormat)
+ return false
+ }
+ let validated = Calendar.current.dateComponents([.year, .month, .day], from: date)
+ guard validated.year == y, validated.month == m, validated.day == d else {
updateWarning(state: .invalidFormat)
return false
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| let today = Calendar.current.startOfDay(for: Date()) | ||||||||||||||||||||||||||||||||||||||
| if date < today { | ||||||||||||||||||||||||||||||||||||||
| updateWarning(state: .pastDate) | ||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| updateWarning(state: .none) | ||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private func updateWarning(state: TreatmentInputWarning) { | ||||||||||||||||||||||||||||||||||||||
| Task { @MainActor in | ||||||||||||||||||||||||||||||||||||||
| warning = state | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TEAM-Cherrish/Cherrish-iOS
Length of output: 600
🏁 Script executed:
Repository: TEAM-Cherrish/Cherrish-iOS
Length of output: 175
🏁 Script executed:
rg -l "TreatmentWarningMessgeView" --type swiftRepository: TEAM-Cherrish/Cherrish-iOS
Length of output: 272
🏁 Script executed:
rg "TreatmentWarningMessgeView" --type swiftRepository: TEAM-Cherrish/Cherrish-iOS
Length of output: 524
🏁 Script executed:
rg "body1_r_14" --type swift -A 2 -B 2Repository: TEAM-Cherrish/Cherrish-iOS
Length of output: 14796
파일명 및 타입명의 오타 수정이 필요합니다.
TreatmentWarningMessgeView는 오타입니다(Message → Messge). 파일명과 타입명 모두 정정이 필요하며,TargetDdaySettingView.swift의 사용처도 함께 수정해야 합니다.또한 고정 높이
20.adjustedH는 줄바꿈이나 큰 글꼴 표시 시 텍스트 잘림을 초래할 수 있습니다. 최소 높이로 변경하여 세로 확장을 허용하는 것이 안전합니다.🛠️ 제안 수정안
📝 Committable suggestion
🤖 Prompt for AI Agents