Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #13 from City-of-Turku/develop" #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .sanitizerconfig
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ strategy:
identifier: null
modified_at: null
name: null
permitted_user_id: null
parkings_permitarea_allowed_users:
id: null
permitarea_id: null
user_id: null
parkings_permitareaitem:
area_id: null
end_time: null
Expand Down
120 changes: 120 additions & 0 deletions docs/api/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Parkkihubi REST APIs

## Different APIs

Parkkihubi has four different REST APIs:

* [Operator API](../operator/)

Operator API can be used to manage parking events and parking permits.
The API is designed to be used by parking operators and other parking
service providers.

* [Enforcement API](../enforcement/)

Enforcement API can be used to check validity of parkings in relation
to the operator created parking events and parking permits. The API
is designed to be used by a system which serves the parking
enforcement personnel.

* [Public API](../public/)

Public API can be used to get some statistics about the parking areas.
The API is designed to be available for anyone.

**NOTE!** The public API is on very initial state. Backward
incompatible changes are possible.

* Monitoring API

Monitoring API can be used to monitor the status of the Parkkihubi.
The API is designed to be used by the Parkkihubi Dashboard.

## Object Model

### Parking (Event)

Parking is a parking event created by a parking operator. It has a
start time and an end time. The parking can be either paid or free
(e.g. a parking disc parking). Parkkihubi doesn't handle or record
parking payments at the moment.

Parkings record an actual parking event that is happening in the real
world (or has happened when looking back in time for statistics). They
are usually created in real time when the parking event starts. The end
time is usually updated when the parking event ends. (Parkings cannot be
created postactively after the parking event has started, because the
parking enforcement personnel wouldn't be able to check them in real
time.)

### Parking Permit

Parking Permit is a permit created by a parking operator. It has a list
of subjects (i.e. registration numbers) and a list of permitted areas.
Each assigned subject and area in the permit has a separate validity
period. A parking is valid by the permit when the registration number
and the area match and their corresponding validity periods cover the
parking time.

Parking permits should be created in advance, before the parking events
start. They are also used to check if a parking event is valid or not,
but with the permits the actual parking times are not recorded. Parking
permits are usually created for a longer period of time (e.g. a month or
a year).

### Permit Series

Permits are grouped into permit series. Permit series ara used as a
mechanism to allow activating and deactivating permits in bulk.

## Method Override

Parkkihubi REST APIs support using the Method Override.

### What Is Method Override?

Method Override is a way to override the HTTP method of a request. This
is useful when you want to perform an action of a different HTTP method
than the one the client is using, e.g. when you want to perform a
`PATCH` request but the client only supports `GET` and `POST`.

### How To Use the Method Override in Parkkihubi

Parkkihubi supports using a `method` query parameter for overriding the
HTTP method of a request. For example, if you want to perform a `PATCH`
request, you can send a `POST` request with a `method=PATCH` query
parameter.

#### Example

Here is an example of how to use the Method Override to update a parking
end time, which would normally be done with a `PATCH` request, but is
here done with a `POST` request instead.

```bash
ID=abcd1234-1234-1234-1234-123456789012 # A parking ID

curl -X POST \
-H "Content-Type: application/json" \
-d '{"time_end": "2023-10-20T17:00:00+0300"}' \
"https://parkki.turku.fi/operator/v1/parking/$ID/?method=PATCH"
```

For comparison here is how it would look like without the Method
Override:

```bash
curl -X PATCH \
-H "Content-Type: application/json" \
-d '{"time_end": "2023-10-20T17:00:00+0300"}' \
"https://parkki.turku.fi/operator/v1/parking/$ID/"
```

### Limitations

The Method Override is only supported when the carrying request is using
`POST` method and `application/json` content type. It can only be used
to override the method to `PATCH`, `PUT` or `DELETE`.

