Fixed parambinder

This commit is contained in:
konrad 2018-07-18 21:54:04 +02:00
parent de95ff40bf
commit 6618874441
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 29 additions and 5 deletions

View File

@ -176,6 +176,8 @@ doch auch in einer Funktion machbar sein.
* [ ] Bessere Fehlermeldungen wenn das Model was ankommt falsch ist und nicht geparst werden kann
* [ ] Fehlerhandling irgendwie besser machen. Zb mit "World error messages"? Sprich, die Methode ruft einfach auf obs die entsprechende Fehlermeldung gibt und zeigt sonst 500 an.
* [ ] Endpoints neu organisieren? Also zb `namespaces/:nID/lists/:lID/items/:iID` statt einzelnen Endpoints für alles
* [ ] Wenn die ID bei irgendeiner GetByID... Methode < 1 ist soll ein error not exist geworfen werden
* [ ] Validation der ankommenden structs
* [ ] "Apiformat" Methoden, damit in der Ausgabe zb kein Passwort drin ist..., oder created/updated von Nutzern... oder ownerID nicht drin ist sondern nur das ownerobject
* [x] Rechte überprüfen:

View File

@ -3,8 +3,8 @@ package models
// TeamNamespace defines the relationship between a Team and a Namespace
type TeamNamespace struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
TeamID int64 `xorm:"int(11) not null" json:"team_id" param:"teamid"`
NamespaceID int64 `xorm:"int(11) not null" json:"namespace_id" param:"namespaceid"`
TeamID int64 `xorm:"int(11) not null" json:"team_id" param:"team"`
NamespaceID int64 `xorm:"int(11) not null" json:"namespace_id" param:"namespace"`
Right NamespaceRight `xorm:"int(11)" json:"right"`
Created int64 `xorm:"created" json:"created"`

View File

@ -34,6 +34,7 @@ import (
apiv1 "git.kolaente.de/konrad/list/routes/api/v1"
_ "git.kolaente.de/konrad/list/routes/api/v1/swagger" // for docs generation
"git.kolaente.de/konrad/list/routes/crud"
"net/http"
)
// NewEcho registers a new Echo instance
@ -82,6 +83,27 @@ func RegisterRoutes(e *echo.Echo) {
a.POST("/login", apiv1.Login)
a.POST("/register", apiv1.RegisterUser)
a.POST("/test/:infi/:Käsebrot/blub/:gedöns", func(c echo.Context) error {
type testStruct struct {
Integ int64 `param:"infi" form:"infi"`
Cheese string `param:"Käsebrot"`
Kram string `param:"gedöns"`
Other string
Whooo int64
Blub float64
Test string `form:"test"`
}
t := testStruct{}
if err := crud.ParamBinder(&t, c); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
}
return c.JSON(http.StatusOK, &t)
})
// ===== Routes with Authetification =====
// Authetification
a.Use(middleware.JWT(models.Config.JWTLoginSecret))
@ -116,9 +138,9 @@ func RegisterRoutes(e *echo.Echo) {
namespaceTeamHandler := &crud.WebHandler{
CObject: &models.TeamNamespace{},
}
a.GET("/namespaces/:id/teams", namespaceTeamHandler.ReadAllWeb)
a.PUT("/namespaces/:namespaceid/teams", namespaceTeamHandler.CreateWeb)
a.DELETE("/namespaces/:namespaceid/teams/:teamid", namespaceTeamHandler.DeleteWeb)
a.GET("/namespaces/:namespace/teams", namespaceTeamHandler.ReadAllWeb)
a.PUT("/namespaces/:namespace/teams", namespaceTeamHandler.CreateWeb)
a.DELETE("/namespaces/:namespace/teams/:team", namespaceTeamHandler.DeleteWeb)
teamHandler := &crud.WebHandler{
CObject: &models.Team{},