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

Liam.burnand/random stuff #25

Merged
merged 4 commits into from
May 14, 2023
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
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-alpine AS build
FROM golang:1.17.6-alpine AS build
LABEL site="api"
LABEL stage="builder"

Expand All @@ -7,13 +7,13 @@ ENV USER=webapiuser
ENV UID=10001

# See https://stackoverflow.com/a/55757473/12429735RUN
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

WORKDIR /src/
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# YSTV web-api

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.
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.

Generation of usable JWT's is available in [web-auth](github.com/ystv/web-auth) currently.

Expand All @@ -19,11 +19,11 @@ Generation of usable JWT's is available in [web-auth](github.com/ystv/web-auth)
- [x] Path to series
- [ ] Thumbnail inheritance
- [ ] Live
- [x] Streams (currrently static)
- [ ] Teams
- [x] Streams (currently static)
- [x] Teams
- [x] Get current team
- [x] List teams
- [ ] Get a team by year
- [x] Get a team by year
- [x] List all officers
- [ ] Internal (Secured)
- [ ] Creator Studio
Expand Down Expand Up @@ -69,7 +69,7 @@ Generation of usable JWT's is available in [web-auth](github.com/ystv/web-auth)
- [x] Listing including positions
- [x] Creating
- [x] Updating
- [ ] Postitions
- [ ] Positions
- [x] List
- [x] Create
- [x] Update
Expand All @@ -88,7 +88,7 @@ Generation of usable JWT's is available in [web-auth](github.com/ystv/web-auth)

- [x] Postgres
- [x] RabbitMQ
- [x] web-auth intergration
- [x] web-auth integration
- [ ] Authstack

## Dependencies
Expand Down Expand Up @@ -131,7 +131,7 @@ Build the image.

`docker image build -t web-api .`

You will then need to set the environment variables like how it is setup in `docker-compose.yml` or you might be able to create a container and then use `docker export` so you can run a static binary built in docker.
You will then need to set the environment variables like how it is set up in `docker-compose.yml` or you might be able to create a container and then use `docker export` so you can run a static binary built in docker.

#### Docker-compose

Expand All @@ -156,9 +156,9 @@ I recommend not using the production environment for testing and recommend runni

Updating the DB schema use `goose` to migrate safely.

When ran with the `debug` flag set to true. 500 server errors will be returned to the browser, not just logged. Otherwise it will only return the 500 code and not not the actual error.
When ran with the `debug` flag set to true. 500 server errors will be returned to the browser, not just logged. Otherwise, it will only return the 500 code and not the actual error.

Try to keep all "business" logic with in the `/services` and try to keep the imports local to that package, but you'll probably need the `utils` package but we're trying to keep it modular so web-api can theoretically be split up and keeping it seperate would likely make it a lot easier.
Try to keep all "business" logic with in the `/services` and try to keep the imports local to that package, but you'll probably need the `utils` package, but we're trying to keep it modular so web-api can theoretically be split up and keeping it separate would likely make it a lot easier.

Generate docs by running `go generate` in the root of the repo.

Expand All @@ -173,7 +173,7 @@ Generate docs by running `go generate` in the root of the repo.
- `/docs`
echo-swagger autogenerated docs.
- `/middleware`
REST middleware, implements some URL sanitisation and logging.
REST middleware, implements some URL sanitization and logging.
- `/routes`
Handles how the REST api is arranged and applies extra middleware if necessary.
- `/services`
Expand Down
2 changes: 1 addition & 1 deletion architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The current aim with the services package is to have a set of core packages:
* campus (campus related activities)

These core packages aim to not depend on each other. Then there are the
hybrid packages which use a mixture of the cores and there own business
hybrid packages which use a mixture of the cores and their own business
code. Examples include:
* creator
* public
2 changes: 1 addition & 1 deletion ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We use Jenkins at YSTV to automate our build deployments. For each of our websit

We use multi-stage pipelines and would recommend them for best compatibility with our scripts.

The repo should be mostly plug and play with Jenkins but you will need to set a couple of credentials that are used by all of our pipelines:
The repo should be mostly plug and play with Jenkins, but you will need to set a couple of credentials that are used by all of our pipelines:

- `docker-registry-endpoint` (secret text) - A Docker registry endpoint i.e. `registry.ystv.co.uk`, checkout this [guide](https://docs.docker.com/registry/) to learn more.

Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/clapper/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *Repos) ListMonth(c echo.Context) error {

// GetEvent handles getting all signups and roles for a given event
// @Summary Get event by ID
// @Description Get a event including signup-sheets and roles.
// @Description Get an event including signup-sheets and roles.
// @ID get-event
// @Tags clapper-events
// @Produce json
Expand Down
8 changes: 4 additions & 4 deletions controllers/v1/creator/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *Repos) NewEncodeFormat(c echo.Context) error {

// UpdateEncodeFormat handles updating a format
// @Summary Update a format
// @Description updates an format
// @Description updates a format
// @ID update-creator-encode-format
// @Tags creator-encodes
// @Accept json
Expand All @@ -80,7 +80,7 @@ func (r *Repos) UpdateEncodeFormat(c echo.Context) error {
}

// DeleteEncodeFormat handles deleting quotes
// @Summary Delete a encode format
// @Summary Delete an encode format
// @Description Delete a video encode format
// @ID delete-creator-encode-format
// @Tags creator-encodes
Expand Down Expand Up @@ -117,7 +117,7 @@ func (r *Repos) ListEncodePreset(c echo.Context) error {
return c.JSON(http.StatusOK, p)
}

// NewPreset handles creating a new preset
// NewEncodePreset handles creating a new preset
// @Summary New preset
// @Description creates a new preset.
// @ID new-creator-encode-preset
Expand All @@ -141,7 +141,7 @@ func (r *Repos) NewEncodePreset(c echo.Context) error {
return c.JSON(http.StatusCreated, presetID)
}

// UpdatePreset handles updating a preset
// UpdateEncodePreset handles updating a preset
// @Summary Update a preset
// @Description updates an preset
// @ID update-creator-encode-preset
Expand Down
8 changes: 4 additions & 4 deletions controllers/v1/creator/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func (r *Repos) ListPlaylist(c echo.Context) error {
return c.JSON(http.StatusOK, p)
}

// GetPlaylist handles getting a single playlist and it's following videometa's
// GetPlaylist handles getting a single playlist, and it's following videometa's
// @Summary Get playlist by ID
// @Description Get a playlist including it's children videos.
// @Description Get a playlist including its children videos.
// @ID get-creator-playlist
// @Tags creator-playlists
// @Produce json
Expand All @@ -38,11 +38,11 @@ func (r *Repos) ListPlaylist(c echo.Context) error {
func (r *Repos) GetPlaylist(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
echo.NewHTTPError(http.StatusBadRequest, "Invalid playlist ID")
return echo.NewHTTPError(http.StatusBadRequest, "Invalid playlist ID")
}
p, err := r.playlist.Get(c.Request().Context(), id)
if err != nil {
err = fmt.Errorf("Playlist get failed: %w", err)
err = fmt.Errorf("playlist get failed: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, p)
Expand Down
4 changes: 2 additions & 2 deletions controllers/v1/creator/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (r *Repos) ListSeries(c echo.Context) error {

// GetSeries finds a video by ID
// @Summary Get series by ID
// @Description Get a series including it's children videos.
// @Description Get a series including its children videos.
// @ID get-creator-series
// @Tags creator-series
// @Produce json
Expand All @@ -35,7 +35,7 @@ func (r *Repos) ListSeries(c echo.Context) error {
func (r *Repos) GetSeries(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.String(http.StatusBadRequest, "Number pls")
return c.String(http.StatusBadRequest, "Number pls")
}
s, err := r.series.Get(c.Request().Context(), id)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions controllers/v1/creator/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// GetVideo finds a video by ID
//
// @Summary Get video by ID
// @Description Get a playlist including it's children files.
// @Description Get a playlist including its children files.
// @ID get-creator-video
// @Tags creator-videos
// @Produce json
Expand All @@ -23,7 +23,7 @@ import (
func (r *Repos) GetVideo(c echo.Context) error {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
echo.NewHTTPError(http.StatusBadRequest, "Invalid video ID")
return echo.NewHTTPError(http.StatusBadRequest, "Invalid video ID")
}
v, err := r.video.GetItem(c.Request().Context(), id)
if err != nil {
Expand Down Expand Up @@ -68,7 +68,7 @@ func (r *Repos) NewVideo(c echo.Context) error {
return c.JSON(http.StatusCreated, NewVideoOutput{VideoID: videoID})
}

// UpdateVideo updates a video's metadata not files
// UpdateVideoMeta updates a video's metadata not files
//
// @Summary Update video meta
// @Description Updates a video metadata
Expand Down Expand Up @@ -196,7 +196,7 @@ func (r *Repos) SearchVideo(c echo.Context) error {
}
s, err := r.video.Search(c.Request().Context(), searchInput.Query)
if err != nil {
err = fmt.Errorf("Public Search failed : %w", err)
err = fmt.Errorf("public Search failed : %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, s)
Expand Down
17 changes: 10 additions & 7 deletions controllers/v1/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ystv/web-api/utils"
)

type EncoderController struct {
type Repo struct {
enc *encoder.Encoder
access *utils.Accesser
}
Expand Down Expand Up @@ -46,8 +46,8 @@ type (
}
)

func NewEncoderController(enc *encoder.Encoder, access *utils.Accesser) *EncoderController {
return &EncoderController{
func NewEncoderController(enc *encoder.Encoder, access *utils.Accesser) *Repo {
return &Repo{
enc: enc,
access: access,
}
Expand All @@ -69,11 +69,14 @@ func NewEncoderController(enc *encoder.Encoder, access *utils.Accesser) *Encoder
// @Accept json
// @Success 200
// @Router /v1/internal/encoder/upload_request [post]
func (e *EncoderController) UploadRequest(c echo.Context) error {
func (e *Repo) UploadRequest(c echo.Context) error {
r := Request{}
c.Bind(&r)
err := c.Bind(&r)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}

_, err := e.access.GetToken(c.Request())
_, err = e.access.GetToken(c.Request())
if err != nil {
err = fmt.Errorf("GetToken failed: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
Expand All @@ -92,7 +95,7 @@ func (e *EncoderController) UploadRequest(c echo.Context) error {
// @Param taskid path int true "Task ID"
// @Success 200
// @Router /v1/internal/encoder/transcode_finished/{taskid} [post]
func (e *EncoderController) TranscodeFinished(c echo.Context) error {
func (e *Repo) TranscodeFinished(c echo.Context) error {
err := e.enc.TranscodeFinished(c.Request().Context(), c.Param("taskid"))
if err != nil {
err = fmt.Errorf("transcode finished failed: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions controllers/v1/misc/webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (r *Repos) ListWebcams(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

perms := []string{}
var perms []string
perms = append(perms, claims.Permissions...)

w, err := r.misc.ListWebcams(c.Request().Context(), perms)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (r *Repos) GetWebcam(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

perms := []string{}
var perms []string
perms = append(perms, claims.Permissions...)

w, err := r.misc.GetWebcam(c.Request().Context(), cameraID, perms)
Expand Down
12 changes: 6 additions & 6 deletions controllers/v1/public/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// GetPlaylist handles returning a playlist with a list of videos and metadata
//
// @Summary Provides a playlist
// @Description Returns a playlist object, includes videos (not videofiles) and metadata.
// @Description Returns a playlist object, includes videos (not video files) and metadata.
// @ID get-public-playlist
// @Tags public-playlist
// @Param playlistid path int true "Playlist ID"
Expand All @@ -25,7 +25,7 @@ func (r *Repos) GetPlaylist(c echo.Context) error {
}
p, err := r.public.GetPlaylist(c.Request().Context(), playlistID)
if err != nil {
err = fmt.Errorf("Public GetPlaylist failed: %w", err)
err = fmt.Errorf("public GetPlaylist failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, p)
Expand All @@ -43,7 +43,7 @@ func (r *Repos) GetPlaylist(c echo.Context) error {
func (r *Repos) GetPlaylistPopularByAllTime(c echo.Context) error {
p, err := r.public.GetPlaylistPopularByAllTime(c.Request().Context())
if err != nil {
err = fmt.Errorf("Public GetPlaylistByAllTime failed: %w", err)
err = fmt.Errorf("public GetPlaylistByAllTime failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, p)
Expand All @@ -61,7 +61,7 @@ func (r *Repos) GetPlaylistPopularByAllTime(c echo.Context) error {
func (r *Repos) GetPlaylistPopularByPastYear(c echo.Context) error {
p, err := r.public.GetPlaylistPopularByPastYear(c.Request().Context())
if err != nil {
err = fmt.Errorf("Public GetPlaylistByPastYear failed: %w", err)
err = fmt.Errorf("public GetPlaylistByPastYear failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, p)
Expand All @@ -79,7 +79,7 @@ func (r *Repos) GetPlaylistPopularByPastYear(c echo.Context) error {
func (r *Repos) GetPlaylistPopularByPastMonth(c echo.Context) error {
p, err := r.public.GetPlaylistPopularByPastMonth(c.Request().Context())
if err != nil {
err = fmt.Errorf("Public GetPlaylistByPastMonth failed: %w", err)
err = fmt.Errorf("public GetPlaylistByPastMonth failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, p)
Expand All @@ -97,7 +97,7 @@ func (r *Repos) GetPlaylistPopularByPastMonth(c echo.Context) error {
func (r *Repos) GetPlaylistRandom(c echo.Context) error {
p, err := r.public.GetPlaylistRandom(c.Request().Context())
if err != nil {
err = fmt.Errorf("Public GetPlaylistByRandom failed: %w", err)
err = fmt.Errorf("public GetPlaylistByRandom failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, p)
Expand Down
8 changes: 4 additions & 4 deletions controllers/v1/public/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/labstack/echo/v4"
)

// SeriesByID returns a series with it's immediate children with a SeriesID
// SeriesByID returns a series with its immediate children with a SeriesID
//
// @Summary Provides a series
// @Description Returns a series object, including the children videos and series.
Expand All @@ -25,7 +25,7 @@ func (r *Repos) SeriesByID(c echo.Context) error {
}
s, err := r.public.GetSeries(c.Request().Context(), id)
if err != nil {
err = fmt.Errorf("Public SeriesByID failed : %w", err)
err = fmt.Errorf("public SeriesByID failed : %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, s)
Expand All @@ -49,7 +49,7 @@ func (r *Repos) SeriesByYear(c echo.Context) error {
}
s, err := r.public.SeriesByYear(c.Request().Context(), year)
if err != nil {
err = fmt.Errorf("Public ListSeriesByYear failed : %w", err)
err = fmt.Errorf("public ListSeriesByYear failed : %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, s)
Expand Down Expand Up @@ -77,7 +77,7 @@ func (r *Repos) Search(c echo.Context) error {
}
s, err := r.public.Search(c.Request().Context(), searchInput.Query)
if err != nil {
err = fmt.Errorf("Public Search failed : %w", err)
err = fmt.Errorf("public Search failed : %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, s)
Expand Down
Loading