It is not possible to override the method to `GET` or `POST`, since
these are assumed to be universally supported by clients.
14 changes: 6 additions & 8 deletions docs/api/enforcement.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
openapi: 3.0.1
info:
title: Parkkihubi Enforcement API
description: >-
Parkkihubi Enforcement REST API Documentation
description:
$ref: ./description.md
version: "1.2.0"
servers:
- url: https://api.parkkiopas.fi/enforcement/v1/
- url: https://parkki.turku.fi/enforcement/v1/
description: Production server
- url: https://testapi.parkkiopas.fi/enforcement/v1/
description: Test server
- url: http://localhost:8000/enforcement/v1/
description: Local development server
tags:
Expand Down Expand Up @@ -399,7 +397,7 @@ paths:
properties:
allowed:
description: >-
Allowance status of the parking or event parking.
Allowance status of the parking or event parking.
True if there exists a parking or permit in the system which is
valid for the specified registration number at the
specified location (and time), false otherwise.
Expand Down Expand Up @@ -601,7 +599,7 @@ paths:
type: object
example:
count: 100
next: "https://api.parkkiopas.fi/enforcement/v1/valid_permit_item/?page=2"
next: "https://parkki.turku.fi/enforcement/v1/valid_permit_item/?page=2"
previous: null
results:
- << : *validPermitItemExample
Expand Down Expand Up @@ -1085,4 +1083,4 @@ paths:
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
$ref: '#/components/responses/NotFound'
50 changes: 24 additions & 26 deletions docs/api/operator.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
openapi: 3.0.1
info:
title: Parkkihubi Operator API
description: >-
Parkkihubi Operator REST API Documentation
description:
$ref: ./description.md
version: "1.2.0"
servers:
- url: https://api.parkkiopas.fi/operator/v1/
- url: https://parkki.turku.fi/operator/v1/
description: Production server
- url: https://testapi.parkkiopas.fi/operator/v1/
description: Test server
- url: http://localhost:8000/operator/v1/
description: Local development server
tags:
Expand Down Expand Up @@ -182,7 +180,7 @@ components:
format: dateTime
readOnly: true
location: &eventParkingLocation
$ref: '#/components/schemas/Location'
$ref: '#/components/schemas/Location'
registration_number: &eventParkingRegistrationNumber
description: Registration number of the event parked vehicle
type: string
Expand All @@ -204,11 +202,11 @@ components:
description: The ID of the event area the event parking is assigned to
type: string
format: uuid
readOnly: true
readOnly: true
required:
- registration_number
- time_start
- event_area_id
- time_start
- event_area_id

Location:
description: Location in GeoJSON format
Expand All @@ -231,7 +229,7 @@ components:
items:
type: number
format: float

PaymentZone:
type: object
example:
Expand Down Expand Up @@ -660,7 +658,7 @@ paths:
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'

/event_parking/:
post:
tags: ['EventParkings']
Expand All @@ -670,11 +668,11 @@ paths:
requestBody:
required: true
description: >-
Event parking to add to the system. An active event area must be is assigned to the event parking.
The event area is assigned either based on the location or the event_area_id.
Event parking to add to the system. An active event area must be is assigned to the event parking.
The event area is assigned either based on the location or the event_area_id.
If event_area_id is not passed, the location must be inside an active event area.
The event area can be assigned by passing the id of the event area with the 'event_area_id' parameter.
If both location and evet_area_id is passed, the event_area_id will be used.
If both location and evet_area_id is passed, the event_area_id will be used.
content: &eventParkingBodyContent
application/json:
schema:
Expand All @@ -692,32 +690,32 @@ paths:
type: object
properties:
location:
<< : *eventParkingLocation
<< : *eventParkingLocation
registration_number:
<< : *eventParkingRegistrationNumber
time_start:
<< : *eventParkingTimeStart
time_end:
<< : *eventParkingTimeEnd
domain:
<< : *eventParkingDomain
<< : *eventParkingDomain
required:
- registration_number
- time_start
- time_start
oneOf:
- required:
- location
- required:
- event_area_id
- event_area_id
responses:
'201':
description: The event parking was created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/EventParking'
'400':
$ref: '#/components/responses/BadRequest'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
/event_parking/{event_parking_id}/:
Expand Down Expand Up @@ -778,7 +776,7 @@ paths:
time_end: "2016-12-25T22:00:00Z"
properties:
location:
<< : *eventParkingLocation
<< : *eventParkingLocation
registration_number:
<< : *eventParkingRegistrationNumber
time_start:
Expand All @@ -788,7 +786,7 @@ paths:
domain:
<< : *eventParkingDomain
event_area_id:
<< : *eventParkingEventAreaID
<< : *eventParkingEventAreaID
responses:
'200':
description: The event parking was updated successfully
Expand Down Expand Up @@ -826,9 +824,9 @@ paths:
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'



/payment_zone/:
get:
tags: ['Payment Zones']
Expand Down Expand Up @@ -1338,4 +1336,4 @@ paths:
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
$ref: '#/components/responses/NotFound'
Loading
Loading