add create project branch endpoint

This commit is contained in:
Mitchell Rosen 2023-01-24 17:11:42 -05:00
parent 76dfe71b48
commit 07c725571d
3 changed files with 51 additions and 6 deletions

View File

@ -12,6 +12,7 @@ dependencies:
- base
- servant
- text
- unison-hash
ghc-options:
-Wall

View File

@ -10,21 +10,28 @@ module Unison.Share.API.Projects
-- ** Create project
CreateProjectAPI,
CreateProjectRequest (..),
CreateProjectResponse (..),
-- ** Create project branch
CreateProjectBranchAPI,
CreateProjectBranchRequest (..),
CreateProjectBranchResponse (..),
-- * Types
Project (..),
ServerProjectId (..),
)
where
import Data.Text (Text)
import GHC.Generics (Generic)
import Servant.API
import Unison.Hash32 (Hash32)
type ProjectsAPI =
GetProjectAPI
:<|> CreateProjectAPI
:<|> CreateProjectBranchAPI
------------------------------------------------------------------------------------------------------------------------
-- Get project
@ -67,18 +74,54 @@ data CreateProjectResponse
| CreateProjectResponseSuccess !Project
deriving stock (Eq, Show)
------------------------------------------------------------------------------------------------------------------------
-- Create project branch
-- | [@POST /create-project-branch@]: Create a project branch
type CreateProjectBranchAPI =
"create-project-branch"
:> ReqBody '[JSON] CreateProjectBranchRequest
:> Verb Post 200 '[JSON] CreateProjectBranchResponse
-- | @POST /create-project-branch@ request.
data CreateProjectBranchRequest = CreateProjectBranchRequest
{ projectId :: Text,
branchName :: Text,
branchCausalHash :: Hash32,
branchMergeTarget :: Maybe ProjectBranchIds
}
deriving stock (Eq, Show)
-- | @POST /create-project-branch@ response.
data CreateProjectBranchResponse
= -- | Request payload invalid.
CreateProjectBranchResponseBadRequest
| CreateProjectBranchResponseUnauthorized
| CreateProjectBranchResponseSuccess !ProjectBranch
deriving stock (Eq, Show)
------------------------------------------------------------------------------------------------------------------------
-- Types
-- | A project.
data Project = Project
{ id :: ServerProjectId,
{ id :: Text,
name :: Text
}
deriving stock (Eq, Generic, Show)
-- | A project id that was generated on the server.
newtype ServerProjectId = ServerProjectId
{ unServerProjectId :: Text
-- | A project branch.
data ProjectBranch = ProjectBranch
{ projectId :: Text,
projectName :: Text,
branchId :: Text,
branchName :: Text
}
deriving newtype (Eq, Show)
deriving stock (Eq, Generic, Show)
-- | A project id and branch id.
data ProjectBranchIds = ProjectBranchIds
{ projectId :: Text,
branchId :: Text
}
deriving stock (Eq, Generic, Show)

View File

@ -53,4 +53,5 @@ library
base
, servant
, text
, unison-hash
default-language: Haskell2010