Skip to content

Commit

Permalink
Add poker story put api endpoint
Browse files Browse the repository at this point in the history
This resolves #645
  • Loading branch information
StevenWeathers committed Oct 30, 2024
1 parent 6bd4d52 commit a68906b
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 1 deletion.
86 changes: 86 additions & 0 deletions docs/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,66 @@ const docTemplate = `{
}
},
"/battles/{battleId}/plans/{planId}": {
"put": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Updates a poker story",
"produces": [
"application/json"
],
"tags": [
"poker"
],
"summary": "Update Poker Story",
"parameters": [
{
"type": "string",
"description": "the poker game ID",
"name": "battleId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "the poker story ID",
"name": "planId",
"in": "path",
"required": true
},
{
"description": "updated story object",
"name": "story",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/http.storyUpdateRequestBody"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/http.standardJsonResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/http.standardJsonResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/http.standardJsonResponse"
}
}
}
},
"delete": {
"security": [
{
Expand Down Expand Up @@ -11117,6 +11177,32 @@ const docTemplate = `{
}
}
},
"http.storyUpdateRequestBody": {
"type": "object",
"properties": {
"acceptanceCriteria": {
"type": "string"
},
"description": {
"type": "string"
},
"link": {
"type": "string"
},
"planName": {
"type": "string"
},
"priority": {
"type": "integer"
},
"referenceId": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"http.storyboardColumnAddRequestBody": {
"type": "object",
"required": [
Expand Down
86 changes: 86 additions & 0 deletions docs/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,66 @@
}
},
"/battles/{battleId}/plans/{planId}": {
"put": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Updates a poker story",
"produces": [
"application/json"
],
"tags": [
"poker"
],
"summary": "Update Poker Story",
"parameters": [
{
"type": "string",
"description": "the poker game ID",
"name": "battleId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "the poker story ID",
"name": "planId",
"in": "path",
"required": true
},
{
"description": "updated story object",
"name": "story",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/http.storyUpdateRequestBody"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/http.standardJsonResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/http.standardJsonResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/http.standardJsonResponse"
}
}
}
},
"delete": {
"security": [
{
Expand Down Expand Up @@ -11109,6 +11169,32 @@
}
}
},
"http.storyUpdateRequestBody": {
"type": "object",
"properties": {
"acceptanceCriteria": {
"type": "string"
},
"description": {
"type": "string"
},
"link": {
"type": "string"
},
"planName": {
"type": "string"
},
"priority": {
"type": "integer"
},
"referenceId": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"http.storyboardColumnAddRequestBody": {
"type": "object",
"required": [
Expand Down
56 changes: 56 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,23 @@ definitions:
success:
type: boolean
type: object
http.storyUpdateRequestBody:
properties:
acceptanceCriteria:
type: string
description:
type: string
link:
type: string
planName:
type: string
priority:
type: integer
referenceId:
type: string
type:
type: string
type: object
http.storyboardColumnAddRequestBody:
properties:
goalId:
Expand Down Expand Up @@ -3427,6 +3444,45 @@ paths:
summary: Delete Poker Story
tags:
- poker
put:
description: Updates a poker story
parameters:
- description: the poker game ID
in: path
name: battleId
required: true
type: string
- description: the poker story ID
in: path
name: planId
required: true
type: string
- description: updated story object
in: body
name: story
required: true
schema:
$ref: '#/definitions/http.storyUpdateRequestBody'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/http.standardJsonResponse'
"403":
description: Forbidden
schema:
$ref: '#/definitions/http.standardJsonResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/http.standardJsonResponse'
security:
- ApiKeyAuth: []
summary: Update Poker Story
tags:
- poker
/estimation-scales/public:
get:
description: get list of all public estimation scales
Expand Down
1 change: 1 addition & 0 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func New(apiService Service, FSS fs.FS, HFS http.FileSystem) *Service {
apiRouter.HandleFunc("/battles/{battleId}", a.userOnly(a.handleGetPokerGame())).Methods("GET")
apiRouter.HandleFunc("/battles/{battleId}", a.userOnly(a.handlePokerDelete(pokerSvc))).Methods("DELETE")
apiRouter.HandleFunc("/battles/{battleId}/plans", a.userOnly(a.handlePokerStoryAdd(pokerSvc))).Methods("POST")
apiRouter.HandleFunc("/battles/{battleId}/plans/{planId}", a.userOnly(a.handlePokerStoryUpdate(pokerSvc))).Methods("PUT")
apiRouter.HandleFunc("/battles/{battleId}/plans/{planId}", a.userOnly(a.handlePokerStoryDelete(pokerSvc))).Methods("DELETE")
apiRouter.HandleFunc("/arena/{battleId}", pokerSvc.ServeBattleWs())

Expand Down
89 changes: 88 additions & 1 deletion internal/http/poker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http

import (
"encoding/json"
"fmt"
"io"
"net/http"
"slices"
Expand Down Expand Up @@ -354,7 +355,93 @@ func (s *Service) handlePokerStoryAdd(pokerSvc *poker.Service) http.HandlerFunc
}
}

// handlePokerStoryAdd handles deleting a story from poker
type storyUpdateRequestBody struct {
ID string `json:"planId" swaggerignore:"true"`
Name string `json:"planName"`
Type string `json:"type"`
ReferenceID string `json:"referenceId"`
Link string `json:"link"`
Description string `json:"description"`
AcceptanceCriteria string `json:"acceptanceCriteria"`
Priority int32 `json:"priority"`
}

// handlePokerStoryUpdate handles updating a poker story
//
// @Summary Update Poker Story
// @Description Updates a poker story
// @Param battleId path string true "the poker game ID"
// @Param planId path string true "the poker story ID"
// @Param story body storyUpdateRequestBody true "updated story object"
// @Tags poker
// @Produce json
// @Success 200 object standardJsonResponse{}
// @Success 403 object standardJsonResponse{}
// @Success 500 object standardJsonResponse{}
// @Security ApiKeyAuth
// @Router /battles/{battleId}/plans/{planId} [put]
func (s *Service) handlePokerStoryUpdate(pokerSvc *poker.Service) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
gameID := vars["battleId"]
idErr := validate.Var(gameID, "required,uuid")
if idErr != nil {
s.Failure(w, r, http.StatusBadRequest, Errorf(
EINVALID, fmt.Errorf("invalid battleId: %v", idErr.Error()).Error()),
)
return
}
storyID := vars["planId"]
idErr = validate.Var(storyID, "required,uuid")
if idErr != nil {
s.Failure(w, r, http.StatusBadRequest, Errorf(
EINVALID, fmt.Errorf("invalid storyId: %v", idErr.Error()).Error()),
)
return
}
sessionUserID := ctx.Value(contextKeyUserID).(string)

body, bodyErr := io.ReadAll(r.Body)
if bodyErr != nil {
s.Failure(w, r, http.StatusBadRequest, Errorf(EINVALID, bodyErr.Error()))
return
}

var story = storyUpdateRequestBody{}
jsonErr := json.Unmarshal(body, &story)
if jsonErr != nil {
s.Failure(w, r, http.StatusBadRequest, Errorf(EINVALID, jsonErr.Error()))
return
}

story.ID = storyID
inputErr := validate.Struct(story)
if inputErr != nil {
s.Failure(w, r, http.StatusBadRequest, Errorf(EINVALID, inputErr.Error()))
return
}

updatedStory, err := json.Marshal(story)
if err != nil {
s.Failure(w, r, http.StatusInternalServerError, Errorf(EINTERNAL, err.Error()))
return
}

err = pokerSvc.APIEvent(ctx, gameID, sessionUserID, "revise_plan", string(updatedStory))
if err != nil {
s.Logger.Ctx(ctx).Error("handlePokerStoryUpdate error", zap.Error(err),
zap.String("poker_id", gameID), zap.String("session_user_id", sessionUserID),
zap.String("story_id", storyID))
s.Failure(w, r, http.StatusInternalServerError, err)
return
}

s.Success(w, r, http.StatusOK, nil, nil)
}
}

// handlePokerStoryDelete handles deleting a story from poker
//
// @Summary Delete Poker Story
// @Description Deletes a poker story
Expand Down

0 comments on commit a68906b

Please sign in to comment.