Skip to content

Commit

Permalink
feat(library): remove booking and add new sheet (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 authored Dec 19, 2024
1 parent 42de524 commit 9b60ac4
Show file tree
Hide file tree
Showing 179 changed files with 5,292 additions and 2,289 deletions.
10 changes: 6 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
},
"extends": [
"eslint:recommended",
"standard-with-typescript",
"plugin:@typescript-eslint/strict",
"plugin:@typescript-eslint/stylistic",
"plugin:react/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "**/tsconfig.json",
"tsconfigRootDir": "./",
"noUnusedLocals": true
"tsconfigRootDir": "./"
},
"plugins": [
"react",
"react-native",
"i18next",
"react-hooks",
"react-native-unistyles"
"react-native-unistyles",
"@typescript-eslint"
],
"settings": {
"react": {
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM oven/bun:1 AS bun
WORKDIR /usr/src/app

# Copy necessary files and install dependencies
COPY package.json bun.lockb ./
COPY package.json bun.lock ./
COPY patches patches
RUN bun install --ignore-scripts --freeze-lockfile

Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ android {
applicationId 'app.neuland'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 265
versionCode 271
versionName "0.11.0"
}
signingConfigs {
Expand Down
2 changes: 1 addition & 1 deletion app.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"android": {
"package": "app.neuland",
"userInterfaceStyle": "automatic",
"versionCode": 265
"versionCode": 271
},
"sdkVersion": "52.0.0",
"experiments": {
Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable no-undef */
module.exports = function (api) {
api.cache(true)
return {
Expand Down
3,678 changes: 3,678 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

Binary file removed bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ RUN apt-get update && apt-get install -y git
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
COPY package.json bun.lock /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile --ignore-scripts

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
COPY package.json bun.lock /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production --ignore-scripts

# copy node_modules from temp directory
Expand Down
503 changes: 503 additions & 0 deletions docs/bun.lock

Large diffs are not rendered by default.

Binary file removed docs/bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion docs/de/app/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Finde **verfügbare Räume**, checke Gebäude oder erkunde den Campus. Nutze uns

### Bibliothek

**Reserviere einen Platz** direkt in der App oder nutze deine Bibliotheks-ID, um Bücher an den Terminals auszuleihen und zurückzugeben.
Nutze deine **virtuelle Bibliotheks-ID**, um Bücher an den Terminals auszuleihen und zurückzugeben.
Oder buche einen **Arbeitsplatz** über den Link in der App.

### Quick Links

Expand Down
2 changes: 1 addition & 1 deletion docs/de/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ features:
link: /app/features#campusplan
- title: Bibliothek
icon: 📚
details: Reserviere einen Platz direkt in der App oder nutze deinen Bibliotheksausweis, um Bücher an den Terminals auszuleihen.
details: Nutze deine virtuelle Bibliotheks-ID, um Bücher an den Terminals auszuleihen und zurückzugeben.
link: /app/features#bibliothek
---
2 changes: 1 addition & 1 deletion docs/en/app/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Find **available rooms**, view buildings or explore the university campus. Use o

### Library

**Reserve a seat** directly from the app, or use your library ID to check out and return books at the terminals.
Use your **virtual library ID** to check out at the terminals to borrow and return books. Or book a **workplace** via the link in the app.

### Quick Links

Expand Down
2 changes: 1 addition & 1 deletion docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ features:
link: /en/app/features#campus-map
- title: Library
icon: 📚
details: Reserve a seat directly from the app, or use your library ID to check out at the terminals.
details: Use your virtual library ID to check out at the terminals to borrow and return books.
link: /en/app/features#library
---
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNDeviceInfo (14.0.1):
- RNDeviceInfo (14.0.2):
- React-Core
- RNFlashList (1.7.1):
- DoubleConversion
Expand Down Expand Up @@ -2808,7 +2808,7 @@ SPEC CHECKSUMS:
ReactCommon: 858d61cce81635d57be89348568b603e838b3cac
rn-quick-actions: dbd80c5223df43389c11920e035d09f4b7694176
RNDateTimePicker: b4dbbbe7a49cf4c9d9c01179f6d30242018e20da
RNDeviceInfo: 825f0d2f4381327317f12d1522720a8f76e6a19e
RNDeviceInfo: 3f2e5fcca3637f75c6d30ba287293c2f97206781
RNFlashList: b85e7b9e77c3b6d9169f88d60ed6dca0a479a822
RNGestureHandler: 598e45cedb905b157e9764acbef0b5e365693451
RNReanimated: c1e1a4cfb360c774af62b1e45f5cd03e49394ad0
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"@aptabase/react-native": "^0.3.10",
"@babel/runtime": "^7.26.0",
"@bottom-tabs/react-navigation": "^0.7.7",
"@bottom-tabs/react-navigation": "^0.7.8",
"@expo/metro-runtime": "^4.0.0",
"@expo/vector-icons": "^14.0.4",
"@gorhom/bottom-sheet": "^5.0.6",
Expand Down Expand Up @@ -98,7 +98,7 @@
"react-native-web": "^0.19.13",
"react-native-webview": "13.12.5",
"rn-quick-actions": "^0.0.3",
"sanitize-html": "^2.13.1",
"sanitize-html": "^2.14.0",
"sweet-sfsymbols": "0.7.2",
"swiftui-react-native": "^6.3.3",
"zustand": "^5.0.2"
Expand Down Expand Up @@ -126,16 +126,16 @@
"@types/prop-types": "^15.7.14",
"@types/react": "~18.3.17",
"@types/sanitize-html": "^2.13.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"ajv": "^8.17.1",
"babel-plugin-formatjs": "^10.5.29",
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-i18next": "^6.1.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsonc": "^2.18.2",
"eslint-plugin-n": "^17.15.0",
"eslint-plugin-promise": "^7.2.1",
"eslint-plugin-react": "7.35.2",
Expand Down
13 changes: 10 additions & 3 deletions src/api/anonymous-api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

/* eslint-disable @typescript-eslint/no-unsafe-member-access */

/* eslint-disable @typescript-eslint/no-unsafe-return */

/* eslint-disable @typescript-eslint/no-explicit-any */
import { Platform } from 'react-native'

import packageInfo from '../../package.json'

const ENDPOINT_HOST: string = 'hiplan.thi.de'
const ENDPOINT_HOST = 'hiplan.thi.de'
const ENDPOINT_URL = '/webservice/zits_s_40_test/index.php'
const USER_AGENT = `neuland.app-native/${packageInfo.version} (+${packageInfo.homepage})`

Expand All @@ -14,7 +21,7 @@ export class APIError extends Error {
public data: object

constructor(status: number, data: object) {
super(`${JSON.stringify(data)} (${status})`)
super(`${JSON.stringify(data)} (${status.toString()})`)
this.status = status
this.data = data
}
Expand Down Expand Up @@ -50,7 +57,7 @@ export class AnonymousAPIClient {

try {
return await resp.json()
} catch (e) {
} catch {
throw new Error(`Response is not valid JSON (${await resp.text()})`)
}
}
Expand Down
128 changes: 11 additions & 117 deletions src/api/authenticated-api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */

/* eslint-disable @typescript-eslint/no-unsafe-assignment */

/* eslint-disable @typescript-eslint/no-unsafe-member-access */

/* eslint-disable @typescript-eslint/no-unsafe-return */

/* eslint-disable @typescript-eslint/no-explicit-any */

/* eslint-disable @typescript-eslint/no-unsafe-argument */
import {
type AvailableLibrarySeats,
type Exams,
type Grade,
type Lecturers,
type PersData,
type Reservation,
type Rooms,
type ThiNews,
type TimetableResponse,
Expand Down Expand Up @@ -40,6 +48,7 @@ export class AuthenticatedAPIClient extends AnonymousAPIClient {
* @param {object} params Request data
* @returns {object}
*/
// eslint-disable-next-line @typescript-eslint/require-await
async requestAuthenticated(params: object): Promise<any> {
console.debug(params)
return this.sessionHandler(async (session: any) => {
Expand Down Expand Up @@ -206,121 +215,6 @@ export class AuthenticatedAPIClient extends AnonymousAPIClient {
return res
}

async getLibraryReservations(): Promise<Reservation[]> {
try {
const res = await this.requestAuthenticated({
service: 'thiapp',
method: 'reservations',
type: 1,
cmd: 'getreservations',
format: 'json',
})

return res[1]
} catch (e: any) {
// as of 2021-06 the API returns "Service not available" when the user has no reservations
// thus we dont alert the error here, but just silently set the reservations to none
if (
e.data === 'No reservation data' ||
e.data === 'Service not available'
) {
return []
} else {
throw e
}
}
}

async getAvailableLibrarySeats(): Promise<AvailableLibrarySeats[]> {
try {
const res = await this.requestAuthenticated({
service: 'thiapp',
method: 'reservations',
type: 1,
subtype: 1,
cmd: 'getavailabilities',
format: 'json',
})

return res[1]
} catch (e: any) {
// Unbekannter Fehler means the user has already reserved a spot
// and can not reserve additional ones
if (e.data === 'Unbekannter Fehler') {
return []
} else {
throw e
}
}
}

/**
* Adds a library reservation for a specific room, day, start and end time, and place
* @param {string} roomId ID of the room to reserve
* @param {string} day Date of the reservation
* @param {string} start Start time of the reservation
* @param {string} end End time of the reservation
* @param {string} place Place of the reservation
* @returns {Promise<any>} Promise that resolves with the reservation ID
*/
async addLibraryReservation(
roomId: string,
day: string,
start: string,
end: string,
place: string
): Promise<any> {
const res = await this.requestAuthenticated({
service: 'thiapp',
method: 'reservations',
type: 1,
subtype: 1,
cmd: 'addreservation',
data: JSON.stringify({
resource: roomId,
at: day,
from: start,
to: end,
place,
}),
dblslots: 0,
format: 'json',
})

return res[0]
}

/**
* Removes a library reservation
* @param {string} reservationId Reservation ID returned by `getLibraryReservations`
*/
async removeLibraryReservation(reservationId: string): Promise<boolean> {
try {
await this.requestAuthenticated({
service: 'thiapp',
method: 'reservations',
type: 1,
subtype: 1,
cmd: 'delreservation',
data: reservationId,
format: 'json',
})

return true
} catch (e: any) {
// as of 2021-06 the API returns "Service not available" when the user has no reservations
// thus we dont alert the error here, but just silently set the reservations to none
if (
e.data === 'No reservation data' ||
e.data === 'Service not available'
) {
return true
} else {
throw e
}
}
}

/**
* Fetches the latest thi news
* @returns {Promise<ThiNews[]>} Promise that resolves with the news
Expand Down
Loading

0 comments on commit 9b60ac4

Please sign in to comment.