Skip to main content

User Contracts API

General notes

Api for operations regarding User Contracts.

Content

Users collection:

Single user:

Users collection

Create user contract

POST /api/v0/users/{user_id}/contracts

This method needs permission create on user-contracts.

Method for creating new User Contract.

Request

ParamTypeDescriptionRequirements
typestringUser's last nameRequired. Nullable. Must be an integer.
fromdateContract start dateRequired.
todateContract end dateNullable.
is_activeboolContract's activity flagIf new contract is set as active, old ones are automatically set as inactive. Default value is true.

NOTE: user_id is set automatically

POST /api/v0/users/1/contracts HTTP/1.1
Content-Type: application/json

{ "type": 4, "from": "2023-06-30", "is_active": true }


### Responses

#### 201 CREATED

New [User Contract](/docs/api/data-types/user-contract) was successfully created.

```json
POST /api/v0/users/1/contracts HTTP/1.1
Content-Type: application/json
Status-Code: 201

{
"id": 1,
"user_id": 1,
"type": 4,
"from": "2023-06-30T22:00:00.000000Z",
"to": null,
"is_active": true,
"created_at": "2023-07-01T13:45:56+0200",
"updated_at": "2023-07-01T13:45:56+0200"
}

422 UNPROCESSABLE ENTITY

Validation error occurred.

POST /api/v0/users/1/contracts HTTP/1.1
Content-Type: application/json
Status-Code: 422

{
"type": "ValidationError",
"message": "The given data was invalid.",
"id": "93190e47-1694-4782-95ac-db7041eb2b2c",
"errors": [
{
"field": "from",
"message": "Pole musí být vyplněno."
}
],
}

404 NOT FOUND


User Contracts index

GET /api/v0/users/{user_id}/contracts

This method needs permission read on users-contracts.

Get list of existing User Contracts.

Request

Index behaviourDefinition
Paginated by defaultNo
Sortingid, user_id, type, from, to, is_active, created_at, updated_at
Filtersid:enum, user_id:int, type:int, from:date, to:date, is_active:bool,created_at:dated, updated_at:date
GET /api/v0/users/1/contracts HTTP/1.1

Responses

200 OK

GET /api/v0/users/1/contracts HTTP/1.1
Content-Type: application/json
Status-Code: 200

{
"items": [
{
"id": 1,
"user_id": 1,
"type": 4,
"from": "2023-06-30T22:00:00.000000Z",
"to": null,
"is_active": true,
"created_at": "2023-07-01T13:45:56+0200",
"updated_at": "2023-07-01T13:45:56+0200"
}
]
}


Single user contract

User Contract detail

GET /api/v0/users/{user_id}/contract/{contract_id}

This method needs permission read on user-contracts.

Get User Contract detail.

Request

GET /api/v0/users/1/contracts/1 HTTP/1.1

Responses

200 OK

GET /api/v0/users/1/contracts/1 HTTP/1.1
Content-Type: application/json
Status-Code: 200

{
"id": 1,
"user_id": 1,
"type": 4,
"from": "2023-06-30T22:00:00.000000Z",
"to": null,
"is_active": true,
"created_at": "2023-07-01T13:45:56+0200",
"updated_at": "2023-07-01T13:45:56+0200"
}

404 NOT FOUND

GET /api/v0/users/1/contracts/2 HTTP/1.1
Content-Type: application/json
Status-Code: 404

{
"type": "NotFound",
"message": "Required model was not found.",
"id": "0cd85449-05fe-4866-9802-8192e6785fc7"
}

Update user contract

PUT/PATCH /api/v0/users/{user_id}/contracts/{contract_id}

This method needs permission update on user-contracts.

Method for updating User Contract data.

Request

ParamTypeDescriptionRequirements
typestringUser's last nameNullable. Must be an integer.
fromdateContract start date
todateContract end dateNullable.
is_activeboolContract's activity flagIf new contract is set as active, old ones are automatically set as inactive.

For PATCH method any field can be omitted.

PATCH /api/v0/users/1/contracts/1 HTTP/1.1
Content-Type: application/json

{
"to": "2023-08-08"
}

Responses

200 OK

PUT /api/v0/users/1 HTTP/1.1
Content-Type: application/json
Status-Code: 200

{
"id": 1,
"user_id": 1,
"type": 4,
"from": "2023-06-30T22:00:00.000000Z",
"to": "2023-08-08T22:00:00.000000Z",
"is_active": true,
"created_at": "2023-07-01T13:45:56+0200",
"updated_at": "2023-07-01T13:45:56+0200"
}

404 NOT FOUND

PUT /api/v0/users/2/contracts/2 HTTP/1.1
Content-Type: application/json
Status-Code: 404

{
"type": "NotFound",
"message": "Required model was not found.",
"id": "0cd85449-05fe-4866-9802-8192e6785fc7"
}

422 UNPROCESSABLE ENTITY

Validation error occurred.

PUT /api/v0/users/1/contracts/1 HTTP/1.1
Content-Type: application/json
Status-Code: 422

{
"type": "ValidationError",
"message": "The given data was invalid.",
"id": "5c99f70a-e400-44bb-9cd4-592b0a30e145",
"errors": [
{
"field": "type",
"message": "The type field must be of type integer."
}
]
}

Delete user contract

DELETE /api/v0/users/{user_id}/contracts/{contract_id}

This method needs permission delete on user-contracts.

Method for deleting User Contract.

Request

DELETE /api/v0/users/1/contracts/1 HTTP/1.1

Responses

204 NO CONTENT

DELETE /api/v0/users/1/contracts/1 HTTP/1.1
Status-Code: 204

404 NOT FOUND

DELETE /api/v0/users/1/contracts/2 HTTP/1.1
Content-Type: application/json
Status-Code: 404

{
"type": "NotFound",
"message": "Required model was not found.",
"id": "0cd85449-05fe-4866-9802-8192e6785fc7"
}