Skip to content

Commit

Permalink
Merge pull request #52 from TeamHY2/Feature/#41-WiseSaying
Browse files Browse the repository at this point in the history
[Feature] 명언 API 구현 및 인터랙터 분리
  • Loading branch information
Seokki-Kwon authored Oct 28, 2024
2 parents 257bb22 + a94a5db commit 8b411ac
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 33 deletions.
8 changes: 8 additions & 0 deletions HongikYeolgong2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
47D5EDCD2CCBCB6D00ACA469 /* ImageBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47D5EDCC2CCBCB6D00ACA469 /* ImageBackground.swift */; };
47D5EDCF2CCBD10300ACA469 /* ActionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47D5EDCE2CCBD10300ACA469 /* ActionButton.swift */; };
47DF041F2CBE7A29007E58A7 /* Encodable+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DF041E2CBE7A29007E58A7 /* Encodable+.swift */; };
47E250712CCF274400267897 /* WeeklyStudyInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47E250702CCF274400267897 /* WeeklyStudyInteractor.swift */; };
47E250732CCF2BED00267897 /* WiseSaying.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47E250722CCF2BED00267897 /* WiseSaying.swift */; };
47F4F6972CC88FBB00543D24 /* SignUpRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F4F6962CC88FBB00543D24 /* SignUpRequestDTO.swift */; };
47F4F6992CC89A6900543D24 /* SignUpResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F4F6982CC89A6900543D24 /* SignUpResponseDTO.swift */; };
47F634FE2CC3E8A40034EAA9 /* NicknameCheckDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F634FD2CC3E8A40034EAA9 /* NicknameCheckDTO.swift */; };
Expand Down Expand Up @@ -220,6 +222,8 @@
47D5EDCC2CCBCB6D00ACA469 /* ImageBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageBackground.swift; sourceTree = "<group>"; };
47D5EDCE2CCBD10300ACA469 /* ActionButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionButton.swift; sourceTree = "<group>"; };
47DF041E2CBE7A29007E58A7 /* Encodable+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Encodable+.swift"; sourceTree = "<group>"; };
47E250702CCF274400267897 /* WeeklyStudyInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeeklyStudyInteractor.swift; sourceTree = "<group>"; };
47E250722CCF2BED00267897 /* WiseSaying.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WiseSaying.swift; sourceTree = "<group>"; };
47F4F6962CC88FBB00543D24 /* SignUpRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpRequestDTO.swift; sourceTree = "<group>"; };
47F4F6982CC89A6900543D24 /* SignUpResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpResponseDTO.swift; sourceTree = "<group>"; };
47F634FD2CC3E8A40034EAA9 /* NicknameCheckDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameCheckDTO.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -367,6 +371,7 @@
isa = PBXGroup;
children = (
4780044F2CCABEFF00FFAF00 /* WeeklyStudyRecord.swift */,
47E250722CCF2BED00267897 /* WiseSaying.swift */,
);
path = WeeklyStudy;
sourceTree = "<group>";
Expand Down Expand Up @@ -520,6 +525,7 @@
4763FFB92CB913FF00990336 /* UserDataInteractor.swift */,
4786A1042CCA3352008635A4 /* StudySessionInteractor.swift */,
4786A0EB2CC9E2BC008635A4 /* UserPermissionsInteractor.swift */,
47E250702CCF274400267897 /* WeeklyStudyInteractor.swift */,
);
path = Interactors;
sourceTree = "<group>";
Expand Down Expand Up @@ -940,6 +946,7 @@
4752A27D2CB96EB00073B784 /* CancleBag.swift in Sources */,
4736719F2CB120A600527896 /* WeeklyStudyView.swift in Sources */,
4780044C2CCAAD4F00FFAF00 /* WeekDay.swift in Sources */,
47E250732CCF2BED00267897 /* WiseSaying.swift in Sources */,
47A1477E2CA159E300A91F66 /* SplashView.swift in Sources */,
475B86E32CA1AF40000534B2 /* SettingView.swift in Sources */,
470723052CBC180D0046469F /* NetworkError.swift in Sources */,
Expand All @@ -958,6 +965,7 @@
47F635022CC3E98D0034EAA9 /* UserEndpoint.swift in Sources */,
478933792CADBDA500E1D89E /* SignUpView.swift in Sources */,
4763FFB52CB90EBD00990336 /* InitialView.swift in Sources */,
47E250712CCF274400267897 /* WeeklyStudyInteractor.swift in Sources */,
470723092CBC198E0046469F /* AuthRepository.swift in Sources */,
47F4F6972CC88FBB00543D24 /* SignUpRequestDTO.swift in Sources */,
478004422CCA924200FFAF00 /* StudySessionMapper.swift in Sources */,
Expand Down
6 changes: 5 additions & 1 deletion HongikYeolgong2/Core/AppEnviroment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ extension AppEnviroment {
UIApplication.shared.open(url)
}
}
)
),
weeklyStudyInteractor: WeeklyStudyInteractorImpl(
appState: appState,
studySessionRepository: remoteRepository.studySessionRepository
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ final class StudySessionRepositoryImpl: StudySessionRepository {
}
}.eraseToAnyPublisher()
}

