Skip to content

Commit

Permalink
Minor bump, more docs and name refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rmil committed Nov 20, 2020
1 parent 4c4a9e0 commit 3d711d3
Show file tree
Hide file tree
Showing 7 changed files with 527 additions and 21 deletions.
14 changes: 7 additions & 7 deletions controllers/v1/clapper/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"github.com/ystv/web-api/services/clapper"
)

// MonthList returns all events for a month.
// ListMonth returns all events for a month.
// @Summary List events by month
// @Description Lists events by month. The signup section will be null.
// @ID get-events-month
// @Tags events
// @Tags clapper, events
// @Produce json
// @Param year path int true "year"
// @Param month path int true "month"
// @Success 200 {array} clapper.Event
// @Router /v1/internal/clapper/calendar/{year}/{month} [get]
func (r *Repos) MonthList(c echo.Context) error {
func (r *Repos) ListMonth(c echo.Context) error {
year, err := strconv.Atoi(c.Param("year"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Year incorrect, format /yyyy/mm")
Expand All @@ -40,23 +40,23 @@ func (r *Repos) MonthList(c echo.Context) error {
return c.JSON(http.StatusOK, e)
}

// EventGet handles getting all signups and roles for a given event
// 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.
// @ID get-event
// @Tags events
// @Tags clapper, events
// @Produce json
// @Param eventid path int true "Event ID"
// @Success 200 {object} clapper.Event
// @Router /v1/internal/clapper/event/{eventid} [get]
func (r *Repos) EventGet(c echo.Context) error {
func (r *Repos) GetEvent(c echo.Context) error {
id, err := strconv.Atoi(c.Param("eventid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid event ID")
}
e, err := r.event.Get(c.Request().Context(), id)
if err != nil {
err = fmt.Errorf("EventGet failed: %w", err)
err = fmt.Errorf("GetEvent failed: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, e)
Expand Down
22 changes: 11 additions & 11 deletions controllers/v1/clapper/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
"github.com/ystv/web-api/services/clapper"
)

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

// PositionNew handles creating a new position
// NewPosition handles creating a new position
// @Summary New position
// @Description creates a new position.
// @ID new-position
Expand All @@ -36,22 +36,22 @@ func (r *Repos) PositionList(c echo.Context) error {
// @Param event body clapper.Position true "Position object"
// @Success 201 body int "Position ID"
// @Router /v1/internal/clapper/positions [post]
func (r *Repos) PositionNew(c echo.Context) error {
func (r *Repos) NewPosition(c echo.Context) error {
p := clapper.Position{}
err := c.Bind(&p)
if err != nil {
err = fmt.Errorf("PositionNew: failed to bind to request json: %w", err)
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("PositionNew: failed to insert position: %w", err)
err = fmt.Errorf("NewPosition: failed to insert position: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusCreated, positionID)
}

// PositionUpdate updates an existing position
// UpdatePosition updates an existing position
// @Summary Update position
// @Description updates a position.
// @ID update-position
Expand All @@ -60,19 +60,19 @@ func (r *Repos) PositionNew(c echo.Context) error {
// @Param quote body clapper.Position true "Position object"
// @Success 200
// @Router /v1/internal/clapper/positions [put]
func (r *Repos) PositionUpdate(c echo.Context) error {
func (r *Repos) UpdatePosition(c echo.Context) error {
p := clapper.Position{}
err := c.Bind(&p)
if err != nil {
err = fmt.Errorf("PositionUpdate: failed to bind to request json: %w", err)
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) {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
err = fmt.Errorf("PositionUpdate failed: %w", err)
err = fmt.Errorf("UpdatePosition failed: %w", err)
return c.JSON(http.StatusInternalServerError, err)
}
return c.NoContent(http.StatusOK)
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/misc/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *Repos) NewQuote(c echo.Context) error {
}
claims, err := people.GetToken(c)
if err != nil {
err = fmt.Errorf("VideoNew failed to get user ID: %w", err)
err = fmt.Errorf("NewQupte failed to get user ID: %w", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
q.CreatedBy = claims.UserID
Expand Down
189 changes: 188 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-10-16 00:14:58.443439962 +0100 BST m=+0.050062649
// 2020-11-20 02:46:06.293999867 +0000 GMT m=+0.069829959

package docs

Expand Down Expand Up @@ -37,6 +37,7 @@ var doc = `{
"application/json"
],
"tags": [
"clapper",
"events"
],
"summary": "List events by month",
Expand Down Expand Up @@ -178,6 +179,7 @@ var doc = `{
"application/json"
],
"tags": [
"clapper",
"events"
],
"summary": "Get event by ID",
Expand All @@ -201,6 +203,121 @@ var doc = `{
}
}
},
"/v1/internal/clapper/event/{eventid}/signup": {
"post": {
"description": "Creates a new signup sheet, this is the sub part of an event\ncontaining the list of crew, with a little metadata on top.",
"consumes": [
"application/json"
],
"tags": [
"clapper",
"signups"
],
"summary": "New signup sheet",
"operationId": "new-signup",
"parameters": [
{
"description": "Signup object",
"name": "event",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/clapper.Signup"
}
}
],
"responses": {
"201": {
"description": "Event ID",
"schema": {
"type": "body"
}
}
}
}
},
"/v1/internal/clapper/event/{eventid}/{signupid}": {
"put": {
"description": "updates a signup sheet, to the body.",
"consumes": [
"application/json"
],
"tags": [
"clapper",
"signups"
],
"summary": "Update signup",
"operationId": "update-signup",
"parameters": [
{
"type": "integer",
"description": "Event ID",
"name": "eventid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Signup ID",
"name": "signupid",
"in": "path",
"required": true
},
{
"description": "Signup object",
"name": "quote",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/clapper.Signup"
}
}
],
"responses": {
"200": {}
}
}
},
"/v1/internal/clapper/event/{eventid}/{signupid}/{positionid}": {
"post": {
"description": "Creates a new crew object, that being a single person.",
"consumes": [
"application/json"
],
"tags": [
"clapper",
"crews"
],
"summary": "NewCrew",
"operationId": "new-crew",
"parameters": [
{
"type": "integer",
"description": "Event ID",
"name": "eventid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Signup ID",
"name": "signupid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Position ID",
"name": "crewid",
"in": "path",
"required": true
}
],
"responses": {
"200": {}
}
}
},
"/v1/internal/clapper/positions": {
"get": {
"description": "Lists all positions.",
Expand Down Expand Up @@ -280,6 +397,73 @@ var doc = `{
}
}
},
"/v1/internal/clapper/{eventid}/{signupid}": {
"delete": {
"description": "deletes a signup by ID.",
"tags": [
"clapper",
"signups"
],
"summary": "Delete signup",
"operationId": "delete-signup",
"parameters": [
{
"type": "integer",
"description": "Event ID",
"name": "signupid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Signup ID",
"name": "signupid",
"in": "path",
"required": true
}
],
"responses": {
"200": {}
}
}
},
"/v1/internal/clapper/{eventid}/{signupid}/{crewid}": {
"delete": {
"description": "deletes a crew position by ID.",
"tags": [
"clapper",
"signups"
],
"summary": "Delete crew",
"operationId": "delete-signup",
"parameters": [
{
"type": "integer",
"description": "Event ID",
"name": "signupid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Signup ID",
"name": "signupid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Crew ID",
"name": "signupid",
"in": "path",
"required": true
}
],
"responses": {
"200": {}
}
}
},
"/v1/internal/creator/calendar/{year}/{month}": {
"get": {
"description": "Lists videos by month.",
Expand Down Expand Up @@ -1514,6 +1698,9 @@ var doc = `{
"people.Permission": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
Expand Down
Loading

0 comments on commit 3d711d3

Please sign in to comment.