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.
Feature/roomfinder study rooms (#449)
* Fix inconsistency on pakage updates, warnings and integrating studyRooms backend * Fix calendar events details view * Refactoring, improvements and merge conflict resolutions to integrade fully study rooms and RoomFinder * Fix calendar day view on iPads * Change Cancel button on selected event sheet to Done * User customizable number of calendar week days * Automatic scrolling on calendar mounth and list view * Fix all build warnings * Adding location and time hh:mm to events in kvkcalendar * Remove the single vertical line on calendar day view * Change the spcaes between horizontal map pics slide Co-authored-by: Milen Vitanov <m.vitanov@tum.de>
- Loading branch information
Showing
73 changed files
with
2,284 additions
and
470 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
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,81 @@ | ||
// | ||
// TUMDevAppAPI.swift | ||
// Campus-iOS | ||
// | ||
// Created by Milen Vitanov on 05.05.22. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
import CoreLocation | ||
|
||
enum TUMDevAppAPI: URLRequestConvertible { | ||
case room(roomNr: Int) | ||
case rooms | ||
|
||
static let baseURL = "https://www.devapp.it.tum.de" | ||
|
||
var path: String { | ||
switch self { | ||
case .room, .rooms: return "iris/ris_api.php" | ||
} | ||
} | ||
|
||
var method: HTTPMethod { | ||
switch self { | ||
default: return .get | ||
} | ||
} | ||
|
||
static var requiresAuth: [String] = [] | ||
|
||
func asURLRequest() throws -> URLRequest { | ||
let url = try TUMDevAppAPI.baseURL.asURL() | ||
var urlRequest = try URLRequest(url: url.appendingPathComponent(path), method: method) | ||
|
||
switch self { | ||
case .room(let roomNr): | ||
urlRequest = try URLEncoding.default.encode(urlRequest, with: ["format": "json", "raum": roomNr]) | ||
case .rooms: | ||
urlRequest = try URLEncoding.default.encode(urlRequest, with: ["format": "json"]) | ||
} | ||
|
||
return urlRequest | ||
} | ||
|
||
// Maximum size of cache: 500kB, Maximum cache entries: 1000, Lifetime: 10min | ||
static let cache = Cache<String, Decodable>(totalCostLimit: 500_000, countLimit: 1_000, entryLifetime: 10 * 60) | ||
|
||
static func fetchStudyRooms(forcedRefresh: Bool) async throws -> StudyRoomApiRespose { | ||
|
||
let fullRequestURL = baseURL + self.rooms.path | ||
|
||
if !forcedRefresh, let rawStudyRoomsResponse = cache.value(forKey: baseURL + self.rooms.path), let studyRoomsResponse = rawStudyRoomsResponse as? StudyRoomApiRespose { | ||
print("Study rooms data from cache") | ||
return studyRoomsResponse | ||
} else { | ||
print("Study rooms data from server") | ||
// Fetch new data and store in cache. | ||
var studyRoomsData: Data | ||
do { | ||
studyRoomsData = try await AF.request(self.rooms).serializingData().value | ||
} catch { | ||
print(error) | ||
throw NetworkingError.deviceIsOffline | ||
} | ||
|
||
var studyRoomsResponse = StudyRoomApiRespose() | ||
do { | ||
studyRoomsResponse = try JSONDecoder().decode(StudyRoomApiRespose.self, from: studyRoomsData) | ||
} catch { | ||
print(error) | ||
throw error | ||
} | ||
|
||
// Write value to cache | ||
cache.setValue(studyRoomsResponse, forKey: fullRequestURL) | ||
|
||
return studyRoomsResponse | ||
} | ||
} | ||
} |
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.