diff --git a/openapi.yaml b/openapi.yaml index 67fb202..888d71d 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -273,6 +273,8 @@ tags: description: Cases linked to a Beneficiary and a Project - name: Stories description: Survey responses, timeline updates, and instant updates — the primary content format + - name: Labels + description: Story Labels — an organisation's themes for coding Stories and survey responses - name: Story Categories description: Surveys — form templates used to create Stories - name: Project Story Categories @@ -6862,6 +6864,215 @@ paths: "422": $ref: '#/components/responses/UnprocessableEntity' + /labels: + get: + tags: [Labels] + summary: List your organisations' Labels + description: | + The Labels (Story Labels) of the organisations you belong to, by name: the ones the Label popup + on a Story offers. Organisations use them to code Stories and survey responses by theme. + operationId: listLabels + security: [{tokenAuth: []}] + parameters: + - name: charity_id + in: query + required: false + schema: { type: integer } + description: Only this organisation's Labels + - name: search + in: query + required: false + schema: { type: string } + description: Part of the name, case-insensitive + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + - $ref: '#/components/parameters/LastSyncDatetime' + responses: + "200": + description: A page of Labels, by name + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/PaginationEnvelope' + - type: object + properties: + data: + type: array + items: { $ref: '#/components/schemas/Label' } + "401": + $ref: '#/components/responses/Unauthorized' + "422": + $ref: '#/components/responses/UnprocessableEntity' + post: + tags: [Labels] + summary: Create a Label + description: Creates a Label for one of your organisations. + operationId: createLabel + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/LabelInput' + - required: [charity_id, name] + example: + charity_id: 913 + name: Housing + color: '#36ac9a' + privacy: only_charity_colleagues + responses: + "201": + description: The new Label + content: + application/json: + schema: { $ref: '#/components/schemas/Label' } + "401": + $ref: '#/components/responses/Unauthorized' + "403": + $ref: '#/components/responses/ForbiddenError' + "422": + $ref: '#/components/responses/UnprocessableEntityList' + /labels/{id}: + patch: + tags: [Labels] + summary: Change a Label + description: Renames a Label, changes its colour or privacy, or moves it to another of your organisations. Only the fields sent change. + operationId: updateLabel + security: [{tokenAuth: []}] + parameters: + - name: id + in: path + required: true + schema: { type: integer } + requestBody: + required: true + content: + application/json: + schema: { $ref: '#/components/schemas/LabelInput' } + example: + name: Safe housing + responses: + "200": + description: The Label + content: + application/json: + schema: { $ref: '#/components/schemas/Label' } + "401": + $ref: '#/components/responses/Unauthorized' + "403": + $ref: '#/components/responses/ForbiddenError' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' + /labels/{id}/stories: + get: + tags: [Labels] + summary: List a Label's Stories + description: | + The Stories and survey responses with this Label that you can see, newest first: ids and dates + only. Fetch one with GET /stories/{id}. + operationId: listLabelStories + security: [{tokenAuth: []}] + parameters: + - name: id + in: path + required: true + schema: { type: integer } + - $ref: '#/components/parameters/Page' + - $ref: '#/components/parameters/PerPage' + responses: + "200": + description: A page of labelled Stories + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/PaginationEnvelope' + - type: object + properties: + data: + type: array + items: + type: object + properties: + id: { type: integer } + actual_created_at: { type: string, format: date-time, description: Date Posted } + created_at: { type: string, format: date-time, description: Date Happened } + labelled_at: { type: string, format: date-time } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntity' + /stories/{story_id}/labels: + parameters: + - name: story_id + in: path + required: true + schema: { type: integer } + post: + tags: [Labels] + summary: Add a Label to a Story + description: Adds one of your organisations' Labels to a Story or survey response you can see. Adding one it already has changes nothing. + operationId: addStoryLabel + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [label_id] + properties: + label_id: { type: integer } + example: + label_id: 412 + responses: + "201": + description: The Label and the Story's Labels + content: + application/json: + schema: { $ref: '#/components/schemas/StoryLabelsResult' } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' + delete: + tags: [Labels] + summary: Take a Label off a Story + description: Takes a Label off a Story or survey response. Removing one it hasn't got changes nothing. + operationId: removeStoryLabel + security: [{tokenAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [label_id] + properties: + label_id: { type: integer } + example: + label_id: 412 + responses: + "200": + description: The Label and the Story's remaining Labels + content: + application/json: + schema: { $ref: '#/components/schemas/StoryLabelsResult' } + "401": + $ref: '#/components/responses/Unauthorized' + "404": + $ref: '#/components/responses/NotFound' + "422": + $ref: '#/components/responses/UnprocessableEntityList' /stories/{id}: get: tags: [Stories] @@ -28059,6 +28270,37 @@ components: type: string enum: [Person, Organisation, Animal, Object] + Label: + type: object + description: A Label (Story Label), one of an organisation's themes for coding Stories and survey responses + properties: + id: { type: integer, example: 412 } + name: { type: string, example: Housing } + color: { type: string, description: Hex colour, example: '#36ac9a' } + charity_id: { type: integer, description: The organisation that owns the Label, example: 913 } + user_id: { type: integer, nullable: true, description: Who created it } + privacy: + type: string + enum: [only_charity_colleagues, everyone] + description: Who may open the Label's page + created_at: { type: string, format: date-time } + updated_at: { type: string, format: date-time } + LabelInput: + type: object + properties: + charity_id: { type: integer, description: The organisation that owns the Label. Must be one you belong to. } + name: { type: string, maxLength: 255 } + color: { type: string, pattern: '^#[0-9a-fA-F]{6}$', description: 'Default #3595d5' } + privacy: { type: string, enum: [only_charity_colleagues, everyone], description: Default only_charity_colleagues } + StoryLabelsResult: + type: object + properties: + story_id: { type: integer } + label: { $ref: '#/components/schemas/Label' } + label_ids: + type: array + items: { type: integer } + description: Your organisations' Labels now on the Story Flag: type: object description: A Flag (Contact Flag) of the organisation @@ -28287,6 +28529,11 @@ components: id: type: integer example: 369011 + label_ids: + type: array + items: { type: integer } + description: The Labels (Story Labels) on the Story. Returned by GET /stories/{id}. + example: [412, 418] text: type: string nullable: true diff --git a/server.js b/server.js index e11b2f3..265fb1b 100644 --- a/server.js +++ b/server.js @@ -939,6 +939,7 @@ function buildDocsPage() {
Surveys Stories + Labels Story Metrics Media Gallery @@ -2473,6 +2474,79 @@ function buildDocsPage() { +Labels (Story Labels) let an organisation code Stories and survey responses by theme, e.g. Housing or Improved confidence. You can list, create and edit the Labels of the organisations you belong to, and add them only to Stories you can see. Another organisation's Label, or a Story you can't see, returns 404.
+privacy is who may open the Label's page: only_charity_colleagues (default) or everyone.
data: each Label's id, name, color, charity_id, user_id and privacy, by name, in the paginated envelope" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "422", cls: "response-4xx", desc: "per_page over 200" }
+ ], "The Labels the Label popup on a Story offers.")}
+ ${endpointCard("POST", "/labels", "Create a Label", true, [
+ { name: "charity_id", in: "body", type: "integer", required: true, desc: "The organisation that owns the Label" },
+ { name: "name", in: "body", type: "string", required: true, desc: "The theme, at most 255 characters" },
+ { name: "color", in: "body", type: "string", required: false, desc: "Hex colour such as #36ac9a. Default #3595d5" },
+ { name: "privacy", in: "body", type: "string", required: false, desc: "only_charity_colleagues or everyone" }
+ ], [
+ { code: "201", cls: "response-2xx", desc: "The Label" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "403", cls: "response-4xx", desc: "An organisation you aren't in" },
+ { code: "422", cls: "response-4xx", desc: "errors: a blank or long name, a bad colour or privacy" }
+ ])}
+ ${endpointCard("PATCH", "/labels/{id}", "Change a Label", true, [
+ { name: "id", in: "path", type: "integer", required: true, desc: "The Label" },
+ { name: "name", in: "body", type: "string", required: false, desc: "New name" },
+ { name: "color", in: "body", type: "string", required: false, desc: "New hex colour" },
+ { name: "privacy", in: "body", type: "string", required: false, desc: "only_charity_colleagues or everyone" },
+ { name: "charity_id", in: "body", type: "integer", required: false, desc: "Move it to another of your organisations" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "The Label" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "403", cls: "response-4xx", desc: "Moving it to an organisation you aren't in" },
+ { code: "404", cls: "response-4xx", desc: "Not one of your organisations' Labels" },
+ { code: "422", cls: "response-4xx", desc: "Invalid values" }
+ ], "Only the fields you send change.")}
+ ${endpointCard("GET", "/labels/{id}/stories", "List a Label's Stories", true, [
+ { name: "id", in: "path", type: "integer", required: true, desc: "The Label" },
+ { name: "page", in: "query", type: "integer", required: false, desc: "Page number" },
+ { name: "per_page", in: "query", type: "integer", required: false, desc: "Default 10, max 200" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "data: each Story's id, actual_created_at, created_at and labelled_at, newest first, in the paginated envelope" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "404", cls: "response-4xx", desc: "Not one of your organisations' Labels" }
+ ], "The Stories and survey responses with this Label that you can see: ids and dates only. Fetch one with GET /stories/{id}.")}
+ ${endpointCard("POST", "/stories/{story_id}/labels", "Add a Label to a Story", true, [
+ { name: "story_id", in: "path", type: "integer", required: true, desc: "The Story or survey response" },
+ { name: "label_id", in: "body", type: "integer", required: true, desc: "The Label" }
+ ], [
+ { code: "201", cls: "response-2xx", desc: "story_id, label and label_ids (your organisations' Labels now on the Story)" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "404", cls: "response-4xx", desc: "A Story you can't see, or a Label that isn't your organisations'" },
+ { code: "422", cls: "response-4xx", desc: "No label_id" }
+ ], "Adding a Label the Story already has changes nothing.")}
+ ${endpointCard("DELETE", "/stories/{story_id}/labels", "Take a Label off a Story", true, [
+ { name: "story_id", in: "path", type: "integer", required: true, desc: "The Story or survey response" },
+ { name: "label_id", in: "body", type: "integer", required: true, desc: "The Label" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "story_id, label and label_ids" },
+ { code: "401", cls: "response-4xx", desc: "Not authenticated" },
+ { code: "404", cls: "response-4xx", desc: "A Story you can't see, or a Label that isn't your organisations'" },
+ { code: "422", cls: "response-4xx", desc: "No label_id" }
+ ])}
+