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

Adding general improvements and fixing TODOs #31

Merged
merged 87 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
058c268
Reformatting the file to a better format
COMTOP1 Aug 22, 2024
fff549a
Reformatting more files to a better format
COMTOP1 Aug 22, 2024
2d30c35
Importing the actual docs for swagger
COMTOP1 Aug 22, 2024
31502e2
Adding basic information for the new swagger docs
COMTOP1 Aug 22, 2024
70cdd96
Minor change
COMTOP1 Aug 22, 2024
d8884c0
Adding custom time marshaling
COMTOP1 Aug 22, 2024
66d4bd9
Fixing docs
COMTOP1 Aug 22, 2024
68ba82c
Incorrect param name
COMTOP1 Aug 22, 2024
4bac8b7
Getting the start and end date of officers
COMTOP1 Aug 22, 2024
764d614
Fixing ordering
COMTOP1 Aug 22, 2024
3c2a03d
Fixing imports
COMTOP1 Aug 24, 2024
9f5108f
Fixing spacing in files
COMTOP1 Aug 24, 2024
18668db
Recreated the stream authentication and publishing
COMTOP1 Aug 30, 2024
0443126
Fixing imports
COMTOP1 Aug 30, 2024
b3bd131
Adding functions to main and router
COMTOP1 Aug 30, 2024
8bbd2da
Fixing the naming
COMTOP1 Aug 30, 2024
b095ce5
Adding a function to eliminate null or nil responses
COMTOP1 Aug 30, 2024
aca9ab2
Adding nil proof code to listing functions
COMTOP1 Aug 30, 2024
171ff6c
Formatting files better
COMTOP1 Aug 30, 2024
0f84059
Improved variable initialisers
COMTOP1 Aug 30, 2024
724e41f
Fixing go.mod
COMTOP1 Aug 30, 2024
c7b52bc
I'm not even sure how this worked before
COMTOP1 Aug 30, 2024
3795e55
Bad initialiser
COMTOP1 Aug 30, 2024
8be3e46
Bad table names
COMTOP1 Aug 30, 2024
1a441d9
Fixing the tags as the database has them stored in a bad format
COMTOP1 Aug 30, 2024
df05b67
Adding a swagger doc file for nilaway checks
COMTOP1 Aug 30, 2024
e7f0f42
Fixing linting
COMTOP1 Aug 30, 2024
c5a7224
Ensuring we only get the id
COMTOP1 Sep 1, 2024
1abfaf2
Changing to use dynamic CDN endpoint
COMTOP1 Sep 1, 2024
f952e46
The print wasn't needed
COMTOP1 Sep 1, 2024
95756d7
Fixing variables
COMTOP1 Sep 1, 2024
37143df
JSON response is required
COMTOP1 Sep 1, 2024
ce11b1c
Resolving avatar TODO
COMTOP1 Sep 1, 2024
61abb43
Adding option for cdn based avatars
COMTOP1 Sep 5, 2024
4cf721f
Adding option for cdn based thumbnails
COMTOP1 Sep 5, 2024
c6c6e1c
Standardising some of the names
COMTOP1 Sep 5, 2024
53823d1
Reordering imports
COMTOP1 Sep 5, 2024
f82d7d9
Adding more functions to streams
COMTOP1 Sep 5, 2024
32dba0b
Reinstating these functions
COMTOP1 Sep 5, 2024
647cb29
Adding more grouping
COMTOP1 Sep 5, 2024
3b57811
Updating docs
COMTOP1 Sep 5, 2024
758db84
Not sure how that happened
COMTOP1 Sep 5, 2024
ae3ce7e
Updated again
COMTOP1 Sep 5, 2024
a2bda09
Adding the ability to look up users by email
COMTOP1 Oct 1, 2024
f0ee6f0
Adding the ability to look up users by email
COMTOP1 Oct 1, 2024
66a464a
Updating docs
COMTOP1 Oct 1, 2024
576e9fa
Adding permissions to stream management
COMTOP1 Oct 13, 2024
b758ce2
Weird typos here
COMTOP1 Oct 13, 2024
343f44a
Updating versions
COMTOP1 Jan 2, 2025
fb2b951
Updating versions and fixing aws sdk v2
COMTOP1 Jan 2, 2025
636d511
Changing from insecure to tls 1.2 minimum
COMTOP1 Jan 2, 2025
216fa65
Minor linting
COMTOP1 Jan 2, 2025
4fc6dab
Minor linting and typos
COMTOP1 Jan 2, 2025
d1cdcaa
Adding specific linting parameters
COMTOP1 Jan 2, 2025
b00f296
Adding context and removing unneeded parameters
COMTOP1 Jan 2, 2025
7d758d3
Specifically disabling linting in spaces
COMTOP1 Jan 2, 2025
8d37da3
Resolving the context issue and bad client
COMTOP1 Jan 2, 2025
36ca5df
Resolving the context issue and bad client
COMTOP1 Jan 2, 2025
021572d
Adding missing preset id
COMTOP1 Jan 2, 2025
0a6325f
Adding playlist id return and fixing up code
COMTOP1 Jan 2, 2025
b8eed9a
Standardising to pointers
COMTOP1 Jan 2, 2025
2e5bb9d
Improving the linting
COMTOP1 Jan 2, 2025
6f3c7bf
Adding missing list id parameter
COMTOP1 Jan 2, 2025
9300110
Changing if-else to switch
COMTOP1 Jan 2, 2025
9918478
Updating the function docs
COMTOP1 Jan 2, 2025
33dd369
Minor typo fixes
COMTOP1 Jan 2, 2025
bc8e4a3
Updating README
COMTOP1 Jan 2, 2025
f0480bf
Standardising more function names
COMTOP1 Jan 2, 2025
d80914e
Removing TODO from lint for now
COMTOP1 Jan 2, 2025
a10a56f
Resolving more TODOs
COMTOP1 Jan 2, 2025
96d4bce
Made into a 1-liner
COMTOP1 Jan 2, 2025
541abe8
This is just worng
COMTOP1 Jan 2, 2025
d6bccf0
Resolving the repos and interface
COMTOP1 Jan 2, 2025
5d3ba53
Adding .swaggo override
COMTOP1 Jan 2, 2025
56d2b81
Redoing the docs for playlist delete
COMTOP1 Jan 2, 2025
5690d9a
Renaming endpoint more accurately
COMTOP1 Jan 2, 2025
777ac10
Fixing another TODO
COMTOP1 Jan 5, 2025
55e9971
Specifically ignoring TODOs
COMTOP1 Jan 5, 2025
143f0f1
Adding a find endpoint route
COMTOP1 Jan 5, 2025
fbe9df1
Actually disabling TODO checks
COMTOP1 Jan 5, 2025
67f96af
Changed to errors.New
COMTOP1 Jan 5, 2025
3cee55a
Updating
COMTOP1 Jan 20, 2025
a8cf745
Printing the default case type
COMTOP1 Jan 20, 2025
0e0e155
Updating docs
COMTOP1 Jan 20, 2025
efc8c3a
Returning the found stream and id
COMTOP1 Jan 20, 2025
ec752aa
Responding with json
COMTOP1 Jan 20, 2025
147ab65
Fixed the name
COMTOP1 Jan 20, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: WillAbides/setup-go-faster@v1
with:
go-version: '1.22.5'
go-version: '1.23.4'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nilaway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: WillAbides/setup-go-faster@v1
with:
go-version: '1.22.5'
go-version: '1.23.4'
- name: download nilaway
run: go install go.uber.org/nilaway/cmd/nilaway@latest
- name: run nilaway
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.env.local
docker-compose.yml
web-api
/swagger
/swagger/*.json
*.sw[a-z]
/.idea
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters:
presets:
- bugs
- error
- unused
- comment
- format
- import
- metalinter
- module
- performance
- sql
disable:
- wrapcheck
- err113
- depguard
- tagalign
- godot
- gci
- gofumpt
- godox
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.5-alpine3.20 AS build
FROM golang:1.23.4-alpine3.21 AS build

LABEL site="api"
LABEL stage="builder"
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ The generation of usable JSON Web Tokens is available in [web-auth](https://gith
- [x] Path to video
- [x] Path to series
- [ ] Thumbnail inheritance
- [ ] Live
- [x] Streams (currently static)
- [x] Live
- [x] Streams
- [x] Teams
- [x] Get current team
- [x] List teams
Expand Down Expand Up @@ -67,7 +67,7 @@ The generation of usable JSON Web Tokens is available in [web-auth](https://gith
- [ ] Events
- [x] List by month
- [ ] List by term
- [ ] Sign ups
- [ ] Signups
- [x] Listing including positions
- [x] Creating
- [x] Updating
Expand All @@ -78,7 +78,11 @@ The generation of usable JSON Web Tokens is available in [web-auth](https://gith
- [ ] Delete
- [ ] Encoder
- [x] Video upload auth hook
- [x] Stream auth (experimental)
- [x] Live
- [x] List streams
- [x] Add a stream
- [x] Update stream
- [x] Delete stream
- [ ] Misc internal services

### Services
Expand Down
2 changes: 1 addition & 1 deletion architecture.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Architecture

This document aims to assist developers on understanding the codebase.
This document aims to assist developers in understanding the codebase.

This application follows the MVC architecture (sort of) at a high level.
With the `controllers` packages containing the code handling HTTP responses
Expand Down
1 change: 1 addition & 0 deletions controllers/v1/clapper/clapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clapper

import (
"github.com/jmoiron/sqlx"

"github.com/ystv/web-api/services/clapper"
"github.com/ystv/web-api/services/clapper/crew"
"github.com/ystv/web-api/services/clapper/event"
Expand Down
12 changes: 12 additions & 0 deletions controllers/v1/clapper/crew.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ func (r *Repos) SetCrew(c echo.Context) error {
err = fmt.Errorf("SetCrew: failed to get token: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

crewID, err := strconv.Atoi(c.Param("crewid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid crew ID")
}

err = r.crew.UpdateUserAndVerify(c.Request().Context(), crewID, p.UserID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.NoContent(http.StatusOK)
}

Expand All @@ -57,10 +60,12 @@ func (r *Repos) ResetCrew(c echo.Context) error {
err = fmt.Errorf("ResetCrew: failed to get token: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

crewID, err := strconv.Atoi(c.Param("crewid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid crew ID")
}

// get crew object
_, err = r.crew.Get(c.Request().Context(), crewID)
if err != nil {
Expand All @@ -69,12 +74,14 @@ func (r *Repos) ResetCrew(c echo.Context) error {
}
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

// TODO verify user has permission

err = r.crew.DeleteUser(c.Request().Context(), crewID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.NoContent(http.StatusOK)
}

Expand All @@ -95,14 +102,17 @@ func (r *Repos) NewCrew(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid signup ID")
}

positionID, err := strconv.Atoi(c.Param("positionid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid position ID")
}

err = r.crew.New(c.Request().Context(), signupID, positionID)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Failed to insert crew: ", err)
}

return c.NoContent(http.StatusOK)
}

Expand All @@ -122,10 +132,12 @@ func (r *Repos) DeleteCrew(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid crew ID")
}

err = r.crew.Delete(c.Request().Context(), signupID)
if err != nil {
err = fmt.Errorf("DeleteCrew failed: %w", err)
return c.JSON(http.StatusInternalServerError, err)
}

return c.NoContent(http.StatusOK)
}
23 changes: 20 additions & 3 deletions controllers/v1/clapper/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"strconv"

"github.com/labstack/echo/v4"

"github.com/ystv/web-api/services/clapper"
"github.com/ystv/web-api/utils"
)

// ListMonth returns all events for a month.
Expand All @@ -26,16 +28,19 @@ func (r *Repos) ListMonth(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Year incorrect, format /yyyy/mm")
}

month, err := strconv.Atoi(c.Param("month"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Month incorrect, format /yyyy/mm")
}

e, err := r.event.ListMonth(c.Request().Context(), year, month)
if err != nil {
err = fmt.Errorf("ListMonth failed: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, e)

return c.JSON(http.StatusOK, utils.NonNil(e))
}

// GetEvent handles getting all signups and roles for a given event
Expand All @@ -52,11 +57,13 @@ func (r *Repos) GetEvent(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid event ID")
}

e, err := r.event.Get(c.Request().Context(), eventID)
if err != nil {
err = fmt.Errorf("GetEvent failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusOK, e)
}

Expand All @@ -71,22 +78,26 @@ func (r *Repos) GetEvent(c echo.Context) error {
// @Success 201 body int "Event ID"
// @Router /v1/internal/clapper/event [post]
func (r *Repos) NewEvent(c echo.Context) error {
e := clapper.NewEvent{}
var e clapper.NewEvent

err := c.Bind(&e)
if err != nil {
err = fmt.Errorf("NewEvent: failed to bind to request json: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

p, err := r.access.GetToken(c.Request())
if err != nil {
err = fmt.Errorf("NewEvent: failed to get token: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

eventID, err := r.event.New(c.Request().Context(), &e, p.UserID)
if err != nil {
err = fmt.Errorf("NewEvent: failed to insert event: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusCreated, eventID)
}

Expand All @@ -101,17 +112,20 @@ func (r *Repos) NewEvent(c echo.Context) error {
// @Success 200
// @Router /v1/internal/clapper/event [put]
func (r *Repos) UpdateEvent(c echo.Context) error {
e := clapper.Event{}
var e clapper.Event

err := c.Bind(&e)
if err != nil {
err = fmt.Errorf("UpdateEvent: failed to bind to request json: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

p, err := r.access.GetToken(c.Request())
if err != nil {
err = fmt.Errorf("UpdateEvent: failed to get token: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

err = r.event.Update(c.Request().Context(), &e, p.UserID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand All @@ -120,6 +134,7 @@ func (r *Repos) UpdateEvent(c echo.Context) error {
err = fmt.Errorf("UpdateEvent: failed to update: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.NoContent(http.StatusOK)
}

Expand All @@ -138,9 +153,11 @@ func (r *Repos) DeleteEvent(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid event ID")
}

err = r.event.Delete(c.Request().Context(), eventID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to delete event: %w", err))
}

return c.NoContent(http.StatusOK)
}
23 changes: 17 additions & 6 deletions controllers/v1/clapper/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ import (
"strconv"

"github.com/labstack/echo/v4"

"github.com/ystv/web-api/services/clapper"
"github.com/ystv/web-api/utils"
)

// ListPosition handles listing all possible positions
// ListPositions handles listing all possible positions
// @Summary List positions
// @Description Lists all positions.
// @ID get-positions
// @Tags clapper-positions
// @Produce json
// @Success 200 {array} clapper.Position
// @Router /v1/internal/clapper/positions [get]
func (r *Repos) ListPosition(c echo.Context) error {
func (r *Repos) ListPositions(c echo.Context) error {
p, err := r.position.List(c.Request().Context())
if err != nil {
err = fmt.Errorf("ListPosition: failed to list: %w", err)
err = fmt.Errorf("ListPositions: failed to list: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, p)

return c.JSON(http.StatusOK, utils.NonNil(p))
}

// NewPosition handles creating a new position
Expand All @@ -37,17 +40,20 @@ func (r *Repos) ListPosition(c echo.Context) error {
// @Success 201 body int "Position ID"
// @Router /v1/internal/clapper/positions [post]
func (r *Repos) NewPosition(c echo.Context) error {
p := clapper.Position{}
var p clapper.Position

err := c.Bind(&p)
if err != nil {
err = fmt.Errorf("NewPosition: failed to bind to request json: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

positionID, err := r.position.New(c.Request().Context(), &p)
if err != nil {
err = fmt.Errorf("NewPosition: failed to insert position: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusCreated, positionID)
}

Expand All @@ -60,12 +66,14 @@ func (r *Repos) NewPosition(c echo.Context) error {
// @Success 200
// @Router /v1/internal/clapper/positions [put]
func (r *Repos) UpdatePosition(c echo.Context) error {
p := clapper.Position{}
var p clapper.Position

err := c.Bind(&p)
if err != nil {
err = fmt.Errorf("UpdatePosition: failed to bind to request json: %w", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

err = r.position.Update(c.Request().Context(), &p)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand All @@ -74,6 +82,7 @@ func (r *Repos) UpdatePosition(c echo.Context) error {
err = fmt.Errorf("UpdatePosition failed: %w", err)
return c.JSON(http.StatusInternalServerError, err)
}

return c.NoContent(http.StatusOK)
}

Expand All @@ -91,9 +100,11 @@ func (r *Repos) DeletePosition(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid position ID")
}

err = r.position.Delete(c.Request().Context(), positionID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to delete event: %w", err))
}

return c.NoContent(http.StatusOK)
}
Loading
Loading