Frontend basics
This commit is contained in:
parent
8565ce19fe
commit
e310930d9e
10 changed files with 607 additions and 58 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -10,6 +11,49 @@ class Request:
|
|||
commit_url: str
|
||||
changelist: List[str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Response:
|
||||
status: int
|
||||
|
||||
|
||||
class EntryKind(str, Enum):
|
||||
simple = "simple"
|
||||
complex = "complex"
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntrySimpleDTO:
|
||||
key: str
|
||||
value: str # mapowane na title/password
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntryComplexDTO:
|
||||
title: str
|
||||
username: str
|
||||
password: str
|
||||
url: Optional[str] = None
|
||||
notes: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class GroupDTO:
|
||||
name: str
|
||||
path: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntryNodeDTO:
|
||||
kind: EntryKind
|
||||
title: str
|
||||
path: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class NodeDTO:
|
||||
# Drzewo: grupa lub wpisy w grupach
|
||||
name: str
|
||||
path: str
|
||||
groups: List["NodeDTO"]
|
||||
entries: List[EntryNodeDTO]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Depends, Body, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi_utils.cbv import cbv
|
||||
|
||||
from app.api.models import Request, Response
|
||||
from app.api.models import *
|
||||
from app.web import PasswordsController
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
|
@ -17,3 +20,83 @@ async def health():
|
|||
@router.post("/ci", summary="CI Webhook")
|
||||
async def ci(request: Request):
|
||||
return Response(200)
|
||||
|
||||
|
||||
@cbv(router)
|
||||
class TreeController:
|
||||
svc: PasswordsController = Depends(PasswordsController.dep)
|
||||
|
||||
@router.get("/tree", response_model=NodeDTO)
|
||||
def get_tree(self) -> NodeDTO:
|
||||
return self.svc.get_tree()
|
||||
|
||||
@router.post("/group", response_model=GroupDTO)
|
||||
def create_group(
|
||||
self,
|
||||
name: str = Body(..., embed=True),
|
||||
parent_path: str | None = Body(None, embed=True),
|
||||
) -> GroupDTO:
|
||||
return self.svc.create_group(name=name, parent_path=parent_path)
|
||||
|
||||
@router.patch("/group/rename", response_model=GroupDTO)
|
||||
def rename_group(
|
||||
self,
|
||||
path: str = Body(..., embed=True),
|
||||
new_name: str = Body(..., embed=True),
|
||||
) -> GroupDTO:
|
||||
return self.svc.rename_group(path, new_name)
|
||||
|
||||
@router.delete("/group")
|
||||
def delete_group(
|
||||
self,
|
||||
path: str = Query(...),
|
||||
):
|
||||
self.svc.delete_group(path)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
@router.post("/entry", response_model=NodeDTO)
|
||||
def create_entry(
|
||||
self,
|
||||
kind: EntryKind = Body(..., embed=True),
|
||||
parent_path: str = Body(..., embed=True),
|
||||
data: dict = Body(..., embed=True),
|
||||
) -> NodeDTO:
|
||||
if kind == EntryKind.simple:
|
||||
dto = EntrySimpleDTO(**data)
|
||||
return self.svc.create_entry_simple(parent_path, dto)
|
||||
dto = EntryComplexDTO(**data)
|
||||
return self.svc.create_entry_complex(parent_path, dto)
|
||||
|
||||
@router.patch("/entry", response_model=NodeDTO)
|
||||
def update_entry(
|
||||
self,
|
||||
path: str = Body(..., embed=True),
|
||||
kind: EntryKind = Body(..., embed=True),
|
||||
data: dict = Body(..., embed=True),
|
||||
) -> NodeDTO:
|
||||
if kind == EntryKind.simple:
|
||||
dto = EntrySimpleDTO(**data)
|
||||
return self.svc.update_entry_simple(path, dto)
|
||||
dto = EntryComplexDTO(**data)
|
||||
return self.svc.update_entry_complex(path, dto)
|
||||
|
||||
@router.patch("/entry/move", response_model=NodeDTO)
|
||||
def move_entry(
|
||||
self,
|
||||
path: str = Body(..., embed=True),
|
||||
target_group_path: str = Body(..., embed=True),
|
||||
) -> NodeDTO:
|
||||
return self.svc.move_entry(path, target_group_path)
|
||||
|
||||
@router.delete("/entry")
|
||||
def delete_entry(
|
||||
self,
|
||||
path: str = Query(...),
|
||||
):
|
||||
self.svc.delete_entry(path)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
@router.post("/save")
|
||||
def save_changes(self):
|
||||
self.svc.save()
|
||||
return JSONResponse({"ok": True})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue