forked from stacklok/codegate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv1_models.py
More file actions
44 lines (33 loc) · 1.25 KB
/
v1_models.py
File metadata and controls
44 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from typing import Any, List, Optional
import pydantic
from codegate.db import models as db_models
class Workspace(pydantic.BaseModel):
name: str
is_active: bool
class ActiveWorkspace(Workspace):
# TODO: use a more specific type for last_updated
last_updated: Any
class ListWorkspacesResponse(pydantic.BaseModel):
workspaces: list[Workspace]
@classmethod
def from_db_workspaces(
cls, db_workspaces: List[db_models.WorkspaceActive])-> "ListWorkspacesResponse":
return cls(workspaces=[
Workspace(name=ws.name, is_active=ws.active_workspace_id is not None)
for ws in db_workspaces])
class ListActiveWorkspacesResponse(pydantic.BaseModel):
workspaces: list[ActiveWorkspace]
@classmethod
def from_db_workspaces(
cls, ws: Optional[db_models.ActiveWorkspace]) -> "ListActiveWorkspacesResponse":
if ws is None:
return cls(workspaces=[])
return cls(workspaces=[
ActiveWorkspace(name=ws.name,
is_active=True,
last_updated=ws.last_update)
])
class CreateWorkspaceRequest(pydantic.BaseModel):
name: str
class ActivateWorkspaceRequest(pydantic.BaseModel):
name: str