Skip to content

Commit 5e14558

Browse files
✨ 🗃️ adding projects_comments DB table and API endpoints (#4383)
1 parent 1db71f9 commit 5e14558

File tree

12 files changed

+1435
-0
lines changed

12 files changed

+1435
-0
lines changed
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
paths:
2+
/projects/{project_uuid}/comments:
3+
get:
4+
tags:
5+
- project
6+
- comments
7+
summary: Retrieve all comments for a specific project.
8+
operationId: list_project_comments
9+
parameters:
10+
- required: true
11+
schema:
12+
title: Project Uuid
13+
type: string
14+
format: uuid
15+
name: project_uuid
16+
in: path
17+
- required: false
18+
schema:
19+
title: Limit
20+
type: integer
21+
default: 20
22+
name: limit
23+
in: query
24+
- required: false
25+
schema:
26+
title: Offset
27+
minimum: 0
28+
type: integer
29+
default: 0
30+
name: offset
31+
in: query
32+
responses:
33+
'200':
34+
description: Successful Response
35+
content:
36+
application/json:
37+
schema:
38+
$ref: '#/components/schemas/Envelope_list_models_library.projects_comments.ProjectsCommentsAPI__'
39+
post:
40+
tags:
41+
- project
42+
- comments
43+
summary: Create a new comment for a specific project. The request body should
44+
contain the comment contents and user information.
45+
operationId: create_project_comment
46+
parameters:
47+
- required: true
48+
schema:
49+
title: Project Uuid
50+
type: string
51+
format: uuid
52+
name: project_uuid
53+
in: path
54+
requestBody:
55+
content:
56+
application/json:
57+
schema:
58+
$ref: '#/components/schemas/_ProjectCommentsBodyParams'
59+
required: true
60+
responses:
61+
'201':
62+
description: Successful Response
63+
content:
64+
application/json:
65+
schema:
66+
$ref: '#/components/schemas/Envelope_dict_Literal__comment_id____pydantic.types.PositiveInt__'
67+
/projects/{project_uuid}/comments/{comment_id}:
68+
get:
69+
tags:
70+
- project
71+
- comments
72+
summary: Retrieve a specific comment by its ID within a project.
73+
operationId: get_project_comment
74+
parameters:
75+
- required: true
76+
schema:
77+
title: Project Uuid
78+
type: string
79+
format: uuid
80+
name: project_uuid
81+
in: path
82+
- required: true
83+
schema:
84+
title: Comment Id
85+
exclusiveMinimum: true
86+
type: integer
87+
minimum: 0
88+
name: comment_id
89+
in: path
90+
responses:
91+
'200':
92+
description: Successful Response
93+
content:
94+
application/json:
95+
schema:
96+
$ref: '#/components/schemas/Envelope_ProjectsCommentsAPI_'
97+
put:
98+
tags:
99+
- project
100+
- comments
101+
summary: Update the contents of a specific comment for a project. The request
102+
body should contain the updated comment contents.
103+
operationId: update_project_comment
104+
parameters:
105+
- required: true
106+
schema:
107+
title: Project Uuid
108+
type: string
109+
format: uuid
110+
name: project_uuid
111+
in: path
112+
- required: true
113+
schema:
114+
title: Comment Id
115+
exclusiveMinimum: true
116+
type: integer
117+
minimum: 0
118+
name: comment_id
119+
in: path
120+
requestBody:
121+
content:
122+
application/json:
123+
schema:
124+
$ref: '#/components/schemas/_ProjectCommentsBodyParams'
125+
required: true
126+
responses:
127+
'200':
128+
description: Successful Response
129+
content:
130+
application/json:
131+
schema:
132+
$ref: '#/components/schemas/Envelope_ProjectsCommentsAPI_'
133+
delete:
134+
tags:
135+
- project
136+
- comments
137+
summary: Delete a specific comment associated with a project.
138+
operationId: delete_project_comment
139+
parameters:
140+
- required: true
141+
schema:
142+
title: Project Uuid
143+
type: string
144+
format: uuid
145+
name: project_uuid
146+
in: path
147+
- required: true
148+
schema:
149+
title: Comment Id
150+
exclusiveMinimum: true
151+
type: integer
152+
minimum: 0
153+
name: comment_id
154+
in: path
155+
responses:
156+
'204':
157+
description: Successful Response
158+
components:
159+
schemas:
160+
Envelope_ProjectsCommentsAPI_:
161+
title: Envelope[ProjectsCommentsAPI]
162+
type: object
163+
properties:
164+
data:
165+
$ref: '#/components/schemas/ProjectsCommentsAPI'
166+
error:
167+
title: Error
168+
Envelope_dict_Literal__comment_id____pydantic.types.PositiveInt__:
169+
title: Envelope[dict[Literal['comment_id'], pydantic.types.PositiveInt]]
170+
type: object
171+
properties:
172+
data:
173+
title: Data
174+
type: object
175+
additionalProperties:
176+
exclusiveMinimum: true
177+
type: integer
178+
minimum: 0
179+
error:
180+
title: Error
181+
Envelope_list_models_library.projects_comments.ProjectsCommentsAPI__:
182+
title: Envelope[list[models_library.projects_comments.ProjectsCommentsAPI]]
183+
type: object
184+
properties:
185+
data:
186+
title: Data
187+
type: array
188+
items:
189+
$ref: '#/components/schemas/ProjectsCommentsAPI'
190+
error:
191+
title: Error
192+
ProjectsCommentsAPI:
193+
title: ProjectsCommentsAPI
194+
required:
195+
- comment_id
196+
- project_uuid
197+
- user_id
198+
- content
199+
- created
200+
- modified
201+
type: object
202+
properties:
203+
comment_id:
204+
title: Comment Id
205+
exclusiveMinimum: true
206+
type: integer
207+
description: Primary key, identifies the comment
208+
minimum: 0
209+
project_uuid:
210+
title: Project Uuid
211+
type: string
212+
description: project reference for this table
213+
format: uuid
214+
user_id:
215+
title: User Id
216+
exclusiveMinimum: true
217+
type: integer
218+
description: user reference for this table
219+
minimum: 0
220+
content:
221+
title: Content
222+
type: string
223+
description: Content of the comment
224+
created:
225+
title: Created
226+
type: string
227+
description: Timestamp on creation
228+
format: date-time
229+
modified:
230+
title: Modified
231+
type: string
232+
description: Timestamp with last update
233+
format: date-time
234+
additionalProperties: false
235+
_ProjectCommentsBodyParams:
236+
title: _ProjectCommentsBodyParams
237+
required:
238+
- contents
239+
type: object
240+
properties:
241+
contents:
242+
title: Contents
243+
type: string
244+
additionalProperties: false

api/specs/webserver/openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ paths:
233233
/projects/{project_id}/nodes/{node_id}/resources:
234234
$ref: "./openapi-projects.yaml#/paths/~1projects~1{project_id}~1nodes~1{node_id}~1resources"
235235

236+
/projects/{project_uuid}/comments:
237+
$ref: "./openapi-projects-comments.yaml#/paths/~1projects~1{project_uuid}~1comments"
238+
239+
/projects/{project_uuid}/comments/{comment_id}:
240+
$ref: "./openapi-projects-comments.yaml#/paths/~1projects~1{project_uuid}~1comments~1{comment_id}"
241+
236242
/projects/{project_id}/nodes/-/services:access:
237243
$ref: "./openapi-projects-nodes.yaml#/paths/~1projects~1{project_id}~1nodes~1-~1services:access"
238244

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
""" Helper script to automatically generate OAS
2+
3+
This OAS are the source of truth
4+
"""
5+
6+
# pylint: disable=redefined-outer-name
7+
# pylint: disable=unused-argument
8+
# pylint: disable=unused-variable
9+
# pylint: disable=too-many-arguments
10+
11+
12+
from enum import Enum
13+
from typing import Literal
14+
15+
from _common import (
16+
CURRENT_DIR,
17+
assert_handler_signature_against_model,
18+
create_openapi_specs,
19+
)
20+
from fastapi import FastAPI
21+
from models_library.generics import Envelope
22+
from models_library.projects import ProjectID
23+
from models_library.projects_comments import CommentID, ProjectsCommentsAPI
24+
from pydantic import NonNegativeInt
25+
from simcore_service_webserver.projects._handlers_project_comments import (
26+
_ProjectCommentsBodyParams,
27+
_ProjectCommentsPathParams,
28+
_ProjectCommentsWithCommentPathParams,
29+
)
30+
31+
app = FastAPI(redoc_url=None)
32+
33+
TAGS: list[str | Enum] = ["project", "comments"]
34+
35+
36+
#
37+
# API entrypoints
38+
#
39+
40+
41+
@app.post(
42+
"/projects/{project_uuid}/comments",
43+
response_model=Envelope[dict[Literal["comment_id"], CommentID]],
44+
tags=TAGS,
45+
operation_id="create_project_comment",
46+
summary="Create a new comment for a specific project. The request body should contain the comment contents and user information.",
47+
status_code=201,
48+
)
49+
async def create_project_comment(
50+
project_uuid: ProjectID, body: _ProjectCommentsBodyParams
51+
):
52+
...
53+
54+
55+
assert_handler_signature_against_model(
56+
create_project_comment, _ProjectCommentsPathParams
57+
)
58+
59+
60+
@app.get(
61+
"/projects/{project_uuid}/comments",
62+
response_model=Envelope[list[ProjectsCommentsAPI]],
63+
tags=TAGS,
64+
operation_id="list_project_comments",
65+
summary="Retrieve all comments for a specific project.",
66+
)
67+
async def list_project_comments(
68+
project_uuid: ProjectID, limit: int = 20, offset: NonNegativeInt = 0
69+
):
70+
...
71+
72+
73+
assert_handler_signature_against_model(
74+
list_project_comments, _ProjectCommentsPathParams
75+
)
76+
77+
78+
@app.put(
79+
"/projects/{project_uuid}/comments/{comment_id}",
80+
response_model=Envelope[ProjectsCommentsAPI],
81+
tags=TAGS,
82+
operation_id="update_project_comment",
83+
summary="Update the contents of a specific comment for a project. The request body should contain the updated comment contents.",
84+
)
85+
async def update_project_comment(
86+
project_uuid: ProjectID,
87+
comment_id: CommentID,
88+
body: _ProjectCommentsBodyParams,
89+
):
90+
...
91+
92+
93+
assert_handler_signature_against_model(
94+
update_project_comment, _ProjectCommentsWithCommentPathParams
95+
)
96+
97+
98+
@app.delete(
99+
"/projects/{project_uuid}/comments/{comment_id}",
100+
tags=TAGS,
101+
operation_id="delete_project_comment",
102+
summary="Delete a specific comment associated with a project.",
103+
status_code=204,
104+
)
105+
async def delete_project_comment(project_uuid: ProjectID, comment_id: CommentID):
106+
...
107+
108+
109+
assert_handler_signature_against_model(
110+
delete_project_comment, _ProjectCommentsWithCommentPathParams
111+
)
112+
113+
114+
@app.get(
115+
"/projects/{project_uuid}/comments/{comment_id}",
116+
response_model=Envelope[ProjectsCommentsAPI],
117+
tags=TAGS,
118+
operation_id="get_project_comment",
119+
summary="Retrieve a specific comment by its ID within a project.",
120+
)
121+
async def get_project_comment(project_uuid: ProjectID, comment_id: CommentID):
122+
...
123+
124+
125+
assert_handler_signature_against_model(
126+
get_project_comment, _ProjectCommentsWithCommentPathParams
127+
)
128+
129+
130+
if __name__ == "__main__":
131+
132+
create_openapi_specs(app, CURRENT_DIR.parent / "openapi-projects-comments.yaml")

0 commit comments

Comments
 (0)