Skip to content

Commit bd47f53

Browse files
authored
Merge pull request #215 from os2display/feature/calendar-api-feed-source
Calendar Api Feed Source
2 parents 53d0474 + 7093489 commit bd47f53

26 files changed

+1123
-147
lines changed

.env

+11
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ REDIS_CACHE_PREFIX=DisplayApiService
9292
REDIS_CACHE_DSN=redis://redis:6379/0
9393
###< redis ###
9494

95+
###> Calendar Api Feed Source ###
96+
# See docs/calendar-api-feed.md for variable explainations.
97+
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT=
98+
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT=
99+
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT=
100+
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS='{}'
101+
CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS='{}'
102+
CALENDAR_API_FEED_SOURCE_DATE_FORMAT=
103+
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE=
104+
CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS=300
105+
###< Calendar Api Feed Source ###

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#215](https://github.com/os2display/display-api-service/pull/215)
8+
- Added calendar api feed type.
79
- [#223](https://github.com/os2display/display-api-service/pull/223)
810
- Added explicit fixtures to avoid false negatives in the test suite
911
- [#219](https://github.com/os2display/display-api-service/pull/219)
1012
- Fixed psalm, test, coding standards and updated api spec.
11-
1213
- [#222](https://github.com/os2display/display-api-service/pull/222)
1314
- Adds create, update, delete operations to feed-source endpoint.
1415
- Adds data validation for feed source.

config/api_platform/feed_source.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ resources:
3333
_api_Feed_get_source_config:
3434
class: ApiPlatform\Metadata\Get
3535
method: GET
36-
uriTemplate: '/feed_sources/{id}/config/{name}'
36+
uriTemplate: '/feed-sources/{id}/config/{name}'
3737
read: false
3838
controller: App\Controller\FeedSourceConfigGetController
3939
openapiContext:

config/packages/cache.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ framework:
1717
# Default expire set to 5 minutes
1818
default_lifetime: 300
1919

20+
# Creates a "calendar.api.cache" service
21+
calendar.api.cache:
22+
adapter: cache.adapter.redis
23+
2024
# Creates a "auth.screen.cache" service
2125
auth.screen.cache:
2226
adapter: cache.adapter.redis
2327
# Default expire set to 1 day
2428
default_lifetime: 86400
2529

26-
# Creates a "interactive_slide.cache" service
30+
# Creates an "interactive_slide.cache" service
2731
interactive_slide.cache:
2832
adapter: cache.adapter.redis
2933
# Default expire set to 12 hours

config/services.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ services:
5151
Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface: '@Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationFailureHandler'
5252
Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface: '@Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler'
5353

54+
App\Feed\CalendarApiFeedType:
55+
arguments:
56+
$locationEndpoint: '%env(string:CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT)%'
57+
$resourceEndpoint: '%env(string:CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT)%'
58+
$eventEndpoint: '%env(string:CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT)%'
59+
$customMappings: '%env(json:CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS)%'
60+
$eventModifiers: '%env(json:CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS)%'
61+
$dateFormat: '%env(string:CALENDAR_API_FEED_SOURCE_DATE_FORMAT)%'
62+
$timezone: '%env(string:CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE)%'
63+
$cacheExpireSeconds: '%env(int:CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS)%'
64+
5465
App\Service\KeyVaultService:
5566
arguments:
5667
$keyVaultSource: '%env(string:APP_KEY_VAULT_SOURCE)%'

docs/calender-api-feed.md

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Calendar API Feed
2+
3+
The CalendarApiFeedType retrieves locations, resources and events from 3 JSON endpoints
4+
set in the environment variables:
5+
6+
```dotenv
7+
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT=
8+
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT=
9+
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT=
10+
```
11+
12+
## Mapping the json data
13+
14+
By default, the three endpoints should return data as follows:
15+
16+
### Locations
17+
18+
```json
19+
[
20+
{
21+
"id": "Location Id 2",
22+
"displayName": "Location display name 1"
23+
},
24+
{
25+
"id": "Location Id 2",
26+
"displayName": "Location display name 2"
27+
}
28+
]
29+
```
30+
31+
* The `id` (Mapping key: LOCATION_ID) should be unique for the location and is used to identify it in the resource relation.
32+
* The `displayName` (Mapping key: LOCATION_DISPLAY_NAME) is the name of the location in the admin.
33+
34+
### Resources
35+
36+
```json
37+
[
38+
{
39+
"id": "Resource Id 1",
40+
"locationId": "Location Id 1",
41+
"displayName": "Resource 1",
42+
"includedInEvents": true
43+
},
44+
{
45+
"id": "Resource Id 2",
46+
"locationId": "Location Id 1",
47+
"displayName": "Resource 2",
48+
"includedInEvents": false
49+
}
50+
]
51+
```
52+
53+
* The `id` (Mapping key: RESOURCE_ID) should be unique for the resource.
54+
* The `locationId` (Mapping key: RESOURCE_LOCATION_ID) is the id of the location the resource belongs to.
55+
* The `displayName` (Mapping key: RESOURCE_DISPLAY_NAME) is the name the resource is presented by in templates and admin.
56+
* The `includedInEvents` (Mapping key: RESOURCE_INCLUDED_IN_EVENTS) determines if the resource is included in the events
57+
endpoint.
58+
This property can be excluded in the data. If this is the case, it defaults to `true`.
59+
60+
### Events
61+
62+
```json
63+
[
64+
{
65+
"title": "Event Title 1",
66+
"startTime": "2025-02-15T13:00:00+02:00",
67+
"endTime": "2025-02-15T13:30:00+02:00",
68+
"resourceDisplayName": "Resource 1",
69+
"resourceId": "Resource Id 1"
70+
},
71+
{
72+
"title": "Event Title 2",
73+
"startTime": "2025-02-15T15:00:00+02:00",
74+
"endTime": "2025-02-15T15:30:00+02:00",
75+
"resourceDisplayName": "Resource 1",
76+
"resourceId": "Resource Id 1"
77+
}
78+
]
79+
```
80+
81+
* The `title` (Mapping key: EVENT_TITLE) is the title of the event.
82+
* The `startTime` (Mapping key: EVENT_START_TIME) is the start time of the event.
83+
Should be formatted as an `ISO 8601 date`, e.g. `2004-02-15T15:00:00+02:00`.
84+
* The `endTime` (Mapping key: EVENT_END_TIME) is the end time of the event.
85+
Should be formatted as an `ISO 8601 date`, e.g. `2004-02-15T15:30:00+02:00`.
86+
* The `resourceDisplayName` (Mapping key: EVENT_RESOURCE_ID) is display name of the resource the event belongs to.
87+
* The `resourceId` (Mapping key: EVENT_RESOURCE_DISPLAY_NAME) is the id of the resource the event belongs to.
88+
89+
## Overriding mappings
90+
91+
Mappings can be overridden changing the following environment variable:
92+
93+
```dotenv
94+
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS='{}'
95+
```
96+
97+
E.g.
98+
99+
```dotenv
100+
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS='{
101+
"LOCATION_ID": "Example1",
102+
"LOCATION_DISPLAY_NAME": "Example2",
103+
"RESOURCE_ID": "Example3",
104+
"RESOURCE_LOCATION_ID": "Example4",
105+
"RESOURCE_DISPLAY_NAME": "Example5",
106+
"RESOURCE_INCLUDED_IN_EVENTS": "Example6",
107+
"EVENT_TITLE": "Example7",
108+
"EVENT_START_TIME": "Example8",
109+
"EVENT_END_TIME": "Example9",
110+
"EVENT_RESOURCE_ID": "Example10",
111+
"EVENT_RESOURCE_DISPLAY_NAME": "Example11"
112+
}'
113+
```
114+
115+
## Dates
116+
117+
By default, dates are assumed to be `Y-m-d\TH:i:sP` e.g. `2004-02-15T15:00:00+02:00`.
118+
119+
If another date format is supplied for the date fields, these can be set with:
120+
121+
```dotenv
122+
CALENDAR_API_FEED_SOURCE_DATE_FORMAT=
123+
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE=
124+
```
125+
126+
E.g.
127+
128+
```dotenv
129+
CALENDAR_API_FEED_SOURCE_DATE_FORMAT="m/d/YH:i:s"
130+
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE="Europe/Copenhagen"
131+
```
132+
133+
## Modifiers
134+
135+
Modifiers can be set up to modify the output of the feed.
136+
137+
Two types of modifiers are available:
138+
139+
* EXCLUDE_IF_TITLE_NOT_CONTAINS: Removes entries from the feed if the title not contain the trigger word.
140+
* REPLACE_TITLE_IF_CONTAINS: Changes the title if it contains the trigger word.
141+
142+
Parameters:
143+
144+
* type: EXCLUDE_IF_TITLE_NOT_CONTAINS or REPLACE_TITLE_IF_CONTAINS
145+
* id: Unique identifier for the modifier.
146+
* title: Display name when showing the modifier in the admin.
147+
* description: Help text for the modifier.
148+
* activateInFeed: Should this filter be optional? If false the rule will always apply.
149+
* trigger: The string that should trigger the modifier.
150+
* replacement: The string to replace the title with.
151+
* removeTrigger: Should the trigger word be filtered from the title?
152+
* caseSensitive: Should the trigger word be case-sensitive?
153+
154+
Examples of modifiers:
155+
156+
```json
157+
[
158+
{
159+
"type": "EXCLUDE_IF_TITLE_NOT_CONTAINS",
160+
"id": "excludeIfNotContainsListe",
161+
"title": "Vis kun begivenheder med (liste) i titlen.",
162+
"description": "Denne mulighed fjerner begivenheder, der IKKE har (liste) i titlen. Den fjerner også (liste) fra titlen.",
163+
"activateInFeed": true,
164+
"trigger": "(liste)",
165+
"removeTrigger": true,
166+
"caseSensitive": false
167+
},
168+
{
169+
"type": "REPLACE_TITLE_IF_CONTAINS",
170+
"id": "replaceIfContainsOptaget",
171+
"activateInFeed": false,
172+
"trigger": "(optaget)",
173+
"replacement": "Optaget",
174+
"removeTrigger": true,
175+
"caseSensitive": false
176+
},
177+
{
178+
"type": "REPLACE_TITLE_IF_CONTAINS",
179+
"id": "onlyShowAsOptaget",
180+
"activateInFeed": true,
181+
"title": "Overskriv alle titler med Optaget",
182+
"description": "Denne mulighed viser alle titler som Optaget.",
183+
"trigger": "",
184+
"replacement": "Optaget",
185+
"removeTrigger": false,
186+
"caseSensitive": false
187+
}
188+
]
189+
```

infrastructure/itkdev/display-api-service/etc/confd/templates/env.local.tmpl

+11
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ CLI_REDIRECT={{ getenv "APP_CLI_REDIRECT" "" }}
5151
REDIS_CACHE_PREFIX={{ getenv "APP_CLI_REDIRECT" "DisplayApiService" }}
5252
REDIS_CACHE_DSN={{ getenv "APP_CLI_REDIRECT" "redis://redis:6379/0" }}
5353
###< redis ###
54+
55+
###> Calendar Api Feed Source ###
56+
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT" "" }}
57+
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT" "" }}
58+
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT" "" }}
59+
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS" "'{}'" }}
60+
CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS" "'{}'" }}
61+
CALENDAR_API_FEED_SOURCE_DATE_FORMAT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_FORMAT" "" }}
62+
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE" "" }}
63+
CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS={{ getenv "CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS" "300" }}
64+
###< Calendar Api Feed Source ###

infrastructure/os2display/display-api-service/etc/confd/templates/env.local.tmpl

+11
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ CLI_REDIRECT={{ getenv "APP_CLI_REDIRECT" "" }}
5151
REDIS_CACHE_PREFIX={{ getenv "APP_CLI_REDIRECT" "DisplayApiService" }}
5252
REDIS_CACHE_DSN={{ getenv "APP_CLI_REDIRECT" "redis://redis:6379/0" }}
5353
###< redis ###
54+
55+
###> Calendar Api Feed Source ###
56+
CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_LOCATION_ENDPOINT" "" }}
57+
CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_RESOURCE_ENDPOINT" "" }}
58+
CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_ENDPOINT" "" }}
59+
CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_CUSTOM_MAPPINGS" "'{}'" }}
60+
CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS={{ getenv "APP_CALENDAR_API_FEED_SOURCE_EVENT_MODIFIERS" "'{}'" }}
61+
CALENDAR_API_FEED_SOURCE_DATE_FORMAT={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_FORMAT" "" }}
62+
CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE={{ getenv "APP_CALENDAR_API_FEED_SOURCE_DATE_TIMEZONE" "" }}
63+
CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS={{ getenv "CALENDAR_API_FEED_SOURCE_CACHE_EXPIRE_SECONDS" "300" }}
64+
###< Calendar Api Feed Source ###

0 commit comments

Comments
 (0)