Base générale d'UI

This commit is contained in:
2019-12-01 22:12:13 +01:00
parent c6851f3f42
commit 048ef49933
49 changed files with 1913 additions and 88 deletions

View File

@ -0,0 +1,26 @@
package repository
type BoardRepository interface {
List() ([]*Board, error)
Get(BoardID) (*Board, error)
Save(*Board) error
Delete(BoardID) error
}
type BoardID string
type Board struct {
ID BoardID `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Lanes []*BoardLane `json:"lanes"`
Projects []string `json:"projects"`
}
type BoardLaneID string
type BoardLane struct {
ID BoardLaneID `json:"id"`
Title string `json:"title"`
IssueLabel string `json:"issueLabel"`
}

View File

@ -0,0 +1,9 @@
package repository
import "gitlab.com/wpetit/goweb/service"
func ServiceProvider(repository *Repository) service.Provider {
return func(ctn *service.Container) (interface{}, error) {
return repository, nil
}
}

View File

@ -0,0 +1,13 @@
package repository
type Repository struct {
boards BoardRepository
}
func (r *Repository) Boards() BoardRepository {
return r.boards
}
func NewRepository(boards BoardRepository) *Repository {
return &Repository{boards}
}

View File

@ -0,0 +1,33 @@
package repository
import (
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/service"
)
const ServiceName service.Name = "repository"
// From retrieves the repository service in the given container
func From(container *service.Container) (*Repository, error) {
service, err := container.Service(ServiceName)
if err != nil {
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
}
srv, ok := service.(*Repository)
if !ok {
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
}
return srv, nil
}
// Must retrieves the repository service in the given container or panic otherwise
func Must(container *service.Container) *Repository {
srv, err := From(container)
if err != nil {
panic(err)
}
return srv
}

View File

@ -0,0 +1,69 @@
package storm
import (
"forge.cadoles.com/wpetit/gitea-kan/internal/repository"
"github.com/asdine/storm"
"github.com/pkg/errors"
)
type BoardRepository struct {
db *storm.DB
}
type boardItem struct {
ID string `storm:"id"`
Board *repository.Board
}
func (r *BoardRepository) Init() error {
if err := r.db.Init(&boardItem{}); err != nil {
return errors.Wrap(err, "could not init 'boardItem' collection")
}
if err := r.db.ReIndex(&boardItem{}); err != nil {
return errors.Wrap(err, "could not reindex 'boardItem' collection")
}
return nil
}
func (r *BoardRepository) List() ([]*repository.Board, error) {
boardItems := make([]*boardItem, 0)
if err := r.db.All(&boardItems); err != nil {
return nil, errors.Wrap(err, "could not retrieve board items")
}
boards := make([]*repository.Board, 0, len(boardItems))
for _, b := range boardItems {
boards = append(boards, b.Board)
}
return boards, nil
}
func (r *BoardRepository) Get(id repository.BoardID) (*repository.Board, error) {
return nil, nil
}
func (r *BoardRepository) Save(board *repository.Board) error {
b := &boardItem{
ID: string(board.ID),
Board: board,
}
if err := r.db.Save(b); err != nil {
return errors.Wrap(err, "could not save board item")
}
return nil
}
func (r *BoardRepository) Delete(id repository.BoardID) error {
return nil
}
func NewBoardRepository(db *storm.DB) *BoardRepository {
return &BoardRepository{db}
}