-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 인사이트 정적 페이지 구현 #76
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35dc74d
feat: insight 관련 파일 추가
enebin 0e961ed
feat: InsightViewModel 추가
enebin e427bb9
feat: 인사이트 섹션 뷰 추가
enebin 500746f
feat: InsightViewController 리팩토링 및 DI 등록
enebin 7ebde5b
fix: InsightKeywordsView height constraint 크래시 수정
enebin 5423f34
fix: 인사이트 에러 처리 개선 및 에러 알럿 추가
enebin 713d85b
fix: 리뷰반영
enebin 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
Some comments aren't visible on the classic Files Changed page.
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
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
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,122 @@ | ||
| // | ||
| // InsightResponseDTO.swift | ||
| // Data | ||
| // | ||
|
|
||
| import Domain | ||
| import Foundation | ||
|
|
||
| struct InsightResponseDTO: Decodable { | ||
| let month: String | ||
| let photoStats: PhotoStatsDTO | ||
| let categoryStats: CategoryStatsDTO | ||
| let topMenu: TopMenuDTO | ||
| let diaryTimeStats: DiaryTimeStatsDTO | ||
| let keywords: [String] | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case month | ||
| case photoStats = "photo_stats" | ||
| case categoryStats = "category_stats" | ||
| case topMenu = "top_menu" | ||
| case diaryTimeStats = "diary_time_stats" | ||
| case keywords | ||
| } | ||
|
|
||
| func toInsight() -> Insight { | ||
| Insight( | ||
| month: month, | ||
| photoStats: photoStats.toEntity(), | ||
| categoryStats: categoryStats.toEntity(), | ||
| topMenu: topMenu.toEntity(), | ||
| diaryTimeStats: diaryTimeStats.toEntity(), | ||
| keywords: keywords | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| struct PhotoStatsDTO: Decodable { | ||
| let currentMonthCount: Int | ||
| let previousMonthCount: Int | ||
| let changeRate: Double | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case currentMonthCount = "current_month_count" | ||
| case previousMonthCount = "previous_month_count" | ||
| case changeRate = "change_rate" | ||
| } | ||
|
|
||
| func toEntity() -> PhotoStats { | ||
| PhotoStats( | ||
| currentMonthCount: currentMonthCount, | ||
| previousMonthCount: previousMonthCount, | ||
| changeRate: changeRate | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| struct CategoryStatsDTO: Decodable { | ||
| let currentMonth: CategoryStatDTO | ||
| let previousMonth: CategoryStatDTO | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case currentMonth = "current_month" | ||
| case previousMonth = "previous_month" | ||
| } | ||
|
|
||
| func toEntity() -> CategoryStats { | ||
| CategoryStats( | ||
| currentMonth: currentMonth.toEntity(), | ||
| previousMonth: previousMonth.toEntity() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| struct CategoryStatDTO: Decodable { | ||
| let topCategory: String | ||
| let count: Int | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case topCategory = "top_category" | ||
| case count | ||
| } | ||
|
|
||
| func toEntity() -> CategoryStat { | ||
| CategoryStat(topCategory: topCategory, count: count) | ||
| } | ||
| } | ||
|
|
||
| struct TopMenuDTO: Decodable { | ||
| let name: String | ||
| let count: Int | ||
|
|
||
| func toEntity() -> TopMenu { | ||
| TopMenu(name: name, count: count) | ||
| } | ||
| } | ||
|
|
||
| struct DiaryTimeStatsDTO: Decodable { | ||
| let mostActiveHour: Int | ||
| let distribution: [HourCountDTO] | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case mostActiveHour = "most_active_hour" | ||
| case distribution | ||
| } | ||
|
|
||
| func toEntity() -> DiaryTimeStats { | ||
| DiaryTimeStats( | ||
| mostActiveHour: mostActiveHour, | ||
| distribution: distribution.map { $0.toEntity() } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| struct HourCountDTO: Decodable { | ||
| let hour: Int | ||
| let count: Int | ||
|
|
||
| func toEntity() -> HourCount { | ||
| HourCount(hour: hour, count: count) | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
FoodDiary/Data/Sources/Network/Endpoints/InsightEndpoint.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,55 @@ | ||
| // | ||
| // InsightEndpoint.swift | ||
| // Data | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public enum InsightEndpoint { | ||
| case fetch | ||
| } | ||
|
|
||
| extension InsightEndpoint: Requestable { | ||
| public var baseURL: String { | ||
| guard let url = Bundle.main.infoDictionary?["BASE_URL"] as? String else { | ||
| fatalError("BASE_URL이 Info.plist에 설정되지 않았습니다.") | ||
| } | ||
|
|
||
| return url | ||
| } | ||
|
|
||
| public var path: String { | ||
| switch self { | ||
| case .fetch: | ||
| "/me/insights" | ||
| } | ||
| } | ||
|
|
||
| public var httpMethod: HTTPMethod { | ||
| switch self { | ||
| case .fetch: | ||
| .get | ||
| } | ||
| } | ||
|
|
||
| public var queryParameters: Encodable? { | ||
| switch self { | ||
| case .fetch: | ||
| nil | ||
| } | ||
| } | ||
|
|
||
| public var bodyParameters: HTTPBody { | ||
| switch self { | ||
| case .fetch: | ||
| .none | ||
| } | ||
| } | ||
|
|
||
| public var headers: [String: String] { | ||
| switch self { | ||
| case .fetch: | ||
| [:] | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
FoodDiary/Data/Sources/Repository/InsightRepositoryImpl.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,29 @@ | ||
| // | ||
| // InsightRepositoryImpl.swift | ||
| // Data | ||
| // | ||
|
|
||
| import Domain | ||
| import Foundation | ||
|
|
||
| public struct InsightRepositoryImpl<Client: HTTPClienting, Storage: AuthTokenStoring>: InsightRepository { | ||
| private let httpClient: Client | ||
| private let tokenStorage: Storage | ||
|
|
||
| public init(httpClient: Client, tokenStorage: Storage) { | ||
| self.httpClient = httpClient | ||
| self.tokenStorage = tokenStorage | ||
| } | ||
|
|
||
| public func fetchInsight() async throws -> Insight { | ||
| do { | ||
| let response: InsightResponseDTO = try await httpClient.request( | ||
| InsightEndpoint.fetch, | ||
| accessToken: tokenStorage.get() | ||
| ) | ||
| return response.toInsight() | ||
| } catch NetworkError.httpError(statusCode: 400, _) { | ||
| throw InsightError.insufficientData | ||
| } | ||
| } | ||
| } |
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,10 @@ | ||
| // | ||
| // InsightError.swift | ||
| // Domain | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public enum InsightError: Error { | ||
| case insufficientData | ||
| } |
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,93 @@ | ||
| // | ||
| // Insight.swift | ||
| // Domain | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public struct Insight: Equatable, Sendable { | ||
| public let month: String | ||
| public let photoStats: PhotoStats | ||
| public let categoryStats: CategoryStats | ||
| public let topMenu: TopMenu | ||
| public let diaryTimeStats: DiaryTimeStats | ||
| public let keywords: [String] | ||
|
|
||
| public init( | ||
| month: String, | ||
| photoStats: PhotoStats, | ||
| categoryStats: CategoryStats, | ||
| topMenu: TopMenu, | ||
| diaryTimeStats: DiaryTimeStats, | ||
| keywords: [String] | ||
| ) { | ||
| self.month = month | ||
| self.photoStats = photoStats | ||
| self.categoryStats = categoryStats | ||
| self.topMenu = topMenu | ||
| self.diaryTimeStats = diaryTimeStats | ||
| self.keywords = keywords | ||
| } | ||
| } | ||
|
|
||
| public struct PhotoStats: Equatable, Sendable { | ||
| public let currentMonthCount: Int | ||
| public let previousMonthCount: Int | ||
| public let changeRate: Double | ||
|
|
||
| public init(currentMonthCount: Int, previousMonthCount: Int, changeRate: Double) { | ||
| self.currentMonthCount = currentMonthCount | ||
| self.previousMonthCount = previousMonthCount | ||
| self.changeRate = changeRate | ||
| } | ||
| } | ||
|
|
||
| public struct CategoryStats: Equatable, Sendable { | ||
| public let currentMonth: CategoryStat | ||
| public let previousMonth: CategoryStat | ||
|
|
||
| public init(currentMonth: CategoryStat, previousMonth: CategoryStat) { | ||
| self.currentMonth = currentMonth | ||
| self.previousMonth = previousMonth | ||
| } | ||
| } | ||
|
|
||
| public struct CategoryStat: Equatable, Sendable { | ||
| public let topCategory: String | ||
| public let count: Int | ||
|
|
||
| public init(topCategory: String, count: Int) { | ||
| self.topCategory = topCategory | ||
| self.count = count | ||
| } | ||
| } | ||
|
|
||
| public struct TopMenu: Equatable, Sendable { | ||
| public let name: String | ||
| public let count: Int | ||
|
|
||
| public init(name: String, count: Int) { | ||
| self.name = name | ||
| self.count = count | ||
| } | ||
| } | ||
|
|
||
| public struct DiaryTimeStats: Equatable, Sendable { | ||
| public let mostActiveHour: Int | ||
| public let distribution: [HourCount] | ||
|
|
||
| public init(mostActiveHour: Int, distribution: [HourCount]) { | ||
| self.mostActiveHour = mostActiveHour | ||
| self.distribution = distribution | ||
| } | ||
| } | ||
|
|
||
| public struct HourCount: Equatable, Sendable { | ||
| public let hour: Int | ||
| public let count: Int | ||
|
|
||
| public init(hour: Int, count: Int) { | ||
| self.hour = hour | ||
| self.count = count | ||
| } | ||
| } |
Oops, something went wrong.
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.
이번에 고도화하면서 VM을 직접 DI에 등록하는거에 대해서 고민을 좀 해봐야 할 듯??
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.
이거 맥락이 기억이 안나는데 VM을 머 따로 관리하기로 했었나..?
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.
ViewModel도
.transient로 해서 괜찮을 거 같긴 하네 큰 문제 생기진 않을 거 같으니까 직접 주입하는 방법으로 일단 가죠!