Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CAS735-F23/macrun-archless-team int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
leonliu288 committed Dec 6, 2023
2 parents 29f79f9 + 068ab55 commit cddbe63
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 18 deletions.
33 changes: 33 additions & 0 deletions game-service/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ type startQuery struct {
Location dto.PointDTO `form:"location"`
}

// handleGameStart godoc
// @Summary Start Game Session
// @Schemes
// @Description start game
// @Tags
// @Accept json
// @Produce json
// @Param username body string true "player username"
// @Success 200 {object} responseMessage
// @Router /game/start [post]
func handleGameStart(app *game.App) gin.HandlerFunc {
return func(c *gin.Context) {
query := &startQuery{}
Expand Down Expand Up @@ -54,6 +64,16 @@ type stopQuery struct {
Username string `form:"username" binding:"required"`
}

// handleGameStop godoc
// @Summary Stop Game Session
// @Schemes
// @Description stop game
// @Tags
// @Accept json
// @Produce json
// @Param username body string true "player username"
// @Success 200 {object} responseMessage
// @Router /game/stop [post]
func handleGameStop(app *game.App) gin.HandlerFunc {
return func(c *gin.Context) {
query := &stopQuery{}
Expand Down Expand Up @@ -89,6 +109,19 @@ type actionQuery struct {
Location dto.PointDTO `form:"location"`
}

// handleGameAction godoc
// @Summary Update Game Action
// @Schemes
// @Description update game action
// @Tags
// @Accept json
// @Produce json
// @Param username body string true "player username"
// @Param action body string false "player action"
// @Param type body string true "player workout type"
// @Param location body dto.PointDTO true "player current location"
// @Success 200 {object} responseMessage
// @Router /game/action [post]
func handleGameAction(app *game.App) gin.HandlerFunc {
return func(c *gin.Context) {
query := &actionQuery{}
Expand Down
6 changes: 6 additions & 0 deletions game-service/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import (

"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"

"game-service/consts"
"game-service/docs"
"game-service/game"
)

Expand Down Expand Up @@ -38,6 +41,9 @@ func New(app *game.App) *gin.Engine {
// index page
r.GET("/", getIndex())

r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))

docs.SwaggerInfo.BasePath = "/game"
gm := r.Group("/game")
{
gm.POST("/start", handleGameStart(app))
Expand Down
190 changes: 190 additions & 0 deletions game-service/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/game/action": {
"post": {
"description": "update game action",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
""
],
"summary": "Update Game Action",
"parameters": [
{
"description": "player username",
"name": "username",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "player action",
"name": "action",
"in": "body",
"schema": {
"type": "string"
}
},
{
"description": "player workout type",
"name": "type",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "player current location",
"name": "location",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.PointDTO"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.responseMessage"
}
}
}
}
},
"/game/start": {
"post": {
"description": "start game",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
""
],
"summary": "Start Game Session",
"parameters": [
{
"description": "player username",
"name": "username",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.responseMessage"
}
}
}
}
},
"/game/stop": {
"post": {
"description": "stop game",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
""
],
"summary": "Stop Game Session",
"parameters": [
{
"description": "player username",
"name": "username",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.responseMessage"
}
}
}
}
}
},
"definitions": {
"api.responseMessage": {
"type": "object",
"properties": {
"data": {},
"message": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"dto.PointDTO": {
"type": "object",
"properties": {
"x": {
"type": "number"
},
"y": {
"type": "number"
}
}
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
Loading

0 comments on commit cddbe63

Please sign in to comment.