Base générale d'UI
This commit is contained in:
@ -11,6 +11,7 @@ type Config struct {
|
||||
Debug bool
|
||||
HTTP HTTPConfig
|
||||
Gitea GiteaConfig
|
||||
Data DataConfig
|
||||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
@ -29,6 +30,10 @@ type GiteaConfig struct {
|
||||
APIBaseURL string
|
||||
}
|
||||
|
||||
type DataConfig struct {
|
||||
DBPath string
|
||||
}
|
||||
|
||||
// NewFromFile retrieves the configuration from the given file
|
||||
func NewFromFile(filepath string) (*Config, error) {
|
||||
config := NewDefault()
|
||||
@ -52,9 +57,12 @@ func NewDefault() *Config {
|
||||
Debug: false,
|
||||
HTTP: HTTPConfig{
|
||||
Address: ":3000",
|
||||
PublicDir: "${GITEA_APP_PUBDIR}",
|
||||
PublicDir: "${GITEAKAN_HTTP_PUBDIR}",
|
||||
},
|
||||
Gitea: GiteaConfig{},
|
||||
Data: DataConfig{
|
||||
DBPath: "${GITEAKAN_DATA_DBPATH}",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
26
internal/repository/board.go
Normal file
26
internal/repository/board.go
Normal 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"`
|
||||
}
|
9
internal/repository/provider.go
Normal file
9
internal/repository/provider.go
Normal 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
|
||||
}
|
||||
}
|
13
internal/repository/repository.go
Normal file
13
internal/repository/repository.go
Normal 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}
|
||||
}
|
33
internal/repository/service.go
Normal file
33
internal/repository/service.go
Normal 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
|
||||
}
|
69
internal/repository/storm/board.go
Normal file
69
internal/repository/storm/board.go
Normal 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}
|
||||
}
|
46
internal/route/board.go
Normal file
46
internal/route/board.go
Normal file
@ -0,0 +1,46 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/gitea-kan/internal/repository"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
)
|
||||
|
||||
func serveBoards(w http.ResponseWriter, r *http.Request) {
|
||||
ctn := container.Must(r.Context())
|
||||
repo := repository.Must(ctn)
|
||||
|
||||
boards, err := repo.Boards().List()
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not retrieve boards list"))
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
if err := encoder.Encode(boards); err != nil {
|
||||
panic(errors.Wrap(err, "could not encode boards list"))
|
||||
}
|
||||
}
|
||||
|
||||
func saveBoard(w http.ResponseWriter, r *http.Request) {
|
||||
ctn := container.Must(r.Context())
|
||||
repo := repository.Must(ctn)
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
board := &repository.Board{}
|
||||
|
||||
if err := decoder.Decode(board); err != nil {
|
||||
panic(errors.Wrap(err, "could not decode board"))
|
||||
}
|
||||
|
||||
if err := repo.Boards().Save(board); err != nil {
|
||||
panic(errors.Wrap(err, "could not save board"))
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
if err := encoder.Encode(board); err != nil {
|
||||
panic(errors.Wrap(err, "could not encode board"))
|
||||
}
|
||||
}
|
@ -6,8 +6,6 @@ import (
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"forge.cadoles.com/wpetit/gitea-kan/internal/config"
|
||||
"forge.cadoles.com/wpetit/gitea-kan/internal/middleware"
|
||||
"github.com/pkg/errors"
|
||||
@ -32,12 +30,13 @@ func proxyAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
accessToken := sess.Get(middleware.SessionOAuth2AccessToken)
|
||||
|
||||
proxy := httputil.NewSingleHostReverseProxy(apiBaseURL)
|
||||
proxy.Director = func(r *http.Request) {
|
||||
r.Host = apiBaseURL.Host
|
||||
r.URL.Scheme = apiBaseURL.Scheme
|
||||
r.URL.Host = apiBaseURL.Host
|
||||
r.Header.Add("Authorization", fmt.Sprintf("token %s", accessToken))
|
||||
spew.Dump(r)
|
||||
proxy.Director = func(rr *http.Request) {
|
||||
rr.Host = apiBaseURL.Host
|
||||
rr.URL.Scheme = apiBaseURL.Scheme
|
||||
rr.URL.Host = apiBaseURL.Host
|
||||
rr.Method = r.Method
|
||||
rr.Header.Add("Accept", "application/json")
|
||||
rr.Header.Add("Authorization", fmt.Sprintf("token %s", accessToken))
|
||||
}
|
||||
|
||||
proxy.ServeHTTP(w, r)
|
||||
|
@ -19,7 +19,9 @@ func Mount(r *chi.Mux, config *config.Config) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middleware.Authenticate)
|
||||
r.Get("/logout", handleLogout)
|
||||
r.Get("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest)).ServeHTTP)
|
||||
r.Get("/api/boards", serveBoards)
|
||||
r.Post("/api/boards", saveBoard)
|
||||
r.Handle("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest)))
|
||||
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", html5PushStateHandler))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user