-
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
0a307dc
commit 4b3417c
Showing
9 changed files
with
128 additions
and
44 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,12 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zeiss/typhoon/internal/api/models" | ||
) | ||
|
||
// ListOperators ... | ||
func (db *database) ListOperators(ctx context.Context, pagination *models.Pagination[models.Operator]) error { | ||
return db.conn.WithContext(ctx).Scopes(models.Paginate(&pagination.Rows, pagination, db.conn)).Preload("SigningKeyGroups").Preload("SigningKeyGroups.Key").Preload("Key").Find(&pagination.Rows).Error | ||
} |
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
41 changes: 41 additions & 0 deletions
41
internal/web/controllers/operators/list_operators_controller.go
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,41 @@ | ||
package operators | ||
|
||
import ( | ||
"fmt" | ||
|
||
htmx "github.com/zeiss/fiber-htmx" | ||
"github.com/zeiss/typhoon/internal/api/models" | ||
"github.com/zeiss/typhoon/internal/web/components" | ||
"github.com/zeiss/typhoon/internal/web/ports" | ||
"github.com/zeiss/typhoon/pkg/resolvers" | ||
) | ||
|
||
var _ = htmx.Controller(&ListOperatorsController{}) | ||
|
||
// ListOperatorsController ... | ||
type ListOperatorsController struct { | ||
htmx.DefaultController | ||
} | ||
|
||
// NewListOperatorsController ... | ||
func NewListOperatorsController(db ports.Operators) *ListOperatorsController { | ||
return &ListOperatorsController{} | ||
} | ||
|
||
// Prepare ... | ||
func (l *ListOperatorsController) Get() error { | ||
ops := htmx.Values[models.Pagination[models.Operator]](l.Ctx().UserContext(), resolvers.ValuesKeyOperators) | ||
|
||
fmt.Println(ops) | ||
|
||
return htmx.RenderComp( | ||
l.Ctx(), | ||
components.Page( | ||
components.PageProps{}, | ||
components.Layout( | ||
components.LayoutProps{}, | ||
htmx.Text("Operators"), | ||
), | ||
), | ||
) | ||
} |
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,13 @@ | ||
package ports | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zeiss/typhoon/internal/api/models" | ||
) | ||
|
||
// Operators is a port that defines the methods for operators | ||
type Operators interface { | ||
// ListOperators is a method that returns a list of operators | ||
ListOperators(ctx context.Context, pagination *models.Pagination[models.Operator]) error | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ package ports | |
// Repository ... | ||
type Repository interface { | ||
Users | ||
Operators | ||
} |
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,42 @@ | ||
package resolvers | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
htmx "github.com/zeiss/fiber-htmx" | ||
"github.com/zeiss/typhoon/internal/api/models" | ||
"github.com/zeiss/typhoon/internal/web/ports" | ||
) | ||
|
||
const ( | ||
// ValuesKeyOperators ... | ||
ValuesKeyOperators = "user" | ||
) | ||
|
||
// ListOperators ... | ||
func ListOperators(db ports.Repository) htmx.ResolveFunc { | ||
return func(ctx *fiber.Ctx) (interface{}, interface{}, error) { | ||
query := struct { | ||
Limit int `json:"limit" xml:"limit" form:"limit"` | ||
Offset int `json:"offset" xml:"offset" form:"offset"` | ||
Search string `json:"search" xml:"search" form:"search"` | ||
}{} | ||
|
||
err := ctx.QueryParser(&query) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
ops := models.Pagination[models.Operator]{} | ||
|
||
ops.Limit = query.Limit | ||
ops.Offset = query.Offset | ||
ops.Search = query.Search | ||
|
||
err = db.ListOperators(ctx.Context(), &ops) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return ValuesKeyOperators, ops, nil | ||
} | ||
} |