Skip to content

Commit

Permalink
feat: created API schema & Lambda handler for user list in admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
KeitaMatsumoto2022 committed Jan 7, 2025
1 parent a66449e commit 4da8de5
Show file tree
Hide file tree
Showing 24 changed files with 955 additions and 2 deletions.
25 changes: 24 additions & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ generate-provider-schema: ## Generate provider schema
OUTPUT=oqtopus_cloud/provider/schemas
@$(MAKE) fmt-provider


generate-admin-schema: ## Generate admin schema
@cd oas && $(MAKE) generate-admin
@$(MAKE) generate \
INPUT=./oas/admin/openapi.yaml \
OUTPUT=oqtopus_cloud/admin/schemas
@$(MAKE) fmt-admin


generate:
@poetry run datamodel-codegen \
--use-schema-description \
Expand All @@ -42,6 +51,7 @@ generate:
generate-all-schema: ## Generate user and provider schemas
@$(MAKE) generate-user-schema
@$(MAKE) generate-provider-schema
@$(MAKE) generate-admin-schema

export ENV=local
export DB_HOST=localhost
Expand Down Expand Up @@ -77,6 +87,9 @@ fmt-user: ## Format user code
fmt-provider: ## Format provider code
@poetry run ruff format oqtopus_cloud/provider

fmt-admin: ## Format admin code
@poetry run ruff format oqtopus_cloud/admin

fmt-all: fmt-common fmt-user fmt-provider ## Format all code

lint-common: ## Run common linters
Expand All @@ -91,7 +104,11 @@ lint-provider: ## Run provider linters
@poetry run ruff check oqtopus_cloud/provider
@poetry run mypy -p oqtopus_cloud.provider

lint-all: lint-common lint-user lint-provider ## Run all linters
lint-admin: ## Run admin linters
@poetry run ruff check oqtopus_cloud/admin
@poetry run mypy -p oqtopus_cloud.admin

lint-all: lint-common lint-user lint-provider lint-admin ## Run all linters

test-common: fmt-common lint-common ## Run common tests
@export POWERTOOLS_METRICS_NAMESPACE=common && \
Expand All @@ -111,6 +128,12 @@ test-provider: fmt-provider lint-provider ## Run Provider tests
poetry run pytest tests/oqtopus_cloud/provider/ -vv --cov=oqtopus_cloud/provider --cov-report=xml:coverage-provider.xml --cov-report=html:htmlcov-provider
@mv .coverage .coverage-provider

test-admin: fmt-admin lint-admin ## Run admin tests
@export POWERTOOLS_METRICS_NAMESPACE=admin-api && \
export POWERTOOLS_SERVICE_NAME=admin-api && \
poetry run pytest tests/oqtopus_cloud/admin/ -vv --cov=oqtopus_cloud/admin --cov-report=xml:coverage-admin.xml --cov-report=html:htmlcov-admin
@mv .coverage .coverage-admin

