Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo #1

Merged
merged 4 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
sqlboiler
sqlboiler-psql
sqlboiler.toml
sqlboiler.toml
swag
36 changes: 0 additions & 36 deletions controllers/quotes.go

This file was deleted.

117 changes: 117 additions & 0 deletions controllers/v1/tables/quotes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package tables

import (
"net/http"
"strconv"

"github.com/labstack/echo/v4"
"github.com/ystv/web-api/models"
"github.com/ystv/web-api/services"
)

// QuoteCreate Quote create API
// @Summary Quote create API
// @Description Create new quote
// @Accept json
// @Produce json
// @Param body body models.Quote true "quote create parameter"
// @Success 200 {object} models.Quote
// @Router /v1/tables/quotes [post]
func QuoteCreate(c echo.Context) error {
q := new(models.Quote)
err := c.Bind(q)
if err != nil {
return c.JSON(http.StatusBadRequest, err.Error())
}
id, err := services.QuoteCreate(q)
if err != nil {
return c.JSON(http.StatusInternalServerError, err.Error())
}
return c.JSON(http.StatusOK, id)
}

// QuoteList Quote list API
// @Summary Quote list API
// @Description list quotes
// @Accept json
// @Produce json
// @Success 200 {object} models.QuoteSlice
// @Router /v1/tables/quotes [get]
func QuoteList(c echo.Context) error {
res, err := services.QuoteList()
if err != nil {
return err
}
return c.JSON(http.StatusOK, res)
}

// QuoteFind Quote find API
// @Summary Quote find API
// @Description find quote
// @Accept json
// @Produce json
// @Success 200 {object} models.Quote
// @Router /v1/tables/quotes/{quote_id} [get]
func QuoteFind(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.String(http.StatusBadRequest, "Number pls")
}
res, err := services.QuoteFind(id)
if err != nil {
return err
}
return c.JSON(http.StatusOK, res)
}

// QuoteUpdate Quote update API
// @Summary Quote update API
// @Description update quotes
// @Accept json
// @Produce json
// @Param quote_id path int true "quote id parameter"
// @Success 200 string string ""
// @Router /v1/tables/quotes/{quote_id} [put]
func QuoteUpdate(c echo.Context) error {
// Check new quote will bind
newQuote := new(models.Quote)
err := c.Bind(newQuote)
if err != nil {
return c.JSON(http.StatusBadRequest, err.Error())
}
// Finding quote to update
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.String(http.StatusBadRequest, "Number pls")
}
oldQuote, err := services.QuoteFind(id)
if err != nil {
return c.JSON(http.StatusNotFound, err.Error())
}
// Update quote
err = services.QuoteUpdate(oldQuote, newQuote)
if err != nil {
return c.JSON(http.StatusInternalServerError, err.Error())
}
return c.JSON(http.StatusOK, oldQuote)
}

// QuoteDelete Quote delete API
// @Summary Quote delete API
// @Description delete quotes
// @Accept json
// @Produce json
// @Param quote_id path int true "quote id parameter"
// @Success 200 string string ""
// @Router /v1/tables/quotes/{quote_id} [delete]
func QuoteDelete(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.String(http.StatusBadRequest, "Number pls")
}
res, err := services.QuoteDelete(id)
if err != nil {
return err
}
return c.JSON(http.StatusOK, res)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllers
package tables

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllers
package tables

import (
"context"
Expand Down
79 changes: 79 additions & 0 deletions controllers/v1/tables/videos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package tables

import (
"net/http"
"strconv"

"github.com/labstack/echo/v4"
"github.com/ystv/web-api/services"
)

// VideoCreate Video create API
// @Summary Video create API
// @Description create new video, there is more to videos!
// @Accept json
// @Produce json
// @Param body body models.Video true "video create parameter"
// @Success 200 {object} models.Video
// @Router /v1/tables/videos [post]
func VideoCreate(c echo.Context) error {
return c.JSON(http.StatusOK, "update ok")
}

// VideoList Video list API
// @Summary Video list API
// @Description list videos
// @Accept json
// @Produce json
// @Success 200 {object} models.VideoSlice
// @Router /v1/tables/videos [get]
func VideoList(c echo.Context) error {
res, err := services.VideoList()
if err != nil {
return err
}
return c.JSON(http.StatusOK, res)
}

// VideoFind Video find API
// @Summary Video find API
// @Description find video
// @Accept json
// @Produce json
// @Success 200 {object} models.Video
// @Router /v1/tables/videos/{video_id} [get]
func VideoFind(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.String(400, "Number pls")
}
res, err := services.VideoFind(id)
if err != nil {
return err
}
return c.JSON(http.StatusOK, res)
}

// VideoUpdate Video update API
// @Summary Video update API
// @Description update videos
// @Accept json
// @Produce json
// @Param video_id path int true "video id parameter"
// @Success 200 string string ""
// @Router /v1/tables/videos/{video_id} [put]
func VideoUpdate(c echo.Context) error {
return c.JSON(http.StatusOK, "update ok")
}

// VideoDelete Video delete API
// @Summary Video delete API
// @Description delete videos
// @Accept json
// @Produce json
// @Param video_id path int true "video id parameter"
// @Success 200 string string ""
// @Router /v1/tables/videos/{video_id} [delete]
func VideoDelete(c echo.Context) error {
return c.JSON(http.StatusOK, "delete ok")
}
53 changes: 0 additions & 53 deletions controllers/videos.go

This file was deleted.

Loading