fmt + lint + docs

This commit is contained in:
konrad 2018-07-21 15:28:09 +02:00 committed by kolaente
parent 9979b7e321
commit 0487889963
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
5 changed files with 21 additions and 9 deletions

View file

@ -108,12 +108,12 @@ Teams sind global, d.h. Ein Team kann mehrere Namespaces verwalten.
~~Ein zu lösendes Problem: Wie regelt man die Berechtigungen um Teams zu verwalten?~~ ~~Ein zu lösendes Problem: Wie regelt man die Berechtigungen um Teams zu verwalten?~~
* [ ] Namespaces * [x] Namespaces
* [x] Erstellen * [x] Erstellen
* [x] Ansehen * [x] Ansehen
* [x] Bearbeiten * [x] Bearbeiten
* [x] Löschen * [x] Löschen
* [ ] Teams hinzufügen. Der Nutzer kriegt nur Teams angezeigt die er erstellt hat. * [x] Teams hinzufügen. Der Nutzer kriegt nur Teams angezeigt die er erstellt hat.
* [x] Alle Listen eines Namespaces anzeigen * [x] Alle Listen eines Namespaces anzeigen
* [x] Listen * [x] Listen
* [x] Listen zu einem Namespace hinzufügen * [x] Listen zu einem Namespace hinzufügen

View file

@ -1,5 +1,6 @@
package models package models
// ReadAll implements the method to read all teams of a namespace
func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) { func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) {
// Check if the user can read the namespace // Check if the user can read the namespace
n, err := GetNamespaceByID(tn.NamespaceID) n, err := GetNamespaceByID(tn.NamespaceID)
@ -7,7 +8,7 @@ func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) {
return nil, err return nil, err
} }
if !n.CanRead(user) { if !n.CanRead(user) {
return nil, ErrNeedToHaveNamespaceReadAccess{NamespaceID:tn.NamespaceID, UserID:user.ID} return nil, ErrNeedToHaveNamespaceReadAccess{NamespaceID: tn.NamespaceID, UserID: user.ID}
} }
// Get the teams // Get the teams
@ -20,4 +21,4 @@ func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) {
Find(&all) Find(&all)
return all, err return all, err
} }

View file

@ -10,4 +10,4 @@ func (tn *TeamNamespace) CanCreate(user *User) bool {
func (tn *TeamNamespace) CanDelete(user *User) bool { func (tn *TeamNamespace) CanDelete(user *User) bool {
n, _ := GetNamespaceByID(tn.NamespaceID) n, _ := GetNamespaceByID(tn.NamespaceID)
return n.IsAdmin(user) return n.IsAdmin(user)
} }

View file

@ -10,6 +10,18 @@ import (
const paramTagName = "param" const paramTagName = "param"
/////////////////////////
// HOW THIS BINDER WORKS
/////////////////////////
// This binder binds all values inside the url to their respective fields in a struct. Those fields need to have a tag
// "param" with the name of the url placeholder which must be the same as in routes.
//
// Whenever one of the standard CRUD methods is invoked, this binder is called, which enables one handler method
// to handle all kinds of different urls with different parameters.
/////////////////////////
// ParamBinder binds parameters to a struct.
// Currently a working implementation, waiting to implement this officially into echo.
func ParamBinder(i interface{}, c echo.Context) (err error) { func ParamBinder(i interface{}, c echo.Context) (err error) {
// Default binder // Default binder
@ -77,9 +89,7 @@ func ParamBinder(i interface{}, c echo.Context) (err error) {
return return
} }
// This is kind of ugly, more a "feature proof", copied from the echo source code. // Binder represents a binder
// Workaround until the pr to implement this nativly in echo is merged.
type Binder struct{} type Binder struct{}
func (b *Binder) bindData(ptr interface{}, data map[string][]string, tag string) error { func (b *Binder) bindData(ptr interface{}, data map[string][]string, tag string) error {
@ -227,6 +237,7 @@ func setFloatField(value string, bitSize int, field reflect.Value) error {
return err return err
} }
// BindUnmarshaler type
type BindUnmarshaler interface { type BindUnmarshaler interface {
// UnmarshalParam decodes and assigns a value from an form or query param. // UnmarshalParam decodes and assigns a value from an form or query param.
UnmarshalParam(param string) error UnmarshalParam(param string) error

View file

@ -1,10 +1,10 @@
package crud package crud
import ( import (
"fmt"
"git.kolaente.de/konrad/list/models" "git.kolaente.de/konrad/list/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"fmt"
) )
// ReadOneWeb is the webhandler to get one object // ReadOneWeb is the webhandler to get one object