Skip to content

Commit

Permalink
Merge pull request #2 from YSTV/sqlx
Browse files Browse the repository at this point in the history
Sqlx
  • Loading branch information
rmil authored Jul 21, 2020
2 parents 698e0cf + 324097b commit 3f21ada
Show file tree
Hide file tree
Showing 38 changed files with 379 additions and 10,971 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# YSTV web-api

A Go based backend that should be able to handle website queries?

This is currently built to handle a few of the tables in `ystv`. If there is a future table needed, you'll probably need to re-run [sqlboiler](https://github.com/volatiletech/sqlboiler) so it can generate the new models. (You'll probably want to update `sqlboiler.toml` so your table isn't blacklisted)
A Go based backend that should be able to handle website queries? Hopefully having a supportive subroutine to keep everything in order. Designed kind of like a monolith but we'll see where we get to with it.

## Functionality

Expand Down Expand Up @@ -101,3 +99,9 @@ Updating the DB schema use `goose` to migrate safely.
Internal API that is the main "business logic" for each service web-api provides.
- /utils
Provides access to commonly used functions, i.e. cdn, mq, sql

### Database info

This is currently built to handle a few of the tables in `ystv`. If there is a future table needed, you'll probably need to re-run [sqlboiler](https://github.com/volatiletech/sqlboiler) so it can generate the new models. (You'll probably want to update `sqlboiler.toml` so your table isn't blacklisted). However we might be moving away from this.

Schema is currently stored in the planning repo.
45 changes: 40 additions & 5 deletions controllers/v1/creator/creator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package creator

import (
"context"
"net/http"
"strconv"

"github.com/labstack/echo/v4"
"github.com/ystv/web-api/services/creator"
Expand All @@ -22,10 +24,17 @@ func CreationFileUpload(c echo.Context) error {
return c.JSON(http.StatusOK, url)
}

// CreationFind Handles finding a creation by ID
func CreationFind(c echo.Context) error {
creation, _ := creator.VideoItemFind()
return c.JSON(http.StatusOK, creation)
// VideoFind finds a video by ID
func VideoFind(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.String(http.StatusBadRequest, "Number pls")
}
v, err := creator.VideoItemFind(context.Background(), id)
if err != nil {
return c.JSON(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, v)
}

// CreationCreate Handles creation of a creation lol
Expand All @@ -35,9 +44,35 @@ func CreationCreate(c echo.Context) error {

// CreationList Handles listing all creations
func CreationList(c echo.Context) error {
creations, err := creator.ListPendingUploads()
creations, err := creator.VideoMetaList(context.Background())
if err != nil {
return err
}
return c.JSON(http.StatusOK, creations)
}

// CalendarList Handles listing all videos from a calendar year/month
func CalendarList(c echo.Context) error {
year, err := strconv.Atoi(c.Param("year"))
if err != nil {
return c.String(http.StatusBadRequest, "Year incorrect, format /yyyy/mm")
}
month, err := strconv.Atoi(c.Param("month"))
if err != nil {
return c.String(http.StatusBadRequest, "Month incorrect, format /yyyy/mm")
}
v, err := creator.CalendarList(context.Background(), year, month)
if err != nil {
return c.JSON(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, v)
}

// Stats handles sending general stats about the video library
func Stats(c echo.Context) error {
s, err := creator.Stats(context.Background())
if err != nil {
return c.JSON(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, s)
}
12 changes: 0 additions & 12 deletions controllers/v1/playlist/playlist.go

This file was deleted.

39 changes: 39 additions & 0 deletions controllers/v1/public/video.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package public

import (
"net/http"
"strconv"

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

// Video handles a video item, providing info vfiles
func Video(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
return c.String(http.StatusBadRequest, "Bad video ID")
}
v, err := public.VideoFind(id)
if err != nil {
return c.NoContent(http.StatusInternalServerError)
}
return c.JSON(http.StatusOK, v)
}

// ListVideos handles listing videos using an offset and page
func ListVideos(c echo.Context) error {
offset, err := strconv.Atoi(c.Param("offset"))
if err != nil {
return c.String(http.StatusBadRequest, "Bad offset")
}
page, err := strconv.Atoi(c.Param("page"))
if err != nil {
return c.String(http.StatusBadRequest, "Bad page")
}
v, err := public.VideoList(offset, page)
if err != nil {
return c.NoContent(http.StatusInternalServerError)
}
return c.JSON(http.StatusOK, v)
}
117 changes: 0 additions & 117 deletions controllers/v1/tables/quotes.go

This file was deleted.

117 changes: 0 additions & 117 deletions controllers/v1/tables/videoboxes.go

This file was deleted.

Loading

0 comments on commit 3f21ada

Please sign in to comment.