-
Notifications
You must be signed in to change notification settings - Fork 0
[#13] weekly 회고 리팩토링 #15
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
Open
aado97
wants to merge
4
commits into
main
Choose a base branch
from
13-weekly-회고-리팩토링
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "13-weekly-\uD68C\uACE0-\uB9AC\uD329\uD1A0\uB9C1"
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
dominjun/Weekly01_회고시스템/Weekly01_회고시스템/Helper/DateHelper.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // | ||
| // DateHelper.swift | ||
| // Weekly01_회고시스템 | ||
| // | ||
| // Created by 도민준 on 2/11/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| class DateHelper { | ||
| // 싱글톤 | ||
| static let shared = DateHelper() | ||
|
|
||
| private let dateFormats = [ | ||
| "yyyy-MM-dd", // 2025-04-12 | ||
| "yyMMdd", // 250412 | ||
| "yyyy년 M월 d일" // 2025년 4월 12일 | ||
| ] | ||
|
|
||
| private var formatters: [DateFormatter] = [] | ||
|
|
||
| private init() { | ||
| formatters = dateFormats.map { format in | ||
| let formatter = DateFormatter() | ||
| formatter.dateFormat = format | ||
| formatter.locale = Locale(identifier: "ko_KR") | ||
| formatter.timeZone = TimeZone(identifier: "Asia/Seoul") | ||
| return formatter | ||
| } | ||
| } | ||
|
|
||
| func stringToDate(from input: String) -> Date? { | ||
| for formatter in formatters { | ||
| if let date = formatter.date(from: input) { | ||
| // 자정으로 설정하여 시간 정보 제거 | ||
| let calendar = Calendar.current | ||
| let normalizedDate = calendar.startOfDay(for: date) // 시간 제거 | ||
| print("변환된 날짜: \(normalizedDate)") // 디버깅용 출력 | ||
| return calendar.startOfDay(for: date) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
dominjun/Weekly01_회고시스템/Weekly01_회고시스템/Model/Reflection.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // | ||
| // Reflection.swift | ||
| // Weekly01_회고시스템 | ||
| // | ||
| // Created by 도민준 on 2/10/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct Reflection { | ||
| let date: Date | ||
| var content: String | ||
|
|
||
| // 날짜를 문자열 형태로 변환 (시간 정보 제거) | ||
| var dateString: String { | ||
| let formatter = DateFormatter() | ||
| formatter.locale = Locale(identifier: "ko_KR") | ||
| formatter.dateFormat = "yyyy-MM-dd" | ||
| formatter.timeZone = TimeZone(identifier: "Asia/Seoul") // 한국 시간으로 변환 | ||
| formatter.timeStyle = .none | ||
| return formatter.string(from: date) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // main.swift | ||
| // Weekly01_회고시스템 | ||
| // | ||
| // Created by 도민준 on 1/26/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| var reflectionManager = ReflectionViewModel() | ||
| var menuNum = 0 | ||
| var date = "" | ||
| var content = "" | ||
|
|
||
| reflectionManager.printMenu() | ||
|
|
||
| while true { | ||
| print("메뉴를 선택하세요:", terminator: " ") | ||
|
|
||
| menuNum = Int(readLine() ?? "0") ?? 0 | ||
|
|
||
| if menuNum == 6 { | ||
| print("프로그램을 종료합니다.") | ||
| break | ||
| } | ||
|
|
||
| switch menuNum { | ||
| case 1: | ||
| print("날짜를 입력하세요 (예: 2024-12-25):", terminator: " ") | ||
| date = readLine() ?? "" | ||
| reflectionManager.addReflection(dateString: date) | ||
|
|
||
| case 2: | ||
| print("조회할 날짜를 입력하세요:", terminator: " ") | ||
| date = readLine() ?? "" | ||
| reflectionManager.retrieveReflection(dateString: date) | ||
| case 3: | ||
| print("수정할 날짜를 입력하세요:", terminator: " ") | ||
| date = readLine() ?? "" | ||
| reflectionManager.updateReflection(dateString: date) | ||
| case 4: | ||
| print("삭제할 날짜를 입력하세요:", terminator: " ") | ||
| date = readLine() ?? "" | ||
| reflectionManager.deleteReflection(dateString: date) | ||
|
|
||
| case 5: | ||
| reflectionManager.printAllReflection() | ||
| default: | ||
| print("잘못된 입력입니다.\n") | ||
| } | ||
| } | ||
|
|
||
99 changes: 99 additions & 0 deletions
99
dominjun/Weekly01_회고시스템/Weekly01_회고시스템/ViewModel/ReflectionViewModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // | ||
| // ReflectionViewModel.swift | ||
| // Weekly01_회고시스템 | ||
| // | ||
| // Created by 도민준 on 2/10/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| class ReflectionViewModel { | ||
| //날짜를 키 값으로 정하기 위해 | ||
| //private 메서드를 통해서만 접근 가능하게 하여 데이터 무결성 유지 | ||
| private var reflections: [Date: Reflection] = [:] | ||
|
|
||
| // 메뉴 출력 | ||
| func printMenu() { | ||
| print(""" | ||
| === 회고 시스템 === | ||
| 1. 회고 추가 | ||
| 2. 회고 조회 | ||
| 3. 회고 수정 | ||
| 4. 회고 삭제 | ||
| 5. 전체 회고 목록 출력 | ||
| 6. 종료\n | ||
| """) | ||
| } | ||
|
|
||
| // 회고 추가 | ||
| func addReflection(dateString: String) { | ||
| guard let date = DateHelper.shared.stringToDate(from: dateString) else { | ||
| print("잘못된 날짜 형식입니다.\n") | ||
| return | ||
| } | ||
|
|
||
| let normalizedDate = Calendar.current.startOfDay(for: date) // 시간 제거 | ||
| print("조회 변환된 날짜: \(normalizedDate)") // 디버깅용 출력 | ||
|
|
||
| print("회고 내용을 입력하세요:", terminator: " ") | ||
| let content = readLine() ?? "" | ||
|
|
||
| reflections[date] = Reflection(date: date, content: content) | ||
| print("회고가 추가 되었습니다.\n") | ||
| } | ||
|
|
||
| // 회고 조회 | ||
| func retrieveReflection(dateString: String) { | ||
| guard let date = DateHelper.shared.stringToDate(from: dateString) else { | ||
| print("잘못된 날짜 형식입니다.\n") | ||
| return | ||
| } | ||
|
|
||
| if let reflection = reflections[date] { | ||
| print("날짜: \(reflection.dateString)") | ||
| print("내용: \(reflection.content)\n") | ||
| } else { | ||
| print("해당 날짜의 회고가 없습니다.\n") | ||
| } | ||
| } | ||
|
|
||
| // 회고 수정 | ||
| func updateReflection(dateString: String) { | ||
| guard let date = DateHelper.shared.stringToDate(from: dateString) else { | ||
| print("잘못된 날짜 형식입니다.\n") | ||
| return | ||
| } | ||
|
|
||
| if reflections[date] != nil { | ||
| print("새로운 회고 내용을 입력하세요: ", terminator: " ") | ||
| let newContent = readLine() ?? "" | ||
| reflections[date]?.content = newContent | ||
| print("회고가 수정되었습니다.\n") | ||
| } else { | ||
| print("해당 날짜의 회고가 없습니다.\n") | ||
| } | ||
| } | ||
|
|
||
| // 회고 삭제 | ||
| func deleteReflection(dateString: String) { | ||
| guard let date = DateHelper.shared.stringToDate(from: dateString) else { | ||
| print("잘못된 날짜 형식입니다.\n") | ||
| return | ||
| } | ||
|
|
||
| if reflections.removeValue(forKey: date) != nil { | ||
| print("회고가 삭제되었습니다.\n") | ||
| } else { | ||
| print("해당 날짜의 회고가 없습니다.\n") | ||
| } | ||
| } | ||
|
|
||
| // 전체 회고 목록 출력 | ||
| func printAllReflection() { | ||
| print("=== 저장된 회고 목록 ===") | ||
| for reflection in reflections.values { | ||
| print("날짜: \(reflection.dateString)") | ||
| print("내용: \(reflection.content)") | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
입력받는 걸 함수화할 수도 있지 않을까요? print문으로 출력할 메세지만 파라미터로 받는다던가, 출력문을 미리 Enum으로 정의해둔다거나 등의 방법으로요!