-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpresentation.go
71 lines (63 loc) · 2.25 KB
/
presentation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"github.com/goadesign/goa"
"github.com/gopheracademy/congo/app"
"github.com/gopheracademy/congo/models"
"github.com/jinzhu/gorm"
)
// PresentationController implements theuser resource.
type PresentationController struct {
*goa.Controller
e *Env
storagelist map[string]Storage
storage models.PresentationStorage
}
// NewPresentationController creates a user controller.
func NewPresentationController(service *goa.Service, storagelist map[string]Storage, e *Env) *PresentationController {
return &PresentationController{
Controller: service.NewController("PresentationController"),
e: e,
storagelist: storagelist,
storage: storagelist["PRESENTATIONSTORAGE"].(models.PresentationStorage),
}
}
// Create runs the create action.
func (c *PresentationController) Create(ctx *app.CreatePresentationContext) error {
a := models.PresentationFromCreatePresentationPayload(ctx.Payload)
ra, err := c.storage.Add(ctx.Context, a)
if err != nil {
return ctx.Service.Send(ctx, 500, err.Error())
}
ctx.ResponseData.Header().Set("Location", app.PresentationHref(ctx.TenantID, ctx.EventID, ctx.SpeakerID, ra.ID))
return ctx.Created()
}
// Delete runs the delete action.
func (c *PresentationController) Delete(ctx *app.DeletePresentationContext) error {
err := c.storage.Delete(ctx.Context, ctx.PresentationID)
if err != nil {
return ctx.NotFound()
}
return ctx.NoContent()
}
// List runs the list action.
func (c *PresentationController) List(ctx *app.ListPresentationContext) error {
res := c.storage.ListPresentation(ctx.Context, ctx.EventID, ctx.SpeakerID)
return ctx.OK(res)
}
// Show runs the show action.
func (c *PresentationController) Show(ctx *app.ShowPresentationContext) error {
res, err := c.storage.OnePresentation(ctx.Context, ctx.PresentationID, ctx.EventID, ctx.SpeakerID)
if err != nil && err == gorm.ErrRecordNotFound {
return ctx.NotFound()
}
return ctx.OK(res)
}
// Update runs the update action.
func (c *PresentationController) Update(ctx *app.UpdatePresentationContext) error {
err := c.storage.UpdateFromUpdatePresentationPayload(ctx.Context, ctx.Payload, ctx.PresentationID)
if err != nil {
goa.LogError(ctx, "updating user", err.Error())
return ctx.Err()
}
return ctx.NoContent()
}