test-all: fmt-all lint-all ## Run All tests
@export POWERTOOLS_METRICS_NAMESPACE=all && \
export POWERTOOLS_SERVICE_NAME=all && \
Expand Down
18 changes: 18 additions & 0 deletions backend/db/init/01.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,21 @@ CREATE TABLE IF NOT EXISTS main.jobs (
created_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

drop table if exists main.user;
CREATE TABLE IF NOT EXISTS user (
id serial PRIMARY KEY,
cognito_id VARCHAR(100) UNIQUE NOT NULL,
email VARCHAR(300) NOT NULL,
username VARCHAR(100),
userstatus Integer,
api_token_secret VARCHAR(100) UNIQUE,
organization VARCHAR(100),
purpose VARCHAR(100),
group_id VARCHAR(300),
require_mfa_reset BOOLEAN,
api_token_expiration TIMESTAMP,
created_at TIMESTAMP,
updated_at TIMESTAMP,
deleted_at TIMESTAMP
);
6 changes: 6 additions & 0 deletions backend/db/init/04.insert_userlist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INSERT INTO main.user (id, cognito_id, email, username, userstatus, api_token_secret, organization, purpose, group_id, require_mfa_reset, api_token_expiration, created_at, updated_at, deleted_at)
SELECT '1', '3704aaf8-a0e1-70c5-b5eb-e3879fd201dd', 'admin-email', 'admin', 1, 'admin-api_token_secret', 'admin-organization', 'admin-purpose', 'admin-group_id', false, '2021-01-01 00:00:05', '2021-01-01 00:00:00', '2021-01-01 00:00:01', '2031-01-01 00:00:09'
WHERE NOT EXISTS (SELECT * FROM main.user WHERE username = 'admin');
INSERT INTO main.user (id, cognito_id, email, username, userstatus, api_token_secret, organization, purpose, group_id, require_mfa_reset, api_token_expiration, created_at, updated_at, deleted_at)
SELECT '2', 'c7740a88-4011-70b9-f031-4656382f880e', '[email protected] ', 'admin2', 1, 'admin-api_token_secret2', 'admin-organization2', 'admin-purpose2', 'admin-group_id2', false, '2021-01-01 00:00:04', '2021-01-01 00:00:02', '2021-01-01 00:00:03', '2031-01-01 00:00:08'
WHERE NOT EXISTS (SELECT * FROM main.user WHERE username = 'admin2');
10 changes: 9 additions & 1 deletion backend/oas/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ lint-user: ## Lint user openapi.yaml
lint-provider: ## Lint provider openapi.yaml
@docker run --rm -v $(PWD):/spec redocly/cli lint provider/openapi.yaml

lint-admin: ## Lint provider openapi.yaml
@docker run --rm -v $(PWD):/spec redocly/cli lint admin/openapi.yaml

lint-all: lint-user lint-provider ## Lint user and provider

generate-user: ## Generate user openapi.yaml
Expand All @@ -22,7 +25,12 @@ generate-provider: ## Generate provider openapi.yaml
@docker run --rm -v $(PWD):/spec redocly/cli bundle /spec/provider/root.yaml -o /spec/provider/openapi.yaml
@$(MAKE) lint-provider

generate-all: generate-user generate-provider ## Generate user and provider openapi.yaml
generate-admin: ## Generate admin openapi.yaml
@docker pull redocly/cli
@docker run --rm -v $(PWD):/spec redocly/cli bundle /spec/admin/root.yaml -o /spec/admin/openapi.yaml
@$(MAKE) lint-admin

generate-all: generate-user generate-provider generate-admin ## Generate user and provider openapi.yaml

help: ## Show this help message
@echo "Usage: make [target]"
Expand Down
222 changes: 222 additions & 0 deletions backend/oas/admin/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
openapi: 3.0.1
info:
title: OQTOPUS Cloud User API
version: '1.0'
contact:
name: oqtopus-team
email: oqtopus-team[at]googlegroups.com
description: OQTOPUS Cloud User API. This API is used to interact with the OQTOPUS Cloud service. The API provides endpoints to manage devices, tasks, and results.
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: http://localhost:8080
description: Local server url
paths:
/users:
get:
tags:
- user
summary: get users
description: get users
operationId: getUsers
security: []
parameters:
- name: offset
in: query
description: offset information
required: false
schema:
type: string
- name: limit
in: query
description: Limit information
required: false
schema:
type: string
- name: email
in: query
description: query email infomation
required: false
schema:
type: string
- name: name
in: query
description: query name information
required: false
schema:
type: string
- name: organization
in: query
description: query organization information
required: false
schema:
type: string
- name: status
in: query
description: query user status
required: false
schema:
type: integer
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/users.GetUsersResponse'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/error.InternalServerError'
example:
detail: Internal Server Error
/users/{userId}:
put:
tags:
- user
summary: update user status
description: update user status
operationId: updatetUserStatusById
security: []
parameters:
- name: userId
in: path
description: User ID
required: true
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/user.UserUpdateStatusRequest'
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/user.GetOneUserResponse'
'404':
description: Not found
content:
application/json:
schema:
$ref: '#/components/schemas/error.NotFoundError'
example:
detail: User not found
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/error.InternalServerError'
example:
detail: Internal Server Error
delete:
tags:
- user
summary: delete user
description: delete user with designated id
operationId: deleteUserById
security: []
parameters:
- name: userId
in: path
description: User ID
required: true
schema:
type: integer
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/success.SuccessResponse'
example:
message: User deleted successfully
'404':
description: Not found
content:
application/json:
schema:
$ref: '#/components/schemas/error.NotFoundError'
example:
detail: User not found
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/error.InternalServerError'
example:
detail: Internal Server Error
components:
schemas:
user.GetOneUserResponse:
description: detail of users response
type: object
properties:
id:
type: string
email:
type: string
name:
type: string
organization:
type: string
status:
type: integer
format: int32
require_mfa_reset:
type: boolean
xml:
name: User
required:
- id
- email
users.GetUsersResponse:
properties:
Offset:
type: string
Limit:
type: string
users:
type: array
items:
$ref: '#/components/schemas/user.GetOneUserResponse'
error.InternalServerError:
type: object
properties:
detail:
type: string
required:
- detail
user.UserUpdateStatusRequest:
type: object
properties:
status:
type: string
enum:
- '1'
- '3'
description: 'status 1: active, 3: inactive'
error.NotFoundError:
type: object
properties:
detail:
type: string
required:
- detail
success.SuccessResponse:
type: object
properties:
message:
type: string
required:
- message
Loading

0 comments on commit 4da8de5

Please sign in to comment.