Skip to content

Commit

Permalink
chore: update api
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 14, 2024
1 parent 9c6596b commit 612a8ae
Show file tree
Hide file tree
Showing 8 changed files with 1,616 additions and 1,466 deletions.
122 changes: 41 additions & 81 deletions api/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,12 @@ paths:
schema:
$ref: "#/components/schemas/ErrorResponse"

/team:
/teams:
post:
tags:
- Teams
summary: Create a new team
operationId: createTeam
security:
- api_key: []
requestBody:
Expand Down Expand Up @@ -427,7 +428,7 @@ paths:
schema:
$ref: "#/components/schemas/ErrorResponse"

/team/{id}:
/teams/{teamId}:
get:
tags:
- Teams
Expand All @@ -436,11 +437,7 @@ paths:
security:
- api_key: []
parameters:
- in: path
name: id
required: true
schema:
type: string
- $ref: "#/components/parameters/teamId"
responses:
"200":
description: Successful response
Expand All @@ -465,14 +462,11 @@ paths:
tags:
- Teams
summary: Update a team
operationId: updateTeam
security:
- api_key: []
parameters:
- in: path
name: id
required: true
schema:
type: string
- $ref: "#/components/parameters/teamId"
requestBody:
content:
application/json:
Expand Down Expand Up @@ -502,14 +496,11 @@ paths:
tags:
- Teams
summary: Delete a team
operationId: deleteTeam
security:
- api_key: []
parameters:
- in: path
name: id
required: true
schema:
type: string
- $ref: "#/components/parameters/teamId"
responses:
"204":
description: Successful response
Expand All @@ -526,11 +517,14 @@ paths:
schema:
$ref: "#/components/schemas/ErrorResponse"

/project:
/teams/{teamId}/projects:
post:
tags:
- Projects
summary: Create a new project
operationId: createProject
parameters:
- $ref: "#/components/parameters/teamId"
security:
- api_key: []
requestBody:
Expand Down Expand Up @@ -560,6 +554,7 @@ paths:
security:
- api_key: []
parameters:
- $ref: "#/components/parameters/teamId"
- in: query
name: limit
schema:
Expand Down Expand Up @@ -598,7 +593,7 @@ paths:
schema:
$ref: "#/components/schemas/ErrorResponse"

/project/{id}:
/teams/{teamId}/projects/{projectId}:
get:
tags:
- Projects
Expand All @@ -607,11 +602,8 @@ paths:
security:
- api_key: []
parameters:
- in: path
name: id
required: true
schema:
type: string
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
responses:
"200":
description: Successful response
Expand All @@ -637,14 +629,11 @@ paths:
- Projects
summary: Update a project
operationId: updateProject
parameters:
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
security:
- api_key: []
parameters:
- in: path
name: id
required: true
schema:
type: string
requestBody:
content:
application/json:
Expand Down Expand Up @@ -675,14 +664,11 @@ paths:
- Projects
summary: Delete a project
operationId: deleteProject
parameters:
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
security:
- api_key: []
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
"204":
description: Successful response
Expand All @@ -699,19 +685,17 @@ paths:
schema:
$ref: "#/components/schemas/ErrorResponse"

/project/{projectId}/environment:
/teams/{teamId}/projects/{projectId}/environments:
post:
tags:
- Environments
summary: Create a new environment
operationId: createEnvironment
security:
- api_key: []
parameters:
- in: path
name: projectId
required: true
schema:
type: string
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
requestBody:
content:
application/json:
Expand Down Expand Up @@ -739,11 +723,8 @@ paths:
security:
- api_key: []
parameters:
- in: path
name: projectId
required: true
schema:
type: string
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
- in: query
name: limit
schema:
Expand Down Expand Up @@ -782,25 +763,18 @@ paths:
schema:
$ref: "#/components/schemas/ErrorResponse"

/project/{projectId}/environment/{environmentId}:
/teams/{teamId}/projects/{projectId}/environments/{environmentId}:
get:
tags:
- Environments
summary: Get an environment
operationId: getEnvironment
parameters:
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
- $ref: "#/components/parameters/environmentId"
security:
- api_key: []
parameters:
- in: path
name: projectId
required: true
schema:
type: string
- in: path
name: environmentId
required: true
schema:
type: string
responses:
"200":
description: Successful response
Expand All @@ -826,19 +800,12 @@ paths:
- Environments
summary: Update an environment
operationId: updateEnvironment
parameters:
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
- $ref: "#/components/parameters/environmentId"
security:
- api_key: []
parameters:
- in: path
name: projectId
required: true
schema:
type: string
- in: path
name: environmentId
required: true
schema:
type: string
requestBody:
content:
application/json:
Expand Down Expand Up @@ -869,19 +836,12 @@ paths:
- Environments
summary: Delete an environment
operationId: deleteEnvironment
parameters:
- $ref: "#/components/parameters/teamId"
- $ref: "#/components/parameters/projectId"
- $ref: "#/components/parameters/environmentId"
security:
- api_key: []
parameters:
- in: path
name: projectId
required: true
schema:
type: string
- in: path
name: environmentId
required: true
schema:
type: string
responses:
"204":
description: Successful response
Expand Down
24 changes: 10 additions & 14 deletions internal/adapters/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@ func (rw *writeTxImpl) CreateLock(ctx context.Context, lock *models.Lock) error
return rw.conn.Create(lock).Error
}

