Skip to content

Commit

Permalink
Merge pull request #14 from justinfarrelldev/update-lobby
Browse files Browse the repository at this point in the history
Added ability to update lobbies once they have been created
  • Loading branch information
justinfarrelldev authored Nov 25, 2024
2 parents a0fa8bc + 8aaf2af commit a02a0ae
Show file tree
Hide file tree
Showing 9 changed files with 610 additions and 12 deletions.
94 changes: 94 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,52 @@ const docTemplate = `{
}
}
}
},
"/lobby/update_lobby": {
"put": {
"description": "This endpoint updates a lobby's info.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"lobby"
],
"summary": "Updates a lobby",
"parameters": [
{
"description": "lobby update request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/lobby.UpdateLobbyArgs"
}
}
],
"responses": {
"200": {
"description": "Successfully updated lobby!",
"schema": {
"type": "string"
}
},
"400": {
"description": "lobby_id must be specified",
"schema": {
"type": "string"
}
},
"500": {
"description": "an error occurred while decoding the request body: \u003cerror message\u003e",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -516,6 +562,54 @@ const docTemplate = `{
"type": "string"
}
}
},
"lobby.LobbyParam": {
"description": "Structure for representing a player lobby with non-required fields.",
"type": "object",
"properties": {
"id": {
"description": "ID is the unique identifier for the lobby.",
"type": "integer"
},
"is_closed": {
"description": "IsClosed indicates if the lobby is closed.",
"type": "boolean"
},
"is_muted": {
"description": "IsMuted indicates if the lobby is muted.",
"type": "boolean"
},
"is_public": {
"description": "IsPublic indicates if the lobby is public.",
"type": "boolean"
},
"name": {
"description": "Name is the name of the lobby.",
"type": "string"
},
"owner_name": {
"description": "OwnerName is the name of the lobby owner.",
"type": "string"
}
}
},
"lobby.UpdateLobbyArgs": {
"description": "Structure for the lobby update request payload.",
"type": "object",
"properties": {
"lobby": {
"description": "The lobby to update.",
"allOf": [
{
"$ref": "#/definitions/lobby.LobbyParam"
}
]
},
"lobby_id": {
"description": "The lobby ID for the lobby that will be updated.",
"type": "integer"
}
}
}
}
}`
Expand Down
94 changes: 94 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,52 @@
}
}
}
},
"/lobby/update_lobby": {
"put": {
"description": "This endpoint updates a lobby's info.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"lobby"
],
"summary": "Updates a lobby",
"parameters": [
{
"description": "lobby update request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/lobby.UpdateLobbyArgs"
}
}
],
"responses": {
"200": {
"description": "Successfully updated lobby!",
"schema": {
"type": "string"
}
},
"400": {
"description": "lobby_id must be specified",
"schema": {
"type": "string"
}
},
"500": {
"description": "an error occurred while decoding the request body: \u003cerror message\u003e",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -507,6 +553,54 @@
"type": "string"
}
}
},
"lobby.LobbyParam": {
"description": "Structure for representing a player lobby with non-required fields.",
"type": "object",
"properties": {
"id": {
"description": "ID is the unique identifier for the lobby.",
"type": "integer"
},
"is_closed": {
"description": "IsClosed indicates if the lobby is closed.",
"type": "boolean"
},
"is_muted": {
"description": "IsMuted indicates if the lobby is muted.",
"type": "boolean"
},
"is_public": {
"description": "IsPublic indicates if the lobby is public.",
"type": "boolean"
},
"name": {
"description": "Name is the name of the lobby.",
"type": "string"
},
"owner_name": {
"description": "OwnerName is the name of the lobby owner.",
"type": "string"
}
}
},
"lobby.UpdateLobbyArgs": {
"description": "Structure for the lobby update request payload.",
"type": "object",
"properties": {
"lobby": {
"description": "The lobby to update.",
"allOf": [
{
"$ref": "#/definitions/lobby.LobbyParam"
}
]
},
"lobby_id": {
"description": "The lobby ID for the lobby that will be updated.",
"type": "integer"
}
}
}
}
}
64 changes: 64 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,39 @@ definitions:
description: OwnerName is the name of the lobby owner.
type: string
type: object
lobby.LobbyParam:
description: Structure for representing a player lobby with non-required fields.
properties:
id:
description: ID is the unique identifier for the lobby.
type: integer
is_closed:
description: IsClosed indicates if the lobby is closed.
type: boolean
is_muted:
description: IsMuted indicates if the lobby is muted.
type: boolean
is_public:
description: IsPublic indicates if the lobby is public.
type: boolean
name:
description: Name is the name of the lobby.
type: string
owner_name:
description: OwnerName is the name of the lobby owner.
type: string
type: object
lobby.UpdateLobbyArgs:
description: Structure for the lobby update request payload.
properties:
lobby:
allOf:
- $ref: '#/definitions/lobby.LobbyParam'
description: The lobby to update.
lobby_id:
description: The lobby ID for the lobby that will be updated.
type: integer
type: object
info:
contact:
email: [email protected]
Expand Down Expand Up @@ -355,4 +388,35 @@ paths:
summary: Gets a lobby
tags:
- lobby
/lobby/update_lobby:
put:
consumes:
- application/json
description: This endpoint updates a lobby's info.
parameters:
- description: lobby update request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/lobby.UpdateLobbyArgs'
produces:
- application/json
responses:
"200":
description: Successfully updated lobby!
schema:
type: string
"400":
description: lobby_id must be specified
schema:
type: string
"500":
description: 'an error occurred while decoding the request body: <error
message>'
schema:
type: string
summary: Updates a lobby
tags:
- lobby
swagger: "2.0"
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ module github.com/justinfarrelldev/open-ctp-server
go 1.23.0

require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/didip/tollbooth/v7 v7.0.2
github.com/flowchartsman/swaggerui v0.0.0-20221017034628-909ed4f3701b
github.com/jmoiron/sqlx v1.4.0
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/swaggo/swag v1.16.3
golang.org/x/crypto v0.26.0
)

require (
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
Expand All @@ -21,7 +22,6 @@ require (
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-pkgz/expirable-cache/v3 v3.0.0 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
golang.org/x/net v0.25.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
Expand Down Expand Up @@ -27,6 +28,7 @@ github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyr
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-pkgz/expirable-cache/v3 v3.0.0 h1:u3/gcu3sabLYiTCevoRKv+WzjIn5oo7P8XtiXBeRDLw=
github.com/go-pkgz/expirable-cache/v3 v3.0.0/go.mod h1:2OQiDyEGQalYecLWmXprm3maPXeVb5/6/X7yRPYTzec=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
Expand All @@ -48,6 +50,7 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand Down
14 changes: 7 additions & 7 deletions internal/lobby/lobby_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func GetLobbyHandler(w http.ResponseWriter, r *http.Request, db *sqlx.DB) {
}
}

// func UpdateLobbyHandler(w http.ResponseWriter, r *http.Request, db *sql.DB) {
// if err := UpdateLobby(w, r, db); err != nil {
// // Handle the error, e.g., log it and send an appropriate response to the client
// http.Error(w, err.Error(), http.StatusInternalServerError)
// return
// }
// }
func UpdateLobbyHandler(w http.ResponseWriter, r *http.Request, db *sqlx.DB) {
if err := UpdateLobby(w, r, db); err != nil {
// Handle the error, e.g., log it and send an appropriate response to the client
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
Loading

0 comments on commit a02a0ae

Please sign in to comment.