From 51b8fca9cb78a2ce8b81d18b5facd21744de593f Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 10:28:10 +0300 Subject: [PATCH 1/8] #1 Add Matchmaker API methods for SOA --- .../src/main/resources/static/openapi/api.yml | 89 +++++++++++++++++-- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/matchmaker/api/src/main/resources/static/openapi/api.yml b/matchmaker/api/src/main/resources/static/openapi/api.yml index aa55c5f7..178cf172 100644 --- a/matchmaker/api/src/main/resources/static/openapi/api.yml +++ b/matchmaker/api/src/main/resources/static/openapi/api.yml @@ -92,6 +92,39 @@ paths: application/json: schema: $ref: "#/components/schemas/GeneralError" + /people/{target_id}/attitudes/{attitude_kind}: + post: + tags: [SOA] + summary: Like or skip a suggestion + description: | + Does the same as /people/{target_id}/attitudes. + Exists just to defend SOA labs. + parameters: + - name: target_id + in: path + required: true + schema: + $ref: "#/components/schemas/PersonId" + - name: attitude_kind + in: path + required: true + schema: + $ref: "#/components/schemas/AttitudeKind" + responses: + 204: + description: Attitude was taken into account + 401: + description: No authentication + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" + 404: + description: Person is not found + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" /people/{person_id}/matches: get: tags: [Suggestions] @@ -131,6 +164,50 @@ paths: application/json: schema: $ref: "#/components/schemas/GeneralError" + /statistics/attitudes: + get: + tags: [SOA] + summary: Get attitudes statistics + description: Returns like/skip counters for each person + responses: + 200: + description: OK + content: + application/json: + schema: + type: array + items: + type: object + properties: + person_id: + $ref: "#/components/schemas/PersonId" + likes: + type: integer + description: Count of people liked by the person + format: int32 + minimum: 0 + skips: + type: integer + description: Count of people skipped by the person + format: int32 + minimum: 0 + required: + - person_id + - likes + - skips + uniqueItems: true + 401: + description: No authentication + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" + 403: + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" components: securitySchemes: bearerAuth: @@ -144,14 +221,16 @@ components: format: int64 minimum: 1 example: 12345678 + AttitudeKind: + type: string + enum: + - like + - skip Attitude: type: object properties: - verdict: - type: string - enum: - - like - - skip + kind: + $ref: "#/components/schemas/AttitudeKind" required: - verdict GeneralError: From 4dd5475dc1f74ee72e2658952e9e66e24891ac71 Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 10:39:38 +0300 Subject: [PATCH 2/8] #1 Add more Matchmaker API methods for SOA --- .../src/main/resources/static/openapi/api.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/matchmaker/api/src/main/resources/static/openapi/api.yml b/matchmaker/api/src/main/resources/static/openapi/api.yml index 178cf172..aa52887c 100644 --- a/matchmaker/api/src/main/resources/static/openapi/api.yml +++ b/matchmaker/api/src/main/resources/static/openapi/api.yml @@ -125,6 +125,32 @@ paths: application/json: schema: $ref: "#/components/schemas/GeneralError" + /attitudes: + delete: + tags: [SOA] + summary: Reset attitudes + description: Removes attitudes from the given person + parameters: + - name: source_id + in: query + required: true + schema: + $ref: "#/components/schemas/PersonId" + responses: + 204: + description: Attitudes was reset + 401: + description: No authentication + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" + 404: + description: Person is not found + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" /people/{person_id}/matches: get: tags: [Suggestions] From 7ab5a492719b154b37cb3317a03c402899cd2065 Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 10:41:01 +0300 Subject: [PATCH 3/8] #1 Make POST /people return 201 Created --- people/api/src/main/resources/static/openapi/api.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/people/api/src/main/resources/static/openapi/api.yml b/people/api/src/main/resources/static/openapi/api.yml index 3f64a99c..55592514 100644 --- a/people/api/src/main/resources/static/openapi/api.yml +++ b/people/api/src/main/resources/static/openapi/api.yml @@ -203,8 +203,8 @@ paths: schema: $ref: "#/components/schemas/PersonDraft" responses: - 200: - description: OK + 201: + description: Created content: application/json: schema: From 4cf29daa552324b8e7702d5b6e5b68643535cd72 Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 10:50:04 +0300 Subject: [PATCH 4/8] #1 Add idempotency for post requests --- .../api/src/main/resources/static/openapi/api.yml | 12 ++++++++++++ .../api/src/main/resources/static/openapi/api.yml | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/matchmaker/api/src/main/resources/static/openapi/api.yml b/matchmaker/api/src/main/resources/static/openapi/api.yml index aa52887c..a65a39b2 100644 --- a/matchmaker/api/src/main/resources/static/openapi/api.yml +++ b/matchmaker/api/src/main/resources/static/openapi/api.yml @@ -92,6 +92,12 @@ paths: application/json: schema: $ref: "#/components/schemas/GeneralError" + 409: + description: Attitude was already taken + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" /people/{target_id}/attitudes/{attitude_kind}: post: tags: [SOA] @@ -125,6 +131,12 @@ paths: application/json: schema: $ref: "#/components/schemas/GeneralError" + 409: + description: Attitude was already taken + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" /attitudes: delete: tags: [SOA] diff --git a/people/api/src/main/resources/static/openapi/api.yml b/people/api/src/main/resources/static/openapi/api.yml index 55592514..914bc7d4 100644 --- a/people/api/src/main/resources/static/openapi/api.yml +++ b/people/api/src/main/resources/static/openapi/api.yml @@ -196,6 +196,14 @@ paths: tags: [People] summary: Create a person description: Creates a person with given parameters + parameters: + - name: Idempotency-Key + in: header + required: true + schema: + type: string + format: uuid + example: 550e8400-e29b-41d4-a716-446655440000 requestBody: required: true content: @@ -221,6 +229,12 @@ paths: application/json: schema: $ref: "#/components/schemas/GeneralError" + 409: + description: If person was already created (Idempotency-Key duplicated) + content: + application/json: + schema: + $ref: "#/components/schemas/GeneralError" /people/{person_id}: get: tags: [People] From 6ee3c4bd592ac42c535abcdc4bcd43c23eab0bfa Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 11:10:59 +0300 Subject: [PATCH 5/8] #1 Add sorting for GET /people --- .../src/main/resources/static/openapi/api.yml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/people/api/src/main/resources/static/openapi/api.yml b/people/api/src/main/resources/static/openapi/api.yml index 914bc7d4..5b14b893 100644 --- a/people/api/src/main/resources/static/openapi/api.yml +++ b/people/api/src/main/resources/static/openapi/api.yml @@ -164,6 +164,16 @@ paths: required: false schema: $ref: "#/components/schemas/UpdateMoment" + - name: sort_by + in: query + description: Sorting keys + required: false + explode: false + schema: + type: array + items: + $ref: "#/components/schemas/PersonSortingKey" + uniqueItems: true responses: 200: description: OK @@ -435,6 +445,19 @@ components: - id - update_moment - $ref: "#/components/schemas/PersonDraft" + PersonSortingKey: + type: string + enum: + - first_name + - last_name + - height + - birthday + - updated + - -first_name + - -last_name + - -height + - -birthday + - -updated ZodiacSign: type: string description: Astrological sign, caclulated based on a birthday From 857bc8a1ba55e4eab7ec0ca6885930c85bb81a0b Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 11:26:11 +0300 Subject: [PATCH 6/8] #1 Add ADMIN security for some endpoints --- matchmaker/api/src/main/resources/static/openapi/api.yml | 4 ++++ people/api/src/main/resources/static/openapi/api.yml | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/matchmaker/api/src/main/resources/static/openapi/api.yml b/matchmaker/api/src/main/resources/static/openapi/api.yml index a65a39b2..6adeed65 100644 --- a/matchmaker/api/src/main/resources/static/openapi/api.yml +++ b/matchmaker/api/src/main/resources/static/openapi/api.yml @@ -142,6 +142,8 @@ paths: tags: [SOA] summary: Reset attitudes description: Removes attitudes from the given person + security: + - bearerAuth: [ADMIN] parameters: - name: source_id in: query @@ -207,6 +209,8 @@ paths: tags: [SOA] summary: Get attitudes statistics description: Returns like/skip counters for each person + security: + - bearerAuth: [ADMIN] responses: 200: description: OK diff --git a/people/api/src/main/resources/static/openapi/api.yml b/people/api/src/main/resources/static/openapi/api.yml index 5b14b893..07294001 100644 --- a/people/api/src/main/resources/static/openapi/api.yml +++ b/people/api/src/main/resources/static/openapi/api.yml @@ -5,7 +5,7 @@ info: servers: - url: /api/v1 security: - - bearerAuth: [] + - bearerAuth: [USER, ADMIN] paths: /monitoring/healthcheck: get: @@ -285,6 +285,8 @@ paths: tags: [People] summary: Delete person by id description: Deletes a person with a given id forever? + security: + - bearerAuth: [ADMIN] parameters: - name: person_id in: path From 153860ec7b1d0ccb2b75a917aa68a265ccbe451d Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 21 Sep 2024 11:29:36 +0300 Subject: [PATCH 7/8] #1 Inline people sorting keys --- .../src/main/resources/static/openapi/api.yml | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/people/api/src/main/resources/static/openapi/api.yml b/people/api/src/main/resources/static/openapi/api.yml index 07294001..283053da 100644 --- a/people/api/src/main/resources/static/openapi/api.yml +++ b/people/api/src/main/resources/static/openapi/api.yml @@ -172,7 +172,18 @@ paths: schema: type: array items: - $ref: "#/components/schemas/PersonSortingKey" + type: string + enum: + - first_name + - last_name + - height + - birthday + - updated + - -first_name + - -last_name + - -height + - -birthday + - -updated uniqueItems: true responses: 200: @@ -447,19 +458,6 @@ components: - id - update_moment - $ref: "#/components/schemas/PersonDraft" - PersonSortingKey: - type: string - enum: - - first_name - - last_name - - height - - birthday - - updated - - -first_name - - -last_name - - -height - - -birthday - - -updated ZodiacSign: type: string description: Astrological sign, caclulated based on a birthday From 423e14a9c9f38347657901538a7864b418b52abb Mon Sep 17 00:00:00 2001 From: Kimiega Date: Sat, 21 Sep 2024 11:35:50 +0300 Subject: [PATCH 8/8] lab-1 fix schema validation warnings --- people/api/src/main/resources/static/openapi/api.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/people/api/src/main/resources/static/openapi/api.yml b/people/api/src/main/resources/static/openapi/api.yml index 5b14b893..7ce63d54 100644 --- a/people/api/src/main/resources/static/openapi/api.yml +++ b/people/api/src/main/resources/static/openapi/api.yml @@ -90,14 +90,14 @@ paths: required: false schema: $ref: "#/components/schemas/PersonHeight" - example: 160 + example: 160 - name: height_max in: query description: Maximum height of a person required: false schema: $ref: "#/components/schemas/PersonHeight" - example: 180 + example: 180 - name: birthday_min in: query description: Minimum birthday of a person