// // RunMigrations runs the database migrations.
// func (d *database) Migrate(ctx context.Context) error {
// return d.conn.WithContext(ctx).AutoMigrate(
// &adapters.GothSession{},
// &adapters.GothAccount{},
// &adapters.GothUser{},
// &adapters.GothTeam{},
// &models.Environment{},
// &models.Project{},
// &models.Lock{},
// &models.State{},
// )
// }

// DeleteLock deletes a lock.
func (rw *writeTxImpl) DeleteLock(ctx context.Context, lock *models.Lock) error {
return rw.conn.Delete(lock).Error
Expand Down Expand Up @@ -117,3 +103,13 @@ func (rw *writeTxImpl) UpdateState(ctx context.Context, state *models.State) err
func (rw *writeTxImpl) CreateSnapshot(ctx context.Context, snapshot *models.Snapshot) error {
return rw.conn.Create(snapshot).Error
}

// CreateTeam creates a new team.
func (rw *writeTxImpl) CreateTeam(ctx context.Context, team *adapters.GothTeam) error {
return rw.conn.Create(team).Error
}

// DeleteTeam deletes a team.
func (rw *writeTxImpl) DeleteTeam(ctx context.Context, team *adapters.GothTeam) error {
return rw.conn.Delete(team).Error
}
14 changes: 7 additions & 7 deletions internal/adapters/handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewAPIHandlers(locks controllers.LocksController, state controllers.StateCo

// Get system health status
// (GET /_health)
func (h *apiHandlers) GetHealth(ctx context.Context, requesta openapi.GetHealthRequestObject) (openapi.GetHealthResponseObject, error) {
return nil, nil
func (h *apiHandlers) GetHealth(ctx context.Context, request openapi.GetHealthRequestObject) (openapi.GetHealthResponseObject, error) {
return openapi.GetHealth200JSONResponse{}, nil // this is just up
}

// Get system readiness
Expand All @@ -44,7 +44,7 @@ func (h *apiHandlers) GetProjects(ctx context.Context, request openapi.GetProjec

// Create a new project
// (POST /project)
func (h *apiHandlers) PostProject(ctx context.Context, request openapi.PostProjectRequestObject) (openapi.PostProjectResponseObject, error) {
func (h *apiHandlers) CreateProject(ctx context.Context, request openapi.CreateProjectRequestObject) (openapi.CreateProjectResponseObject, error) {
return nil, nil
}

Expand Down Expand Up @@ -74,7 +74,7 @@ func (h *apiHandlers) GetEnvironments(ctx context.Context, request openapi.GetEn

// Create a new environment
// (POST /project/{projectId}/environment)
func (h *apiHandlers) PostProjectProjectIdEnvironment(ctx context.Context, request openapi.PostProjectProjectIdEnvironmentRequestObject) (openapi.PostProjectProjectIdEnvironmentResponseObject, error) {
func (h *apiHandlers) CreateEnvironment(ctx context.Context, request openapi.CreateEnvironmentRequestObject) (openapi.CreateEnvironmentResponseObject, error) {
return nil, nil
}

Expand Down Expand Up @@ -134,13 +134,13 @@ func (h *apiHandlers) GetTeams(ctx context.Context, request openapi.GetTeamsRequ

// Create a new team
// (POST /team)
func (h *apiHandlers) PostTeam(ctx context.Context, request openapi.PostTeamRequestObject) (openapi.PostTeamResponseObject, error) {
func (h *apiHandlers) CreateTeam(ctx context.Context, request openapi.CreateTeamRequestObject) (openapi.CreateTeamResponseObject, error) {
return nil, nil
}

// Delete a team
// (DELETE /team/{id})
func (h *apiHandlers) DeleteTeamId(ctx context.Context, request openapi.DeleteTeamIdRequestObject) (openapi.DeleteTeamIdResponseObject, error) {
func (h *apiHandlers) DeleteTeam(ctx context.Context, request openapi.DeleteTeamRequestObject) (openapi.DeleteTeamResponseObject, error) {
return nil, nil
}

Expand All @@ -152,7 +152,7 @@ func (h *apiHandlers) GetTeam(ctx context.Context, request openapi.GetTeamReques

// Update a team
// (PUT /team/{id})
func (h *apiHandlers) PutTeamId(ctx context.Context, request openapi.PutTeamIdRequestObject) (openapi.PutTeamIdResponseObject, error) {
func (h *apiHandlers) UpdateTeam(ctx context.Context, request openapi.UpdateTeamRequestObject) (openapi.UpdateTeamResponseObject, error) {
return nil, nil
}

Expand Down
21 changes: 21 additions & 0 deletions internal/controllers/team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package controllers

import (
seed "github.com/zeiss/gorm-seed"
"github.com/zeiss/knox/internal/ports"
)

var _ TeamController = (*TeamControllerImpl)(nil)

// TeamController ...
type TeamController interface{}

// TeamControllerImpl is the controller for teams.
type TeamControllerImpl struct {
store seed.Database[ports.ReadTx, ports.ReadWriteTx]
}

// NewTeamController returns a new instance of TeamController.
func NewTeamController(store seed.Database[ports.ReadTx, ports.ReadWriteTx]) *TeamControllerImpl {
return &TeamControllerImpl{store}
}
Loading

0 comments on commit 612a8ae

Please sign in to comment.