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

Calendar Api Feed Source #215

Merged
merged 24 commits into from
Nov 22, 2024
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
11 changes: 11 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,14 @@ REDIS_CACHE_PREFIX=DisplayApiService
REDIS_CACHE_DSN=redis://redis:6379/0
###< redis ###

###> Calendar Api Feed Source ###
# See docs/calendar-api-feed.md for variable explainations.
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT=
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT=
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT=
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS='{}'
CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS='{}'
CALENDAR_API_FEED_SOURCE_DATE_FORMAT=
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE=
CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS=300
###< Calendar Api Feed Source ###
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- [#215](https://github.com/os2display/display-api-service/pull/215)
- Added calendar api feed type.
- [#223](https://github.com/os2display/display-api-service/pull/223)
- Added explicit fixtures to avoid false negatives in the test suite
- [#219](https://github.com/os2display/display-api-service/pull/219)
- Fixed psalm, test, coding standards and updated api spec.

- [#222](https://github.com/os2display/display-api-service/pull/222)
- Adds create, update, delete operations to feed-source endpoint.
- Adds data validation for feed source.
Expand Down
2 changes: 1 addition & 1 deletion config/api_platform/feed_source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resources:
_api_Feed_get_source_config:
class: ApiPlatform\Metadata\Get
method: GET
uriTemplate: '/feed_sources/{id}/config/{name}'
uriTemplate: '/feed-sources/{id}/config/{name}'
read: false
controller: App\Controller\FeedSourceConfigGetController
openapiContext:
Expand Down
6 changes: 5 additions & 1 deletion config/packages/cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ framework:
# Default expire set to 5 minutes
default_lifetime: 300

# Creates a "calendar.api.cache" service
calendar.api.cache:
adapter: cache.adapter.redis

# Creates a "auth.screen.cache" service
auth.screen.cache:
adapter: cache.adapter.redis
# Default expire set to 1 day
default_lifetime: 86400

# Creates a "interactive_slide.cache" service
# Creates an "interactive_slide.cache" service
interactive_slide.cache:
adapter: cache.adapter.redis
# Default expire set to 12 hours
Expand Down
11 changes: 11 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ services:
Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface: '@Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationFailureHandler'
Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface: '@Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler'

App\Feed\CalendarApiFeedType:
arguments:
$locationEndpoint: '%env(string:CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT)%'
$resourceEndpoint: '%env(string:CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT)%'
$eventEndpoint: '%env(string:CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT)%'
$customMappings: '%env(json:CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS)%'
$eventModifiers: '%env(json:CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS)%'
$dateFormat: '%env(string:CALENDAR_API_FEED_SOURCE_DATE_FORMAT)%'
$timezone: '%env(string:CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE)%'
$cacheExpireSeconds: '%env(int:CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS)%'

App\Service\KeyVaultService:
arguments:
$keyVaultSource: '%env(string:APP_KEY_VAULT_SOURCE)%'
Expand Down
189 changes: 189 additions & 0 deletions docs/calender-api-feed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Calendar API Feed

The CalendarApiFeedType retrieves locations, resources and events from 3 JSON endpoints
set in the environment variables:

```dotenv
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT=
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT=
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT=
```

## Mapping the json data

By default, the three endpoints should return data as follows:

### Locations

```json
[
{
"id": "Location Id 2",
"displayName": "Location display name 1"
},
{
"id": "Location Id 2",
"displayName": "Location display name 2"
}
]
```

* The `id` (Mapping key: LOCATION_ID) should be unique for the location and is used to identify it in the resource relation.
* The `displayName` (Mapping key: LOCATION_DISPLAY_NAME) is the name of the location in the admin.

### Resources

```json
[
{
"id": "Resource Id 1",
"locationId": "Location Id 1",
"displayName": "Resource 1",
"includedInEvents": true
},
{
"id": "Resource Id 2",
"locationId": "Location Id 1",
"displayName": "Resource 2",
"includedInEvents": false
}
]
```

* The `id` (Mapping key: RESOURCE_ID) should be unique for the resource.
* The `locationId` (Mapping key: RESOURCE_LOCATION_ID) is the id of the location the resource belongs to.
* The `displayName` (Mapping key: RESOURCE_DISPLAY_NAME) is the name the resource is presented by in templates and admin.
* The `includedInEvents` (Mapping key: RESOURCE_INCLUDED_IN_EVENTS) determines if the resource is included in the events
endpoint.
This property can be excluded in the data. If this is the case, it defaults to `true`.

### Events

```json
[
{
"title": "Event Title 1",
"startTime": "2025-02-15T13:00:00+02:00",
"endTime": "2025-02-15T13:30:00+02:00",
"resourceDisplayName": "Resource 1",
"resourceId": "Resource Id 1"
},
{
"title": "Event Title 2",
"startTime": "2025-02-15T15:00:00+02:00",
"endTime": "2025-02-15T15:30:00+02:00",
"resourceDisplayName": "Resource 1",
"resourceId": "Resource Id 1"
}
]
```

* The `title` (Mapping key: EVENT_TITLE) is the title of the event.
* The `startTime` (Mapping key: EVENT_START_TIME) is the start time of the event.
Should be formatted as an `ISO 8601 date`, e.g. `2004-02-15T15:00:00+02:00`.
* The `endTime` (Mapping key: EVENT_END_TIME) is the end time of the event.
Should be formatted as an `ISO 8601 date`, e.g. `2004-02-15T15:30:00+02:00`.
* The `resourceDisplayName` (Mapping key: EVENT_RESOURCE_ID) is display name of the resource the event belongs to.
* The `resourceId` (Mapping key: EVENT_RESOURCE_DISPLAY_NAME) is the id of the resource the event belongs to.

## Overriding mappings

Mappings can be overridden changing the following environment variable:

```dotenv
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS='{}'
```

E.g.

```dotenv
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS='{
"LOCATION_ID": "Example1",
"LOCATION_DISPLAY_NAME": "Example2",
"RESOURCE_ID": "Example3",
"RESOURCE_LOCATION_ID": "Example4",
"RESOURCE_DISPLAY_NAME": "Example5",
"RESOURCE_INCLUDED_IN_EVENTS": "Example6",
"EVENT_TITLE": "Example7",
"EVENT_START_TIME": "Example8",
"EVENT_END_TIME": "Example9",
"EVENT_RESOURCE_ID": "Example10",
"EVENT_RESOURCE_DISPLAY_NAME": "Example11"
}'
```

## Dates

By default, dates are assumed to be `Y-m-d\TH:i:sP` e.g. `2004-02-15T15:00:00+02:00`.

If another date format is supplied for the date fields, these can be set with:

```dotenv
CALENDAR_API_FEED_SOURCE_DATE_FORMAT=
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE=
```

E.g.

```dotenv
CALENDAR_API_FEED_SOURCE_DATE_FORMAT="m/d/YH:i:s"
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE="Europe/Copenhagen"
```

## Modifiers

Modifiers can be set up to modify the output of the feed.

Two types of modifiers are available:

* EXCLUDE_IF_TITLE_NOT_CONTAINS: Removes entries from the feed if the title not contain the trigger word.
* REPLACE_TITLE_IF_CONTAINS: Changes the title if it contains the trigger word.

Parameters:

* type: EXCLUDE_IF_TITLE_NOT_CONTAINS or REPLACE_TITLE_IF_CONTAINS
* id: Unique identifier for the modifier.
* title: Display name when showing the modifier in the admin.
* description: Help text for the modifier.
* activateInFeed: Should this filter be optional? If false the rule will always apply.
* trigger: The string that should trigger the modifier.
* replacement: The string to replace the title with.
* removeTrigger: Should the trigger word be filtered from the title?
* caseSensitive: Should the trigger word be case-sensitive?

Examples of modifiers:

```json
[
{
"type": "EXCLUDE_IF_TITLE_NOT_CONTAINS",
"id": "excludeIfNotContainsListe",
"title": "Vis kun begivenheder med (liste) i titlen.",
"description": "Denne mulighed fjerner begivenheder, der IKKE har (liste) i titlen. Den fjerner også (liste) fra titlen.",
"activateInFeed": true,
"trigger": "(liste)",
"removeTrigger": true,
"caseSensitive": false
},
{
"type": "REPLACE_TITLE_IF_CONTAINS",
"id": "replaceIfContainsOptaget",
"activateInFeed": false,
"trigger": "(optaget)",
"replacement": "Optaget",
"removeTrigger": true,
"caseSensitive": false
},
{
"type": "REPLACE_TITLE_IF_CONTAINS",
"id": "onlyShowAsOptaget",
"activateInFeed": true,
"title": "Overskriv alle titler med Optaget",
"description": "Denne mulighed viser alle titler som Optaget.",
"trigger": "",
"replacement": "Optaget",
"removeTrigger": false,
"caseSensitive": false
}
]
```
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ CLI_REDIRECT={{ getenv "APP_CLI_REDIRECT" "" }}
REDIS_CACHE_PREFIX={{ getenv "APP_CLI_REDIRECT" "DisplayApiService" }}
REDIS_CACHE_DSN={{ getenv "APP_CLI_REDIRECT" "redis://redis:6379/0" }}
###< redis ###

###> Calendar Api Feed Source ###
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT" "" }}
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT" "" }}
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT" "" }}
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS" "'{}'" }}
CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS" "'{}'" }}
CALENDAR_API_FEED_SOURCE_DATE_FORMAT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_FORMAT" "" }}
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE" "" }}
CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS={{ getenv "CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS" "300" }}
###< Calendar Api Feed Source ###
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ CLI_REDIRECT={{ getenv "APP_CLI_REDIRECT" "" }}
REDIS_CACHE_PREFIX={{ getenv "APP_CLI_REDIRECT" "DisplayApiService" }}
REDIS_CACHE_DSN={{ getenv "APP_CLI_REDIRECT" "redis://redis:6379/0" }}
###< redis ###

###> Calendar Api Feed Source ###
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT" "" }}
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT" "" }}
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT" "" }}
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS" "'{}'" }}
CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS" "'{}'" }}
CALENDAR_API_FEED_SOURCE_DATE_FORMAT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_FORMAT" "" }}
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE" "" }}
CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS={{ getenv "CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS" "300" }}
###< Calendar Api Feed Source ###
Loading