Skip to content

Commit

Permalink
Merge pull request #97 from TeamHY2/Feature/#95-ToggleSetting
Browse files Browse the repository at this point in the history
[Fix] SettingScreen 설정에 따라서 알림 on/off 기능을 추가합니다
  • Loading branch information
Seokki-Kwon authored Nov 14, 2024
2 parents 84479c2 + 10ca5f5 commit dc0285a
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 282 deletions.
20 changes: 18 additions & 2 deletions HongikYeolgong2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
4780044C2CCAAD4F00FFAF00 /* WeekDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780044B2CCAAD4F00FFAF00 /* WeekDay.swift */; };
4780044E2CCAAE3200FFAF00 /* String+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780044D2CCAAE3200FFAF00 /* String+.swift */; };
478004502CCABEFF00FFAF00 /* WeeklyStudyRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4780044F2CCABEFF00FFAF00 /* WeeklyStudyRecord.swift */; };
478589FE2CE4973B0027ED32 /* MenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 478589FD2CE4973B0027ED32 /* MenuItem.swift */; };
4786A0EC2CC9E2BC008635A4 /* UserPermissionsInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4786A0EB2CC9E2BC008635A4 /* UserPermissionsInteractor.swift */; };
4786A1052CCA3352008635A4 /* StudySessionInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4786A1042CCA3352008635A4 /* StudySessionInteractor.swift */; };
4786A1072CCA33DF008635A4 /* WeeklyEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4786A1062CCA33DF008635A4 /* WeeklyEndpoint.swift */; };
Expand Down Expand Up @@ -108,6 +109,7 @@
47B1D4C72C9CB1760071B62B /* HongikYeolgong2UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47B1D4C62C9CB1760071B62B /* HongikYeolgong2UITests.swift */; };
47B1D4C92C9CB1760071B62B /* HongikYeolgong2UITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47B1D4C82C9CB1760071B62B /* HongikYeolgong2UITestsLaunchTests.swift */; };
47BACCF72CA164BA00295DAC /* Font+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47BACCF62CA164BA00295DAC /* Font+.swift */; };
47BB5BE32CE52858002BBEE1 /* Page.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47BB5BE22CE52858002BBEE1 /* Page.swift */; };
47BE30E32CC813BB0015D973 /* KeyChainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47BE30E22CC813BB0015D973 /* KeyChainManager.swift */; };
47BE30E52CC81A9E0015D973 /* URLRequest+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47BE30E42CC81A9E0015D973 /* URLRequest+.swift */; };
47C815382CE21E640017EA24 /* ASAuthEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C815372CE21E640017EA24 /* ASAuthEndpoint.swift */; };
Expand Down Expand Up @@ -236,6 +238,7 @@
4780044B2CCAAD4F00FFAF00 /* WeekDay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekDay.swift; sourceTree = "<group>"; };
4780044D2CCAAE3200FFAF00 /* String+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+.swift"; sourceTree = "<group>"; };
4780044F2CCABEFF00FFAF00 /* WeeklyStudyRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeeklyStudyRecord.swift; sourceTree = "<group>"; };
478589FD2CE4973B0027ED32 /* MenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItem.swift; sourceTree = "<group>"; };
4786A0EB2CC9E2BC008635A4 /* UserPermissionsInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPermissionsInteractor.swift; sourceTree = "<group>"; };
4786A1042CCA3352008635A4 /* StudySessionInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudySessionInteractor.swift; sourceTree = "<group>"; };
4786A1062CCA33DF008635A4 /* WeeklyEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeeklyEndpoint.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -292,6 +295,7 @@
47B1D4C62C9CB1760071B62B /* HongikYeolgong2UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HongikYeolgong2UITests.swift; sourceTree = "<group>"; };
47B1D4C82C9CB1760071B62B /* HongikYeolgong2UITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HongikYeolgong2UITestsLaunchTests.swift; sourceTree = "<group>"; };
47BACCF62CA164BA00295DAC /* Font+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+.swift"; sourceTree = "<group>"; };
47BB5BE22CE52858002BBEE1 /* Page.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Page.swift; sourceTree = "<group>"; };
47BE30E22CC813BB0015D973 /* KeyChainManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyChainManager.swift; sourceTree = "<group>"; };
47BE30E42CC81A9E0015D973 /* URLRequest+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLRequest+.swift"; sourceTree = "<group>"; };
47C815372CE21E640017EA24 /* ASAuthEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASAuthEndpoint.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -526,6 +530,14 @@
path = Mapper;
sourceTree = "<group>";
};
478589FC2CE497100027ED32 /* Component */ = {
isa = PBXGroup;
children = (
478589FD2CE4973B0027ED32 /* MenuItem.swift */,
);
path = Component;
sourceTree = "<group>";
};
4786A10A2CCA3496008635A4 /* StudySession */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -676,6 +688,7 @@
47A147372CA1379A00A91F66 /* Setting */ = {
isa = PBXGroup;
children = (
478589FC2CE497100027ED32 /* Component */,
475B86E22CA1AF40000534B2 /* SettingView.swift */,
);
path = Setting;
Expand Down Expand Up @@ -984,6 +997,7 @@
4780044B2CCAAD4F00FFAF00 /* WeekDay.swift */,
47A540722CD0D90F00DC40D0 /* Nickname.swift */,
479BF66B2CDD1A8D009D9E44 /* StudyNotificationType.swift */,
47BB5BE22CE52858002BBEE1 /* Page.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -1231,6 +1245,7 @@
4707230F2CBC1A9C0046469F /* LoginRequestDTO.swift in Sources */,
478F84442CD350850097CAA1 /* WeeklyRankingResponseDTO.swift in Sources */,
473E8EBC2CCEBEF3000F102C /* ModalView.swift in Sources */,
47BB5BE32CE52858002BBEE1 /* Page.swift in Sources */,
473E8EB62CCE6A02000F102C /* Date+.swift in Sources */,
47C815412CE221060017EA24 /* SocialLoginRepositoryImpl.swift in Sources */,
470483A82CDB50FA00C381ED /* TokenEndpoint.swift in Sources */,
Expand Down Expand Up @@ -1292,6 +1307,7 @@
47F71B5D2CDC77C60044DEC5 /* UserDataInteractor+Migration.swift in Sources */,
4763FFB52CB90EBD00990336 /* InitialView.swift in Sources */,
47E250712CCF274400267897 /* WeeklyStudyInteractor.swift in Sources */,
478589FE2CE4973B0027ED32 /* MenuItem.swift in Sources */,
47C815462CE223DA0017EA24 /* ASTokenResponseDTO.swift in Sources */,
470723092CBC198E0046469F /* AuthRepository.swift in Sources */,
47F4F6972CC88FBB00543D24 /* SignUpRequestDTO.swift in Sources */,
Expand Down Expand Up @@ -1497,7 +1513,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_ASSET_PATHS = "\"HongikYeolgong2/Resources/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = P4D4ZQC4YF;
Expand Down Expand Up @@ -1544,7 +1560,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_ASSET_PATHS = "\"HongikYeolgong2/Resources/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = P4D4ZQC4YF;
Expand Down
4 changes: 3 additions & 1 deletion HongikYeolgong2/Core/AppEnviroment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ extension AppEnviroment {
userPermissionsInteractor: RealUserPermissionsInteractor(
appState: appState,
openAppSetting: {
if let url = URL(string: UIApplication.openNotificationSettingsURLString) {
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }

if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
Expand Down
17 changes: 7 additions & 10 deletions HongikYeolgong2/Data/Repositories/Auth/AuthRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ final class AuthRepositoryImpl: AuthRepository {
/// 소셜로그인
/// - Parameter loginReqDto: 로그인 요청 DTO(이메일, identityToken)
/// - Returns: 로그인 응답 DTO(accessToken, 가입여부)
func signIn(loginReqDto: LoginRequestDTO) -> AnyPublisher<LoginResponseDTO, NetworkError> {
return Future<LoginResponseDTO, NetworkError> { promise in
func signIn(loginReqDto: LoginRequestDTO) -> AnyPublisher<LoginResponseDTO, NetworkError> {
return Future<LoginResponseDTO, NetworkError> { promise in
Task {
do {
let response: BaseResponse<LoginResponseDTO> = try await NetworkService.shared.request(endpoint: AuthEndpoint.login(loginReqDto: loginReqDto))
promise(.success(response.data))
} catch let error as NetworkError {
} catch let error as NetworkError {
promise(.failure(error))
}
}
Expand Down Expand Up @@ -50,8 +50,8 @@ final class AuthRepositoryImpl: AuthRepository {
Task {
do {
let response: BaseResponse<SignUpResponseDTO> = try await NetworkService.shared.request(endpoint: UserEndpoint.signUp(signUpReqDto: signUpReqDto))
promise(.success(response.data))
} catch let error as NetworkError {
promise(.success(response.data))
} catch let error as NetworkError {
promise(.failure(error))
}
}
Expand All @@ -66,7 +66,7 @@ final class AuthRepositoryImpl: AuthRepository {
do {
let response: BaseResponse<SignUpResponseDTO> = try await NetworkService.shared.request(endpoint: UserEndpoint.getUser)
promise(.success(response.data))
} catch let error as NetworkError {
} catch let error as NetworkError {
promise(.failure(error))
}
}
Expand Down Expand Up @@ -98,7 +98,6 @@ final class AuthRepositoryImpl: AuthRepository {
let response: BaseResponse<UserProfile> = try await NetworkService.shared.request(endpoint: UserEndpoint.getUserProfile)
promise(.success(response.data))
} catch let error as NetworkError {

promise(.failure(error))
}
}
Expand All @@ -110,10 +109,8 @@ final class AuthRepositoryImpl: AuthRepository {
Task {
do {
let response: BaseResponse<WithdrawResponseDTO> = try await NetworkService.shared.request(endpoint: AuthEndpoint.withdraw)

promise(.success(()))
} catch let error as NetworkError {

} catch let error as NetworkError {
promise(.failure(error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class SocialLoginRepositoryImpl: SocialLoginRepository {
let _ = try await NetworkService.shared.plainRequest(endpoint: ASAuthEndpoint.requestRevoke(asRevokeTokenRequestDto))
promise(.success(()))
}
catch let error as NetworkError {
catch let error as NetworkError {
promise(.failure(error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ final class StudySessionRepositoryImpl: StudySessionRepository {
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))
}
}
Expand All @@ -57,7 +56,7 @@ final class StudySessionRepositoryImpl: StudySessionRepository {
let response: BaseResponse<WeeklyRankingResponseDTO> = try await NetworkService.shared.request(endpoint: WeeklyEndpoint.getWeeklyRanking(yearWeek: weekNumber))
promise(.success(response.data.toEntity()))
} catch let error as NetworkError {
print(error.message)
promise(.failure(error))
}
}
}.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class WeeklyRepositoryImpl: WeeklyRepository {
let response: BaseResponse<WeekFieldResponseDTO> = try await NetworkService.shared.request(endpoint: WeeklyEndpoint.getWeekField(date: date))
promise(.success(response.data.weekNumber))
} catch let error as NetworkError {
print(error.message)
promise(.failure(error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ final class StudySessionInteractorImpl: StudySessionInteractor {

/// 열람실 이용종료 Notification을 등록합니다.
func registerNotification(for type: StudyNotificationType, endTimeInMinute: TimeInterval) {
guard appState.value.userData.isOnAlarm else { return }
let content = configuredNotificationContent(for: type)
let trigger = configuredNotificationTrigger(for: type, endTime: endTimeInMinute)
let request = UNNotificationRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class UserDataMigrationInteractor: UserDataInteractor {
/// - Parameter authorization: ASAuthorization
func requestAppleLogin(_ authorization: ASAuthorization) {
guard let appleIDCredential = appleLoginService.requestAppleLogin(authorization),
let idTokenData = appleIDCredential.identityToken,
let idTokenData = appleIDCredential.identityToken,
let idToken = String(data: idTokenData, encoding: .utf8) else {
return
}
Expand All @@ -89,12 +89,14 @@ final class UserDataMigrationInteractor: UserDataInteractor {
return Fail(error: NetworkError.decodingError("")).eraseToAnyPublisher()
}
let loginReqDto: LoginRequestDTO = .init(email: userID, idToken: idToken)

return authRepository.signIn(loginReqDto: loginReqDto)
}
.receive(on: DispatchQueue.main)
.sink(
receiveCompletion: { _ in},
receiveValue: { [weak self] loginResDto in

guard let self = self else { return }

let isAlreadyExists = loginResDto.alreadyExist
Expand Down Expand Up @@ -124,7 +126,8 @@ final class UserDataMigrationInteractor: UserDataInteractor {
receiveValue: { [weak self] signUpResDto in
guard let self = self else { return }
appState[\.userSession] = .authenticated
KeyChainManager.addItem(key: .accessToken, value: signUpResDto.accessToken)
appState[\.routing.onboarding.signUp] = false
KeyChainManager.addItem(key: .accessToken, value: signUpResDto.accessToken)
}
)
.store(in: cancleBag)
Expand All @@ -149,26 +152,6 @@ final class UserDataMigrationInteractor: UserDataInteractor {
.store(in: cancleBag)
}

/// 로그인된 유저정보를 가져옵니다.
func getUser() {
authRepository
.getUser()
.receive(on: DispatchQueue.main)
.sink(
receiveCompletion: { [weak self] completion in
guard let self = self else { return }
switch completion {
case .finished:
appState[\.userSession] = .authenticated
case .failure(_):
appState[\.userSession] = .unauthenticated
}
},
receiveValue: { _ in }
)
.store(in: cancleBag)
}

/// 유저인증 상태를 체크합니다.
func checkAuthentication() {
authRepository
Expand All @@ -184,6 +167,7 @@ final class UserDataMigrationInteractor: UserDataInteractor {
}
}, receiveValue: { [weak self] tokenValidRes in
guard let self = self else { return }

if tokenValidRes.role == "USER" {
appState[\.userSession] = .authenticated
} else {
Expand All @@ -193,12 +177,16 @@ final class UserDataMigrationInteractor: UserDataInteractor {
.store(in: cancleBag)
}

func getUserProfile(userProfile: Binding<UserProfile>) {
func getUserProfile() {
authRepository
.getUserProfile()
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { _ in }) {
userProfile.wrappedValue = $0
.sink(receiveCompletion: { _ in }) { [weak self] userProfile in
guard let self = self else { return }
appState.bulkUpdate { appState in
appState.userData.nickname = userProfile.nickname
appState.userData.department = userProfile.department
}
}
.store(in: cancleBag)
}
Expand Down
29 changes: 4 additions & 25 deletions HongikYeolgong2/Domain/Interactors/UserDataInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ protocol UserDataInteractor: AnyObject {
func requestAppleLogin(_ authorization: ASAuthorization)
func signUp(nickname: String, department: Department)
func logout()
func getUser()
func checkAuthentication()
func checkUserNickname(nickname: String, nicknameCheckSubject: CurrentValueSubject<Bool, Never>)
func getUserProfile(userProfile: Binding<UserProfile>)
func getUserProfile()
func withdraw()
}

Expand Down Expand Up @@ -108,26 +107,6 @@ final class UserDataInteractorImpl: UserDataInteractor {
.store(in: cancleBag)
}

/// 로그인된 유저정보를 가져옵니다.
func getUser() {
authRepository
.getUser()
.receive(on: DispatchQueue.main)
.sink(
receiveCompletion: { [weak self] completion in
guard let self = self else { return }
switch completion {
case .finished:
appState[\.userSession] = .authenticated
case .failure(_):
appState[\.userSession] = .unauthenticated
}
},
receiveValue: { _ in }
)
.store(in: cancleBag)
}

/// 유저인증 상태를 체크합니다.
func checkAuthentication() {
authRepository
Expand All @@ -152,12 +131,12 @@ final class UserDataInteractorImpl: UserDataInteractor {
.store(in: cancleBag)
}

func getUserProfile(userProfile: Binding<UserProfile>) {
func getUserProfile() {
authRepository
.getUserProfile()
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { _ in }) {
userProfile.wrappedValue = $0
.sink(receiveCompletion: { _ in }) { _ in

}
.store(in: cancleBag)
}
Expand Down
Loading

0 comments on commit dc0285a

Please sign in to comment.