This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calendar types, TUMSexyView, MoviesView and NewsView (#399)
* Introduce Different Calendar Types * Fully functional TUMSexy component * added buildin web view functionality * Working News API * Initial News View * Fix project file after rebase * Finalized news component * Functioning movie component plus initial view * Movies View * Completed Movies Views * Resolve duplicates after rebasing to swiftUi Co-authored-by: Milen Vitanov <m.vitanov@tum.de>
- Loading branch information
Showing
34 changed files
with
1,966 additions
and
577 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// EntityImporter.swift | ||
// Campus-iOS | ||
// | ||
// Created by Milen Vitanov on 13.01.22. | ||
// | ||
|
||
import UIKit.UIApplication | ||
//import CoreData | ||
import Alamofire | ||
import FirebaseCrashlytics | ||
|
||
protocol Entity: Decodable { | ||
|
||
} | ||
|
||
enum ImporterError: Error { | ||
case invalidData | ||
} | ||
|
||
final class Importer<EntityType: Entity, EntityContainer: Decodable, DecoderType: DecoderProtocol> { | ||
typealias RequestHandler = (Result<EntityContainer, Error>) -> Void | ||
|
||
let endpoint: URLRequestConvertible | ||
let dateDecodingStrategy: DecoderType.DateDecodingStrategy? | ||
let predicate: NSPredicate? | ||
|
||
private let sessionManager = Session.defaultSession | ||
|
||
required init(endpoint: URLRequestConvertible, predicate: NSPredicate? = nil, dateDecodingStrategy: DecoderType.DateDecodingStrategy? = nil) { | ||
self.endpoint = endpoint | ||
self.predicate = predicate | ||
self.dateDecodingStrategy = dateDecodingStrategy | ||
} | ||
|
||
func performFetch(handler: RequestHandler? = nil) { | ||
sessionManager.request(endpoint) | ||
.validate(statusCode: 200..<300) | ||
.validate(contentType: DecoderType.contentType) | ||
.responseData { response in | ||
if let responseError = response.error { | ||
handler?(.failure(BackendError.AFError(message: responseError.localizedDescription))) | ||
return | ||
} | ||
guard let data = response.data else { | ||
handler?(.failure(ImporterError.invalidData)) | ||
return | ||
} | ||
|
||
let decoder = DecoderType.instantiate() | ||
if let strategy = self.dateDecodingStrategy { | ||
decoder.dateDecodingStrategy = strategy | ||
} | ||
do { | ||
let storage = try decoder.decode(EntityContainer.self, from: data) | ||
handler?(.success(storage)) | ||
} catch let apiError as APIError { | ||
Crashlytics.crashlytics().record(error: apiError) | ||
handler?(.failure(apiError)) | ||
return | ||
} catch let decodingError as DecodingError { | ||
Crashlytics.crashlytics().record(error: decodingError) | ||
handler?(.failure(decodingError)) | ||
return | ||
} catch let error { | ||
Crashlytics.crashlytics().record(error: error) | ||
handler?(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
} |
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,20 @@ | ||
// | ||
// DecoderProtocol.swift | ||
// Campus-iOS | ||
// | ||
// Created by Milen Vitanov on 13.01.22. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
protocol DecoderProtocol: AnyObject, DataDecoder { | ||
associatedtype DateDecodingStrategy: DecodingStrategyProtocol | ||
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable | ||
var userInfo: [CodingUserInfoKey : Any] { get set } | ||
var dateDecodingStrategy: DateDecodingStrategy { get set } | ||
static var contentType: [String] { get } | ||
static func instantiate() -> Self | ||
} | ||
|
||
protocol DecodingStrategyProtocol { } |
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 @@ | ||
// | ||
// TUMSexyAPI.swift | ||
// TUM Campus App | ||
// | ||
// Created by Tim Gymnich on 2/23/19. | ||
// Copyright © 2019 TUM. All rights reserved. | ||
// | ||
|
||
import Alamofire | ||
import Foundation | ||
|
||
struct TUMSexyAPI: URLRequestConvertible { | ||
static let baseURLString = "https://json.tum.sexy" | ||
|
||
var method: HTTPMethod { | ||
switch self { | ||
default: return .get | ||
} | ||
} | ||
|
||
static var requiresAuth: [String] = [] | ||
|
||
func asURLRequest() throws -> URLRequest { | ||
let url = try TUMSexyAPI.baseURLString.asURL() | ||
let urlRequest = try URLRequest(url: url, method: method) | ||
return urlRequest | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.