Skip to content

Commit

Permalink
33 schema adaptation (#40)
Browse files Browse the repository at this point in the history
* Added api changes for vehicles for website

* Added api changes for app

* Added speed to schema and interface

* Added type changes to api

* Some refactoring

* Changed schema a bit

* some testing -> changing done

* Changed type of tracker ids

---------

Co-authored-by: Liam Boddin <stu222452@mail.uni-kiel.de>
  • Loading branch information
2 people authored and n1kPLV committed Jul 24, 2023
1 parent d12674d commit 2a5cab5
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 449 deletions.
18 changes: 4 additions & 14 deletions Server/src/models/api.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,17 @@ export interface VehicleApp {
headingTowardsUser: boolean; // Is the other vehicle heading towards the user?
}

export interface UpdateRequestWithLocationEnabledApp {
export interface UpdateRequestApp {
vehicleId: number; // vehicle id of user
pos: PositionApp; // the current position of user
pos?: PositionApp; // the current position of user
}

export interface UpdateResponseWithLocationEnabledApp {
vehiclesNearUser: VehicleApp[]; // Vehicles that should be marked on the map
percentagePositionOnTrack: number; // Percentage (0-100) e.g. 0% Malente; 100% Lütjenburg
passingPosition?: PositionApp; // Only set if needed
}


export interface UpdateRequestWithLocationNotEnabledApp {
vehicleId: number; // vehicle id of user
}

export interface UpdateResponseWithLocationNotEnabledApp {
export interface UpdateResponseApp {
pos: PositionApp; // The current position as measured by vehicle
heading: number; // Heading of the vehicle between 0 and 359
vehiclesNearUser: VehicleApp[]; // Vehicles that should be marked on the map
percentagePositionOnTrack: number; // Percentage (0-100) e.g. 0% Malente; 100% Lütjenburg
speed: number // Speed in km/h
passingPosition?: PositionApp; // Only set if needed
}

Expand Down
10 changes: 4 additions & 6 deletions Server/src/models/api.website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,16 @@ export interface TrackPathWebsite {

export interface VehicleListItemWebsite {
uid: number, // Uid of the vehicle
name: string, // String name of the vehicle, perhaps something like "Draisine 1"
physicalName: string, // The name, that is attached to the vehicle, e.g. "1" for "Draisine 1"
name: string, // The name, that is attached to the vehicle, e.g. "1" for "Draisine 1"
typeId: number, // The id of the type
trackerId?: string // A unique id to identify the tracker belonging to that vehicle
trackerIds?: string[] // A unique id to identify the tracker belonging to that vehicle
}

export interface VehicleCrUWebsite {
uid?: number, // Null, if creating vehicle, some other value otherwise
name: string, // String name of the vehicle, perhaps something like "Draisine 1"
physicalName: string, // The name, that is attached to the vehicle, e.g. "1" for "Draisine 1"
name: string, // The name, that is attached to the vehicle, e.g. "1" for "Draisine 1"
typeId: number, // The id of the type
trackerId?: string // A unique id to identify the tracker belonging to that vehicle
trackerIds: string[]// A unique id to identify the tracker belonging to that vehicle
}

export interface VehicleTypeListItemWebsite {
Expand Down
64 changes: 22 additions & 42 deletions Server/src/models/jsonschemas.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export const InitResponseSchemaApp = {
"trackName": { "type": "string" },
"trackPath": { "type": "GeoJSON" },
"trackLength": { "type": "number" },
"pointsOfInterest": { "type": "array",
"items": { "$ref": "PointOfInterestApp" } },
"pointsOfInterest": {
"type": "array",
"items": { "$ref": "PointOfInterestApp" }
},
},
"required": [
"trackId",
Expand Down Expand Up @@ -75,8 +77,8 @@ export const PointOfInterestSchemaApp = {
"isTurningPoint": { "type": "boolean" },
},
"required": ["type", "pos", "percentagePosition",
"isTurningPoint"],
"additionalProperties": false
"isTurningPoint"],
"additionalProperties": false
}


Expand All @@ -89,13 +91,13 @@ export const VehicleSchemaApp = {
"headingTowardsUser": { "type": "boolean" },
"heading": { "type": "number", "minimum": 0, "maximum": 359 },
},
"required": ["id", "pos",
"headingTowardsUser", "heading"],
"required": ["id", "pos",
"headingTowardsUser", "heading"],
"additionalProperties": false
}

export const UpdateRequestWithLocationEnabledSchemaApp = {
"id": "UpdateRequestWithLocationEnabledApp",
export const UpdateRequestSchemaApp = {
"id": "UpdateRequestApp",
"type": "object",
"properties": {
"vehicleId": { "type": "number" },
Expand All @@ -108,46 +110,24 @@ export const UpdateRequestWithLocationEnabledSchemaApp = {
"additionalProperties": false
}

export const UpdateResponseWithLocationEnabledSchemaApp = {
"id": "UpdateResponseWithLocationEnabledApp",
"type": "object",
"properties": {
"vehiclesNearUser": { "type": "array",
"items": { "$ref": "VehicleApp" } },
"percentagePositionOnTrack": { "type": "number" },
"passingPosition": { "$ref": "PositionApp" },
},
"required": [
"vehiclesNearUser",
"passingPosition"
],
"additionalProperties": false
}

export const UpdateRequestWithLocationNotEnabledSchemaApp = {
"id": "UpdateRequestWithLocationNotEnabledApp",
"type": "object",
"properties": {
"vehicleId": { "type": "number" },
},
"required": ["vehicleId"],
"additionalProperties": false
}

export const UpdateResponseWithLocationNotEnabledSchemaApp = {
"id": "UpdateResponseWithLocationNotEnabledApp",
export const UpdateResponseAppSchema = {
"id": "UpdateResponseApp",
"type": "object",
"properties": {
"pos": { "$ref": "PositionApp" },
"heading": { "type": "number" },
"vehiclesNearUser": { "type": "array",
"items": { "$ref": "VehicleApp" } },
"percentagePositionOnTrack": { "type": "number",
"minimum": 0, "maximum": 101 },
"vehiclesNearUser": {
"type": "array",
"items": { "$ref": "VehicleApp" }
},
"percentagePositionOnTrack": {
"type": "number",
"minimum": 0, "maximum": 101
},
"speed" : { "type": "number"},
"passingPosition": { "$ref": "PositionApp" },
},
"required": ["pos", "vehicleId",
"heading", "vehiclesNearUser", "percentagePositionOnTrack"],
"required": ["pos", "heading", "vehiclesNearUser", "percentagePositionOnTrack", "speed"],
"additionalProperties": false
}

Expand Down
14 changes: 11 additions & 3 deletions Server/src/models/jsonschemas.website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ export const VehicleListItemSchemaWebsite = {
"name": { "type" : "string"},
"physicalName": { "type" : "string"},
"typeId": { "type" : "number"},
"trackerId": { "type" : "string"},
"trackerIds": {
"type": "array", "items": {
"type": "number"
}
},
},
"required": ["uid", "name", "physicalName", "typeId"],
"additionalProperties": false
Expand All @@ -205,9 +209,13 @@ export const VehicleCrUSchemaWebsite = {
"name": { "type" : "string"},
"physicalName": { "type" : "string"},
"typeId": { "type" : "number"},
"trackerId": { "type" : "string"},
"trackerIds": {
"type": "array", "items": {
"type": "string"
}
},
},
"required": ["name", "physicalName", "typeId"],
"required": ["name", "physicalName", "typeId", "trackerIds"],
"additionalProperties": false
}

Expand Down
52 changes: 27 additions & 25 deletions Server/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { Request, Response, Router } from "express";
import { Request, Response, Router } from "express"

import { LoginRoute } from "./login.route";
import { VehicleRoute } from "./vehicles.route";
import { InitRoute } from "./init.route";
import { TrackerRoute } from "./tracker.route";
import * as jwt from "jsonwebtoken";
import { logger } from "../utils/logger";
import bodyParser from "body-parser";
import { randomBytes } from "crypto";
import { PoiRoute } from "./poi.route";
import { TrackUploadRoute } from "./trackupload.route";
import { UsersRoute } from "./users.route";
import { PointOfInterestSchemaApp, PositionSchemaApp, VehicleSchemaApp } from "../models/jsonschemas.app";
import { PointOfInterestSchemaWebsite, PositionSchemaWebsite, UserSchemaWebsite } from "../models/jsonschemas.website";
import { validate } from "jsonschema";
const Validator = require('jsonschema').Validator;
import { LoginRoute } from "./login.route"
import { VehicleRoute } from "./vehicles.route"
import { InitRoute } from "./init.route"
import { TrackerRoute } from "./tracker.route"
import * as jwt from "jsonwebtoken"
import { logger } from "../utils/logger"
import bodyParser from "body-parser"
import { randomBytes } from "crypto"
import { PoiRoute } from "./poi.route"
import { TrackUploadRoute } from "./trackupload.route"
import { UsersRoute } from "./users.route"
import { PointOfInterestSchemaApp, PositionSchemaApp, VehicleSchemaApp } from "../models/jsonschemas.app"
import { PointOfInterestSchemaWebsite, PositionSchemaWebsite, UserSchemaWebsite } from "../models/jsonschemas.website"
import { validate } from "jsonschema"
import { VehicleTypeRoute } from "./vehicletypes.route"
const Validator = require('jsonschema').Validator

const config = require("../config/index");
const config = require("../config/index")
/** A basic jsonParser to parse the requestbodies. */
export const jsonParser = bodyParser.json();
export const jsonParser = bodyParser.json()

/** A validator for json schema validation. */
export const v = new Validator();
export const v = new Validator()

/** A secret string that is used to create and verify the authentication tokens.*/
export const accessTokenSecret: string = randomBytes(128).toString("base64")
Expand All @@ -31,12 +32,12 @@ export const accessTokenSecret: string = randomBytes(128).toString("base64")
*/
export class ApiRoutes {
/** The base path for the api. This name was chosen to make sure it is obvious, that this is only a REST-API. */
public static path = "/api";
public static path = "/api"
/** The main router instance. */
public static instance: ApiRoutes;
public static instance: ApiRoutes

/** The base router object. */
private router = Router();
private router = Router()

/**
* Initializes the router with all of the subrouters.
Expand All @@ -55,16 +56,17 @@ export class ApiRoutes {
this.router.use(TrackUploadRoute.path, TrackUploadRoute.router)
this.router.use(UsersRoute.path, UsersRoute.router)
this.router.use(TrackerRoute.path, TrackerRoute.router)
this.router.use(VehicleTypeRoute.path, VehicleTypeRoute.router)
}

/**
* Creates an instance if there is none yet.
*/
static get router() {
if (!ApiRoutes.instance) {
ApiRoutes.instance = new ApiRoutes();
ApiRoutes.instance = new ApiRoutes()
}
return ApiRoutes.instance.router;
return ApiRoutes.instance.router
}
}

Expand All @@ -77,7 +79,7 @@ export class ApiRoutes {
* @returns Just `void`.
*/
export const authenticateJWT = (req: Request, res: Response, next: any) => {
const authHeader = req.headers.authorization;
const authHeader = req.headers.authorization

if (authHeader) {
// Bearer <token>
Expand Down
Loading

0 comments on commit 2a5cab5

Please sign in to comment.