-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebddbbc
commit 5ac4cbb
Showing
14 changed files
with
538 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
StudyFora.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http:https://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict/> | ||
</plist> |
14 changes: 14 additions & 0 deletions
14
...proj/project.xcworkspace/xcuserdata/carissafarry.xcuserdatad/WorkspaceSettings.xcsettings
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http:https://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>BuildLocationStyle</key> | ||
<string>UseAppPreferences</string> | ||
<key>CustomBuildLocationType</key> | ||
<string>RelativeToDerivedData</string> | ||
<key>DerivedDataLocationStyle</key> | ||
<string>Default</string> | ||
<key>ShowSharedSchemesAutomaticallyEnabled</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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 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 @@ | ||
// | ||
// StatesEnum.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 23/12/23. | ||
// | ||
|
||
enum StatesEnum: String,Equatable { | ||
case initiate = "Initiate" | ||
case loading = "Loading" | ||
case error = "Error" | ||
case success = "Success" | ||
} |
13 changes: 13 additions & 0 deletions
13
StudyFora/Features/Login/Domain/Model/LoginReponseModel.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 @@ | ||
// | ||
// LoginReponseModel.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 27/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LoginResponseModel { | ||
let uid: String | ||
let email: String | ||
} |
18 changes: 18 additions & 0 deletions
18
StudyFora/Features/Profile/Presentation/View/ProfileView.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,18 @@ | ||
// | ||
// ProfileView.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 26/12/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ProfileView: View { | ||
var body: some View { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
} | ||
} | ||
|
||
#Preview { | ||
ProfileView() | ||
} |
23 changes: 23 additions & 0 deletions
23
StudyFora/Features/Register/Data/RepositoryImpl/RegisterRepositoryImpl.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,23 @@ | ||
// | ||
// RegisterRepositoryImpl.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 26/12/23. | ||
// | ||
|
||
import Foundation | ||
import FirebaseAuth | ||
|
||
struct RegisterRepositoryImpl: RegisterRepository { | ||
func doRegister(data: RegisterRequestModel, completion: @escaping (Result<AuthDataResult, Error>) -> Void) { | ||
Auth.auth().createUser(withEmail: data.email, password: data.password) { authResult, error in | ||
if let error = error { | ||
completion(.failure(error)) | ||
} else if let authResult = authResult { | ||
completion(.success(authResult)) | ||
} else { | ||
fatalError("Unexpected nil value in authResult") | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
StudyFora/Features/Register/Domain/Model/RegisterRequestModel.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 @@ | ||
// | ||
// RegisterRequestModel.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 27/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RegisterRequestModel { | ||
let email: String | ||
let password: String | ||
} |
12 changes: 12 additions & 0 deletions
12
StudyFora/Features/Register/Domain/Repository/RegisterRepository.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,12 @@ | ||
// | ||
// RegisterRepository.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 26/12/23. | ||
// | ||
|
||
import FirebaseAuth | ||
|
||
protocol RegisterRepository{ | ||
func doRegister(data: RegisterRequestModel, completion: @escaping (Result<AuthDataResult, Error>) -> Void) | ||
} |
29 changes: 29 additions & 0 deletions
29
StudyFora/Features/Register/Domain/UseCase/RegisterUseCase.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,29 @@ | ||
// | ||
// RegisterUseCase.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 26/12/23. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import FirebaseAuth | ||
|
||
struct RegisterUseCase { | ||
var repository: RegisterRepository | ||
|
||
func execute(data: RegisterRequestModel) async throws -> AuthDataResult? { | ||
return try await withCheckedThrowingContinuation { continuation in | ||
repository.doRegister(data:data) { result in | ||
do { | ||
let authResult = try result.get() | ||
print("User registered successfully!") | ||
continuation.resume(returning: authResult) | ||
} catch { | ||
print("Error registering user: \(error.localizedDescription)") | ||
continuation.resume(throwing: error) | ||
} | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
StudyFora/Features/Register/Presentation/View/RegisterView.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,40 @@ | ||
// | ||
// RegisterView.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 23/12/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct RegisterView: View { | ||
@EnvironmentObject var router: Router | ||
|
||
@StateObject var registerViewModel = RegisterViewModel() | ||
|
||
@State private var email = "" | ||
@State private var password = "" | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Register") | ||
TextField("Email", text: self.$email) | ||
TextField("Password", text: self.$password) | ||
Button("Register") { | ||
Task { | ||
await registerViewModel.register(data: RegisterRequestModel(email: email, password: password)) | ||
print(email) | ||
} | ||
} | ||
Button("Back") { | ||
router.navigateBack() | ||
} | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
#Preview { | ||
RegisterView() | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
StudyFora/Features/Register/Presentation/ViewModel/RegisterViewModel.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,28 @@ | ||
// | ||
// RegisterViewModel.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 23/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
class RegisterViewModel: ObservableObject { | ||
private var registerUseCase = RegisterUseCase(repository: RegisterRepositoryImpl()) | ||
|
||
@Published var states: StatesEnum = .initiate | ||
@Published var userLogin: LoginResponseModel? | ||
|
||
func register(data: RegisterRequestModel) async { | ||
do { | ||
if let res = try await registerUseCase.execute(data: data) { | ||
userLogin = LoginResponseModel( | ||
uid: res.user.uid, | ||
email: res.user.email! | ||
) | ||
} | ||
} catch let error { | ||
states = .error | ||
} | ||
} | ||
} |