Skip to content

Implement Hitobito event retrieval endpoint #10386

Description

@eliaSchenker

The following endpoint is added, which allows searching events from Hitobito. Only events that the user manages are returned (that the user is Lagerleiter:in of).

// GET /api/hitobito/events

// Response
{
	"_links": {},
    "totalItems": 5,
    "_embedded": {
        "items": [
            {
                "_links": {},
                "_embedded": {},
                "id": 1234,
                "name": "Test Lager"
            }
            // ...
        ]
    }
}

Workflow

  1. Initialize OAuth (TBD)
  2. Retrieve events from the Hitobito API retrieving event participations of the current user, starting with the first page:
GET <base-url>/api/event_participations
?include=roles,event
&filter[participant_id][eq]=<hitobito_user_id>
&fields[event_participations]=active
&fields[events]=name
&fields[event_roles]=type
&page[number]=<page>
&page[size]=20

The fields[event_participations], fields[events]=name, fields[event_roles]=type params limit the fields that are returned, only including the specified fields. By default all fields of participations, events and event_roles would be returned, which results in a larger response body.

Example Response:

{
  "data": [
    {
      "id": "16904",
      "type": "event_participations",
      "attributes": {
        "active": true
      },
      "relationships": {
        "event": {
          "data": {
            "type": "events",
            "id": "2611"
          }
        },
        // ...
        "roles": {
          "data": [
            {
              "type": "event_roles",
              "id": "17996"
            }
          ]
        }
      }
    }
  ],
  "included": [
    {
      "id": "2611",
      "type": "events",
      "attributes": {
        "name": "Lumos + Iltis"
      },
      "relationships": {
	      // ...
      }
    },
    {
      "id": "17996",
      "type": "event_roles",
      "attributes": {
        "type": "Event::Camp::Role::Leader"
      },
      "relationships": {
        "participation": {
          "meta": {
            "included": false
          }
        }
      }
    }
  ],
  "links": {
     // ...
     "next": "/api/event_participations?fields%5Bevent_participations%5D=active&fields%5Bevent_roles%5D=type&fields%5Bevents%5D=name&filter%5Bparticipant_id%5D%5Beq%5D=2&include=roles%2Cevent&page%5Bnumber%5D=2&page%5Bsize%5D=20" // not set if there are no more pages
  },
  "meta": {}
}
  1. For every retrieved page, perform the following steps:
    1. Go through each participation
    2. Check whether one of the corresponding event roles has attributes.type = "Event::Camp::Role::Leader"
      1. If not, discard the participation
    3. Check whether the participation has attributes.active = true
      1. If not, discard the participation
    4. Add the event id and attributes.name to result array
  2. If the response contains links.next, increment the page and continue
  3. Otherwise, exit and return all gathered events

Implementation Note: Make sure that the role that identifies a user as a leader of an event (for MiData Event::Camp::Role::Leader) is configurable per different Hitobito provider, so that new supported instance (i.e. CeviDB) can be easily added in the future.

Optimally we would directly query the event name / filter the role when calling the api, but this is seemingly unsupported by Hitobito.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions