-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feature] WeeklyStudy API 구현 및 연동
- Loading branch information
Showing
28 changed files
with
538 additions
and
116 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
HongikYeolgong2/Data/DTO/StudySession/WeeklyStudySessionDTO.swift
This file contains 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,13 @@ | ||
// | ||
// WeelyStudyResonseDTO.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/24/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct WeeklyStudySessionDTO: Decodable { | ||
let date: String | ||
let studyCount: Int | ||
} |
This file contains 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
24 changes: 24 additions & 0 deletions
24
HongikYeolgong2/Data/Repositories/StudySession/StudySessionRepositoryImpl.swift
This file contains 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,24 @@ | ||
// | ||
// WeeklyStudyRepositoryImpl.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/24/24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
final class StudySessionRepositoryImpl: StudySessionRepository { | ||
func getWeeklyStudyRecords() -> AnyPublisher<[WeeklyStudySessionDTO], NetworkError> { | ||
return Future<[WeeklyStudySessionDTO], NetworkError> { promise in | ||
Task { | ||
do { | ||
let response: BaseResponse<[WeeklyStudySessionDTO]> = try await NetworkService.shared.request(endpoint: WeeklyEndpoint.getWeeklyStudy) | ||
promise(.success(response.data)) | ||
} catch let error as NetworkError { | ||
promise(.failure(error)) | ||
} | ||
} | ||
}.eraseToAnyPublisher() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
HongikYeolgong2/Domain/Entities/WeeklyStudy/WeeklyStudyRecord.swift
This file contains 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,30 @@ | ||
// | ||
// WeeklyStudyRecord.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/25/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct WeeklyStudyRecord { | ||
let monthOfDay: String | ||
let dayOfWeek: String | ||
let studyCount: Int | ||
let isUpcomming: Bool | ||
|
||
var imageName: String { | ||
switch studyCount { | ||
case 0: | ||
"shineCount00" | ||
case 1: | ||
"shineCount01" | ||
case 2: | ||
"shineCount02" | ||
case 3: | ||
"shineCount03" | ||
default: | ||
"shineCount00" | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
HongikYeolgong2/Domain/Interactors/StudySessionInteractor.swift
This file contains 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,33 @@ | ||
// | ||
// WeeklyStudyInteractor.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/24/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
protocol StudySessionInteractor { | ||
func getWeekyStudy(studyRecords: Binding<[WeeklyStudyRecord]>) | ||
} | ||
|
||
final class StudySessionInteractorImpl: StudySessionInteractor { | ||
private let cancleBag = CancelBag() | ||
private let studySessionRepository: StudySessionRepository | ||
|
||
init(studySessionRepository: StudySessionRepository) { | ||
self.studySessionRepository = studySessionRepository | ||
} | ||
|
||
/// 한 주에 대한 공부 횟수를 가져옵니다. | ||
/// - Parameter studyRecords: 공부 기록(월 - 일) | ||
func getWeekyStudy(studyRecords: Binding<[WeeklyStudyRecord]>) { | ||
studySessionRepository | ||
.getWeeklyStudyRecords() | ||
.receive(on: DispatchQueue.main) | ||
.sink(receiveCompletion: { _ in }) { | ||
studyRecords.wrappedValue = $0.map { $0.toEntity() } | ||
} | ||
.store(in: cancleBag) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
HongikYeolgong2/Domain/Interfaces/StudySessionRepository.swift
This file contains 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,13 @@ | ||
// | ||
// WeeklyStudyRepository.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/24/24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
protocol StudySessionRepository { | ||
func getWeeklyStudyRecords() -> AnyPublisher<[WeeklyStudySessionDTO], NetworkError> | ||
} |
This file contains 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,18 @@ | ||
// | ||
// StudySessionMapper.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/24/24. | ||
// | ||
|
||
import Foundation | ||
|
||
// StudySession에 대한 Mapper | ||
extension WeeklyStudySessionDTO { | ||
func toEntity() -> WeeklyStudyRecord { | ||
.init(monthOfDay: date.toMonthOfDay(), | ||
dayOfWeek: date.toDayOfWeek(), | ||
studyCount: studyCount, | ||
isUpcomming: date.toDate() ?? .now <= .now) | ||
} | ||
} |
This file contains 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 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 was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.