basic workspace model and repository implementation
This commit is contained in:
@@ -1,23 +1,44 @@
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from atst.database import db
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
from atst.models.workspace import Workspace
|
||||
|
||||
|
||||
class Workspaces(object):
|
||||
MOCK_WORKSPACES = [
|
||||
{
|
||||
"name": "Unclassified IaaS and PaaS for Defense Digital Service (DDS)",
|
||||
"id": "5966187a-eff9-44c3-aa15-4de7a65ac7ff",
|
||||
"task_order": {"number": 123456},
|
||||
"user_count": 23,
|
||||
}
|
||||
]
|
||||
# will a request have a TO association?
|
||||
# do we automatically create an entry for the request.creator in the
|
||||
# workspace_roles table?
|
||||
|
||||
@classmethod
|
||||
def create(cls, request, task_order, name=None):
|
||||
name = name or request.id
|
||||
return Workspace(request=request, task_order=task_order, name=name)
|
||||
|
||||
@classmethod
|
||||
def get(cls, workspace_id):
|
||||
return cls.MOCK_WORKSPACES[0]
|
||||
try:
|
||||
workspace = db.session.query(Workspace).filter_by(id=workspace_id).one()
|
||||
except NoResultFound:
|
||||
raise NotFoundError("workspace")
|
||||
|
||||
return workspace
|
||||
|
||||
@classmethod
|
||||
def get_many(cls):
|
||||
return cls.MOCK_WORKSPACES
|
||||
def get_by_request(cls, request):
|
||||
try:
|
||||
workspace = db.session.query(Workspace).filter_by(request=request).one()
|
||||
except NoResultFound:
|
||||
raise NotFoundError("workspace")
|
||||
|
||||
return workspace
|
||||
|
||||
|
||||
class Projects(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def create(cls, creator_id, body):
|
||||
pass
|
||||
@@ -67,6 +88,9 @@ class Projects(object):
|
||||
|
||||
class Members(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def create(cls, creator_id, body):
|
||||
pass
|
||||
|
||||
@@ -10,3 +10,4 @@ from .user import User
|
||||
from .workspace_role import WorkspaceRole
|
||||
from .pe_number import PENumber
|
||||
from .task_order import TaskOrder
|
||||
from .workspace import Workspace
|
||||
|
||||
19
atst/models/workspace.py
Normal file
19
atst/models/workspace.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from sqlalchemy import Column, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models.types import Id
|
||||
|
||||
|
||||
class Workspace(Base):
|
||||
__tablename__ = "workspaces"
|
||||
|
||||
id = Id()
|
||||
|
||||
request_id = Column(ForeignKey("requests.id"), nullable=False)
|
||||
request = relationship("Request")
|
||||
|
||||
task_order_id = Column(ForeignKey("task_order.id"), nullable=False)
|
||||
task_order = relationship("TaskOrder")
|
||||
|
||||
name = Column(String, unique=True)
|
||||
Reference in New Issue
Block a user