func getWiseSaying() -> AnyPublisher<WiseSaying, NetworkError> {
return Future<WiseSaying, NetworkError> { promise in
Task {
do {
let response: BaseResponse<WiseSaying> = try await NetworkService.shared.request(endpoint: WeeklyEndpoint.getWiseSaying)
promise(.success(response.data))
} catch let error as NetworkError {
print(error.message)
promise(.failure(error))
}
}
}.eraseToAnyPublisher()
}
}
23 changes: 23 additions & 0 deletions HongikYeolgong2/Domain/Entities/WeeklyStudy/WiseSaying.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// WiseSaying.swift
// HongikYeolgong2
//
// Created by 권석기 on 10/28/24.
//

import Foundation

struct WiseSaying: Decodable {
var quote: String
let author: String

init(quote: String, author: String) {
self.quote = quote
self.author = author
}

init() {
self.quote = "행동보다 빠르게 불안감을 \n 없앨 수 있는 것은 없습니다."
self.author = "윌터 앤더슨"
}
}
15 changes: 1 addition & 14 deletions HongikYeolgong2/Domain/Interactors/StudySessionInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import SwiftUI
import Combine

protocol StudySessionInteractor {
func getWeekyStudy(studyRecords: Binding<[WeeklyStudyRecord]>)
protocol StudySessionInteractor {
func startStudy()
func endStudy()
func addTime()
Expand All @@ -29,18 +28,6 @@ final class StudySessionInteractorImpl: StudySessionInteractor {
self.appState = appState
self.studySessionRepository = studySessionRepository
}

/// 한 주에 대한 공부 횟수를 가져옵니다.
/// - Parameter studyRecords: 공부 기록(월 - 일)
func getWeekyStudy(studyRecords: Binding<[WeeklyStudyRecord]>) {
studySessionRepository
.getWeeklyStudyRecords()
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { _ in }) {
studyRecords.wrappedValue = $0
}
.store(in: cancleBag)
}

/// 스터디세션을 시작합니다.
func startStudy() {
Expand Down
45 changes: 45 additions & 0 deletions HongikYeolgong2/Domain/Interactors/WeeklyStudyInteractor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// WeeklyStudyInteractor.swift
// HongikYeolgong2
//
// Created by 권석기 on 10/28/24.
//

import SwiftUI

protocol WeeklyStudyInteractor {
func getWeekyStudy(studyRecords: Binding<[WeeklyStudyRecord]>)
func getWiseSaying(wiseSaying: Binding<WiseSaying>)
}

final class WeeklyStudyInteractorImpl: WeeklyStudyInteractor {
private let appState: Store<AppState>
private let cancleBag = CancelBag()
private let studySessionRepository: StudySessionRepository

init(appState: Store<AppState>,
studySessionRepository: StudySessionRepository) {
self.appState = appState
self.studySessionRepository = studySessionRepository
}

func getWeekyStudy(studyRecords: Binding<[WeeklyStudyRecord]>) {
studySessionRepository
.getWeeklyStudyRecords()
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { _ in }) {
studyRecords.wrappedValue = $0
}
.store(in: cancleBag)
}

func getWiseSaying(wiseSaying: Binding<WiseSaying>) {
studySessionRepository
.getWiseSaying()
.sink { _ in
} receiveValue: {
wiseSaying.wrappedValue = $0
}
.store(in: cancleBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import Combine
protocol StudySessionRepository {
func getWeeklyStudyRecords() -> AnyPublisher<[WeeklyStudyRecord], NetworkError>
func uploadStudyRecord(startTime: Date, endTime: Date) -> AnyPublisher<StudySessionResponseDTO, NetworkError>
func getWiseSaying() -> AnyPublisher<WiseSaying, NetworkError>
}
10 changes: 7 additions & 3 deletions HongikYeolgong2/Injected/InteractorsContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ extension DIContainer {
struct Interactors {
let userDataInteractor: UserDataInteractor
let studySessionInteractor: StudySessionInteractor
let userPermissionsInteractor: UserPermissionsInteractor
let userPermissionsInteractor: UserPermissionsInteractor
let weeklyStudyInteractor: WeeklyStudyInteractor

init(userDataInteractor: UserDataInteractor,
studySessionInteractor: StudySessionInteractor,
userPermissionsInteractor: UserPermissionsInteractor) {
userPermissionsInteractor: UserPermissionsInteractor,
weeklyStudyInteractor: WeeklyStudyInteractor) {

self.userDataInteractor = userDataInteractor
self.studySessionInteractor = studySessionInteractor
self.userPermissionsInteractor = userPermissionsInteractor
self.weeklyStudyInteractor = weeklyStudyInteractor
}

static let `default` = Self(
Expand All @@ -29,7 +32,8 @@ extension DIContainer {
authService: AuthenticationServiceImpl()
),
studySessionInteractor: StudySessionInteractorImpl(appState: Store<AppState>(AppState()), studySessionRepository: StudySessionRepositoryImpl()),
userPermissionsInteractor: RealUserPermissionsInteractor(appState: Store<AppState>(AppState()), openAppSetting: {})
userPermissionsInteractor: RealUserPermissionsInteractor(appState: Store<AppState>(AppState()), openAppSetting: {}),
weeklyStudyInteractor: WeeklyStudyInteractorImpl(appState: Store<AppState>(AppState()), studySessionRepository: StudySessionRepositoryImpl())
)
}
}
Expand Down
21 changes: 14 additions & 7 deletions HongikYeolgong2/Presentation/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ struct HomeView: View {
@Environment(\.injected.appState) var appState
@Environment(\.injected.interactors.userPermissionsInteractor) var permissions
@Environment(\.injected.interactors.studySessionInteractor) var studySessionInteractor
@Environment(\.injected.interactors.weeklyStudyInteractor) var weeklyStudyInteractor

@State private var studyRecords = [WeeklyStudyRecord]()
@State private var studySession = AppState.StudySession()
@State private var wiseSaying = WiseSaying()
@State private var shouldShowTimePicker = false
@State private var shouldShowAddTimeModal = false
@State private var shouldShowEndUseModal = false
Expand All @@ -24,7 +26,10 @@ struct HomeView: View {
VStack {
WeeklyStudyView(studyRecords: studyRecords)

StudyContentControllerView(studySession: $studySession)
StudyContentControllerView(
studySession: $studySession,
wiseSaying: wiseSaying
)

Spacer()

Expand All @@ -48,7 +53,7 @@ struct HomeView: View {
studySessionInteractor.startStudy()
shouldShowTimePicker = false
}
)
)
}
.systemOverlay(isPresented: $shouldShowAddTimeModal) {
ModalView(title: "열람실 이용 시간을 연장할까요?",
Expand All @@ -58,7 +63,7 @@ struct HomeView: View {
studySessionInteractor.addTime()
shouldShowAddTimeModal = false
},
cancleAction: { shouldShowAddTimeModal = false })
cancleAction: { shouldShowAddTimeModal = false })
}
.systemOverlay(isPresented: $shouldShowEndUseModal) {
ModalView(title: "열람실을 다 이용하셨나요?",
Expand All @@ -68,15 +73,16 @@ struct HomeView: View {
studySessionInteractor.endStudy()
shouldShowEndUseModal = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
studySessionInteractor.getWeekyStudy(studyRecords: $studyRecords)
weeklyStudyInteractor.getWeekyStudy(studyRecords: $studyRecords)
}
},
cancleAction: { shouldShowEndUseModal = false })
cancleAction: { shouldShowEndUseModal = false })
}
.padding(.horizontal, 32.adjustToScreenWidth)
.modifier(GradientBackground())
.onAppear { permissions.request(permission: .localNotifications) }
.onAppear { studySessionInteractor.getWeekyStudy(studyRecords: $studyRecords) }
.onAppear { weeklyStudyInteractor.getWeekyStudy(studyRecords: $studyRecords) }
.onAppear { weeklyStudyInteractor.getWiseSaying(wiseSaying: $wiseSaying) }
.onReceive(studySessionUpdated) { studySession = $0 }
}
}
Expand All @@ -91,6 +97,7 @@ extension HomeView {
// MARK: - StudyContentControllerView
struct StudyContentControllerView: View {
@Binding var studySession: AppState.StudySession
let wiseSaying: WiseSaying

var body: some View {
Group {
Expand All @@ -108,7 +115,7 @@ struct StudyContentControllerView: View {
}
.padding(.top, 36.adjustToScreenHeight)
} else {
TodayWiseSaying()
TodayWiseSaying(wiseSaying: wiseSaying)
.padding(.top, 120.adjustToScreenHeight)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
import SwiftUI

struct TodayWiseSaying: View {
let wiseSaying: WiseSaying

var body: some View {
VStack(spacing: 12) {
Text("행동보다 빠르게 불안감을 \n 없앨 수 있는 것은 없습니다.")
Text(wiseSaying.quote)
.font(.pretendard(size: 18, weight: .regular), lineHeight: 28)
.foregroundColor(.gray100)
.multilineTextAlignment(.center)

Text("-윌터 앤더슨")
Text("-\(wiseSaying.author)")
.font(.pretendard(size: 12, weight: .regular), lineHeight: 18)
.foregroundColor(.gray200)
.multilineTextAlignment(.center)
}
}
}

#Preview {
TodayWiseSaying()
}
//#Preview {
// TodayWiseSaying()
//}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions HongikYeolgong2/Util/API/Endpoints/WeeklyEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum WeeklyEndpoint: EndpointProtocol {
/// 이번주 열람실 이용횟수
case getWeeklyStudy
case uploadStudySession(StudySessionRequestDTO)
case getWiseSaying
}

extension WeeklyEndpoint {
Expand All @@ -23,14 +24,16 @@ extension WeeklyEndpoint {
switch self {
case .getWeeklyStudy:
"/study/week"
case .getWiseSaying:
"/wise-saying"
default:
"/study"
}
}

var method: NetworkMethod {
switch self {
case .getWeeklyStudy:
case .getWeeklyStudy, .getWiseSaying:
.get
case .uploadStudySession:
.post
Expand All @@ -53,10 +56,10 @@ extension WeeklyEndpoint {

var body: Data? {
switch self {
case .getWeeklyStudy:
return nil
case let .uploadStudySession(studySessionReqDto):
return studySessionReqDto.toData()
default:
return nil
}
}
}

0 comments on commit 8b411ac

Please sign in to comment.