Skip to content

Commit

Permalink
back and frontend apis added with api call tests
Browse files Browse the repository at this point in the history
  • Loading branch information
euanwm committed Dec 31, 2023
1 parent 9625396 commit b56c923
Show file tree
Hide file tree
Showing 14 changed files with 3,306 additions and 366 deletions.
91 changes: 86 additions & 5 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/event": {
"/events": {
"post": {
"description": "Requires a case-sensitive event name to be passed to it. This is still a work in progress.",
"description": "Fetch a single event by ID and federation.",
"consumes": [
"application/json"
],
Expand All @@ -30,11 +30,20 @@ const docTemplate = `{
"tags": [
"POST Requests"
],
"summary": "Pull a specific event by name",
"summary": "Fetch a single event",
"parameters": [
{
"description": "name",
"name": "name",
"description": "Federation of the event",
"name": "federation",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "ID of the event",
"name": "id",
"in": "body",
"required": true,
"schema": {
Expand All @@ -59,6 +68,50 @@ const docTemplate = `{
"description": "No Content"
}
}
},
"options": {
"description": "Metadata shows the name, federation and date of the event along with the filename in the event_data folder.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"OPTIONS Requests"
],
"summary": "Fetch available event metadata within a set date range",
"parameters": [
{
"type": "string",
"description": "Start date to filter from",
"name": "startdate",
"in": "query"
},
{
"type": "string",
"description": "End date to filter to",
"name": "enddate",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/structs.EventsList"
}
}
}
},
"204": {
"description": "No Content"
}
}
}
},
"/history": {
Expand Down Expand Up @@ -363,6 +416,17 @@ const docTemplate = `{
}
}
},
"structs.EventsList": {
"type": "object",
"properties": {
"events": {
"type": "array",
"items": {
"$ref": "#/definitions/structs.SingleEventMetaData"
}
}
}
},
"structs.LeaderboardResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -404,6 +468,23 @@ const docTemplate = `{
}
}
}
},
"structs.SingleEventMetaData": {
"type": "object",
"properties": {
"date": {
"type": "string"
},
"federation": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}`
Expand Down
91 changes: 86 additions & 5 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"host": "api.openweightlifting.org",
"basePath": "/",
"paths": {
"/event": {
"/events": {
"post": {
"description": "Requires a case-sensitive event name to be passed to it. This is still a work in progress.",
"description": "Fetch a single event by ID and federation.",
"consumes": [
"application/json"
],
Expand All @@ -27,11 +27,20 @@
"tags": [
"POST Requests"
],
"summary": "Pull a specific event by name",
"summary": "Fetch a single event",
"parameters": [
{
"description": "name",
"name": "name",
"description": "Federation of the event",
"name": "federation",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "ID of the event",
"name": "id",
"in": "body",
"required": true,
"schema": {
Expand All @@ -56,6 +65,50 @@
"description": "No Content"
}
}
},
"options": {
"description": "Metadata shows the name, federation and date of the event along with the filename in the event_data folder.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"OPTIONS Requests"
],
"summary": "Fetch available event metadata within a set date range",
"parameters": [
{
"type": "string",
"description": "Start date to filter from",
"name": "startdate",
"in": "query"
},
{
"type": "string",
"description": "End date to filter to",
"name": "enddate",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/structs.EventsList"
}
}
}
},
"204": {
"description": "No Content"
}
}
}
},
"/history": {
Expand Down Expand Up @@ -360,6 +413,17 @@
}
}
},
"structs.EventsList": {
"type": "object",
"properties": {
"events": {
"type": "array",
"items": {
"$ref": "#/definitions/structs.SingleEventMetaData"
}
}
}
},
"structs.LeaderboardResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -401,6 +465,23 @@
}
}
}
},
"structs.SingleEventMetaData": {
"type": "object",
"properties": {
"date": {
"type": "string"
},
"federation": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
65 changes: 59 additions & 6 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ definitions:
total:
type: number
type: object
structs.EventsList:
properties:
events:
items:
$ref: '#/definitions/structs.SingleEventMetaData'
type: array
type: object
structs.LeaderboardResponse:
properties:
data:
Expand Down Expand Up @@ -93,6 +100,17 @@ definitions:
type: string
type: array
type: object
structs.SingleEventMetaData:
properties:
date:
type: string
federation:
type: string
id:
type: string
name:
type: string
type: object
host: api.openweightlifting.org
info:
contact:
Expand All @@ -102,16 +120,51 @@ info:
title: OpenWeightlifting API
version: "1.0"
paths:
/event:
/events:
options:
consumes:
- application/json
description: Metadata shows the name, federation and date of the event along
with the filename in the event_data folder.
parameters:
- description: Start date to filter from
in: query
name: startdate
type: string
- description: End date to filter to
in: query
name: enddate
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
items:
$ref: '#/definitions/structs.EventsList'
type: array
type: array
"204":
description: No Content
summary: Fetch available event metadata within a set date range
tags:
- OPTIONS Requests
post:
consumes:
- application/json
description: Requires a case-sensitive event name to be passed to it. This is
still a work in progress.
description: Fetch a single event by ID and federation.
parameters:
- description: name
- description: Federation of the event
in: body
name: name
name: federation
required: true
schema:
type: string
- description: ID of the event
in: body
name: id
required: true
schema:
type: string
Expand All @@ -128,7 +181,7 @@ paths:
type: array
"204":
description: No Content
summary: Pull a specific event by name
summary: Fetch a single event
tags:
- POST Requests
/history:
Expand Down
12 changes: 6 additions & 6 deletions backend/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,27 @@ func Leaderboard(c *gin.Context) {

// Events godoc
//
// @Summary Fetch event metadata within a set date range
// @Summary Fetch available event metadata within a set date range
// @Schemes
// @Description Metadata shows the name, federation and date of the event along with the filename in the event_data folder.
// @Tags GET Requests
// @Tags OPTIONS Requests
// @Param startdate query string false "Start date to filter from"
// @Param enddate query string false "End date to filter to"
// @Accept json
// @Produce json
// @Success 200 {array} []structs.SingleEventMetaData
// @Success 200 {array} []structs.EventsList
// @Failure 204 {object} nil
// @Router /events [get]
// @Router /events [options]
func Events(c *gin.Context) {
var response []structs.SingleEventMetaData
var response structs.EventsList
var query structs.EventSearch
if err := c.BindJSON(&query); err != nil {
abortErr := c.AbortWithError(http.StatusBadRequest, err)
log.Println(abortErr)
return
}

response = EventsData.FetchEventWithinDate(query.StartDate, query.EndDate)
response.Events = EventsData.FetchEventWithinDate(query.StartDate, query.EndDate)
c.JSON(http.StatusOK, response)
}

Expand Down
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func buildServer() *gin.Engine {
r.GET("search", SearchName)
r.POST("lifter", LifterRecord)
r.POST("history", LifterHistory)
r.GET("events", Events)
r.OPTIONS("events", Events)
r.POST("events", SingleEvent)
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
return r
Expand Down
Loading

0 comments on commit b56c923

Please sign in to comment.