1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

remove the old 'mvc' folder - examples are not changed yet - add the 'di' package inside the mvc2 package - which will be renamed to 'mvc' on the next commit - new mvc.Application and some dublications removed - The new version will be version 9 because it will contain breaking changes (not to the end-developer's controllers but to the API they register them) - get ready for 'Christmas Edition' for believers

Former-commit-id: c7114233dee90ee308c0a3e77ec2ad0c361094b8
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-12-15 20:28:06 +02:00
parent 4e15f4ea88
commit 55dfd195e0
48 changed files with 984 additions and 3591 deletions

View File

@@ -10,17 +10,19 @@ import (
// TodoController is our TODO app's web controller.
type TodoController struct {
service todo.Service
Service todo.Service
session *sessions.Session
Session *sessions.Session
}
// OnActivate called once before the server ran, can bind custom
// things to the controller.
func (c *TodoController) OnActivate(ca *mvc.ControllerActivator) {
// BeforeActivate called once before the server ran, and before
// the routes and dependency binder builded.
// You can bind custom things to the controller, add new methods, add middleware,
// add dependencies to the struct or the method(s) and more.
func (c *TodoController) BeforeActivate(ca *mvc.ControllerActivator) {
// this could be binded to a controller's function input argument
// if any, or struct field if any:
ca.Bind(func(ctx iris.Context) todo.Item {
ca.Dependencies.Add(func(ctx iris.Context) todo.Item {
// ctx.ReadForm(&item)
var (
owner = ctx.PostValue("owner")
@@ -35,25 +37,30 @@ func (c *TodoController) OnActivate(ca *mvc.ControllerActivator) {
}
})
// ca.Router.Use(...).Done(...).Layout(...)
// TODO:(?)
// m := ca.Method("PutCompleteBy")
// m.Route.Use(...).Done(...) <- we don't have the route here but I can find something to solve this.
// m.Dependencies.Add(...)
}
// Get handles the GET: /todo route.
func (c *TodoController) Get() []todo.Item {
return c.service.GetByOwner(c.session.ID())
return c.Service.GetByOwner(c.Session.ID())
}
// PutCompleteBy handles the PUT: /todo/complete/{id:long} route.
func (c *TodoController) PutCompleteBy(id int64) int {
item, found := c.service.GetByID(id)
item, found := c.Service.GetByID(id)
if !found {
return iris.StatusNotFound
}
if item.OwnerID != c.session.ID() {
if item.OwnerID != c.Session.ID() {
return iris.StatusForbidden
}
if !c.service.Complete(item) {
if !c.Service.Complete(item) {
return iris.StatusBadRequest
}
@@ -62,11 +69,11 @@ func (c *TodoController) PutCompleteBy(id int64) int {
// Post handles the POST: /todo route.
func (c *TodoController) Post(newItem todo.Item) int {
if newItem.OwnerID != c.session.ID() {
if newItem.OwnerID != c.Session.ID() {
return iris.StatusForbidden
}
if err := c.service.Save(newItem); err != nil {
if err := c.Service.Save(newItem); err != nil {
return iris.StatusBadRequest
}
return iris.StatusOK