generated from ZEISS/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e7856b
commit 5c5fc72
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zeiss/fiber-goth/adapters" | ||
seed "github.com/zeiss/gorm-seed" | ||
"github.com/zeiss/knox/internal/models" | ||
"github.com/zeiss/knox/internal/ports" | ||
"github.com/zeiss/knox/pkg/utils" | ||
) | ||
|
||
var _ ProjectController = (*ProjectControllerImpl)(nil) | ||
|
||
// CreateProjectCommand ... | ||
type CreateProjectCommand struct { | ||
Team string `json:"team" form:"team"` | ||
Name string `json:"name" form:"name"` | ||
Description string `json:"description" form:"description"` | ||
} | ||
|
||
// ProjectControllerImpl ... | ||
type ProjectControllerImpl struct { | ||
store seed.Database[ports.ReadTx, ports.ReadWriteTx] | ||
} | ||
|
||
// ProjectController ... | ||
type ProjectController interface { | ||
// CreateProject ... | ||
CreateProject(ctx context.Context, cmd CreateProjectCommand) error | ||
} | ||
|
||
// NewProjectController ... | ||
func NewProjectController(store seed.Database[ports.ReadTx, ports.ReadWriteTx]) *ProjectControllerImpl { | ||
return &ProjectControllerImpl{store} | ||
} | ||
|
||
// CreateProject ... | ||
func (c *ProjectControllerImpl) CreateProject(ctx context.Context, cmd CreateProjectCommand) error { | ||
team := adapters.GothTeam{ | ||
Slug: cmd.Team, | ||
} | ||
|
||
err := c.store.ReadTx(ctx, func(ctx context.Context, tx ports.ReadTx) error { | ||
return tx.GetTeam(ctx, &team) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
project := models.Project{ | ||
Name: cmd.Name, | ||
Description: utils.StrPtr(cmd.Description), | ||
Team: team, | ||
} | ||
|
||
return c.store.ReadWriteTx(ctx, func(ctx context.Context, tx ports.ReadWriteTx) error { | ||
return tx.CreateProject(ctx, &project) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dto | ||
|
||
import ( | ||
"github.com/zeiss/knox/internal/controllers" | ||
openapi "github.com/zeiss/knox/pkg/apis" | ||
"github.com/zeiss/knox/pkg/utils" | ||
) | ||
|
||
// FromCreateProjectRequestObject ... | ||
func FromCreateProjectRequestObject(req openapi.CreateProjectRequestObject) controllers.CreateProjectCommand { | ||
return controllers.CreateProjectCommand{ | ||
Team: req.TeamId, | ||
Name: utils.PtrStr(req.Body.Name), | ||
Description: utils.PtrStr(req.Body.Description), | ||
} | ||
} | ||
|
||
// ToCreateProjectResponseObject ... | ||
func ToCreateProjectResponseObject() openapi.CreateProject201JSONResponse { | ||
res := openapi.CreateProject201JSONResponse{} | ||
|
||
return res | ||
} |