-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alleged Domain Driven Design / Dependency Injection and other things
- Loading branch information
Showing
57 changed files
with
1,853 additions
and
1,115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package clapper | ||
|
||
import ( | ||
"github.com/jmoiron/sqlx" | ||
"github.com/ystv/web-api/services/clapper" | ||
"github.com/ystv/web-api/services/clapper/event" | ||
"github.com/ystv/web-api/services/clapper/position" | ||
"github.com/ystv/web-api/services/clapper/signup" | ||
) | ||
|
||
// Repos encapsulates the dependency | ||
type Repos struct { | ||
event clapper.EventRepo | ||
signup clapper.SignupRepo | ||
position clapper.PositionRepo | ||
} | ||
|
||
// NewRepos creates our data store | ||
func NewRepos(db *sqlx.DB) *Repos { | ||
return &Repos{event.NewStore(db), signup.NewStore(db), position.NewStore(db)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package clapper | ||
|
||
import ( | ||
"database/sql" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/ystv/web-api/services/clapper" | ||
) | ||
|
||
// SignupNew | ||
func (r *Repos) SignupNew(c echo.Context) error { | ||
// Validate event ID | ||
eventID, err := strconv.Atoi(c.Param("eventID")) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, "Bad event ID") | ||
} | ||
// Bind request json to signup | ||
s := clapper.Signup{} | ||
err = c.Bind(&s) | ||
if err != nil { | ||
err = fmt.Errorf("SignupNew: failed to bind to request json: %w", err) | ||
return echo.NewHTTPError(http.StatusBadRequest, err) | ||
} | ||
|
||
// Check event exists | ||
// TODO we might want to move this inside the service | ||
e, err := r.event.Get(c.Request().Context(), eventID) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return echo.NewHTTPError(http.StatusNotFound, "No event found") | ||
} | ||
return echo.NewHTTPError(http.StatusInternalServerError, err) | ||
} | ||
|
||
// Insert new signup sheet | ||
signupID, err := r.signup.New(c.Request().Context(), e.EventID, s) | ||
if err != nil { | ||
err = fmt.Errorf("SignupNew: failed to insert new signup: %w", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err) | ||
} | ||
return c.JSON(http.StatusCreated, signupID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,48 @@ | ||
package creator | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/jmoiron/sqlx" | ||
"github.com/labstack/echo/v4" | ||
"github.com/ystv/web-api/services/creator" | ||
"github.com/ystv/web-api/services/creator/breadcrumb" | ||
"github.com/ystv/web-api/services/creator/encode" | ||
"github.com/ystv/web-api/services/creator/playlist" | ||
"github.com/ystv/web-api/services/creator/series" | ||
"github.com/ystv/web-api/services/creator/video" | ||
) | ||
|
||
// FileUpload Handles uploading a file | ||
func FileUpload(c echo.Context) error { | ||
creator.CreateBucket("pending", "ystv-wales-1") | ||
url, err := creator.GenerateUploadURL("pending", c.Param("id")) | ||
if err != nil { | ||
return c.JSON(http.StatusInternalServerError, err.Error()) | ||
// Repos represents all our data repositories | ||
type Repos struct { | ||
video creator.VideoRepo | ||
series creator.SeriesRepo | ||
playlist creator.PlaylistRepo | ||
breadcrumb creator.BreadcrumbRepo | ||
encode creator.EncodeRepo | ||
creator creator.StatRepo | ||
} | ||
|
||
// NewRepos creates our data repositories | ||
func NewRepos(db *sqlx.DB, cdn *s3.S3) *Repos { | ||
return &Repos{ | ||
video.NewStore(db, cdn), | ||
series.NewController(db, cdn), | ||
playlist.NewStore(db), | ||
breadcrumb.NewController(db, cdn), | ||
encode.NewStore(db), | ||
creator.NewStore(db), | ||
} | ||
return c.JSON(http.StatusOK, url) | ||
} | ||
|
||
// Stats handles sending general stats about the video library | ||
func Stats(c echo.Context) error { | ||
s, err := creator.Stats(context.Background()) | ||
func (r *Repos) Stats(c echo.Context) error { | ||
s, err := r.creator.GlobalVideo(c.Request().Context()) | ||
if err != nil { | ||
return c.JSON(http.StatusBadRequest, err) | ||
err = fmt.Errorf("stats failed: %w", err) | ||
return echo.NewHTTPError(http.StatusBadRequest, err) | ||
} | ||
return c.JSON(http.StatusOK, s) | ||
} |
Oops, something went wrong.