Skip to content

Commit

Permalink
feat(locations): Create/Get/List locations
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstojda committed Jul 26, 2023
1 parent 49c14d7 commit 1526974
Show file tree
Hide file tree
Showing 11 changed files with 795 additions and 8 deletions.
6 changes: 4 additions & 2 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
inpackage: true
keeptree: true
inpackage: True
dir: "{{.InterfaceDir}}"
with-expecter: false
packages:
pinman/internal/utils:
interfaces:
# select the interfaces you want mocked
HttpDoer: {}
pinman/internal/clients/pinballmap:
interfaces:
ClientInterface: {}
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ keys:
@rm -r ./token ./token.pub

test-backend-cov: test-setup
@ginkgo --cover --race --json-report=report.json --output-dir=reports/go --skip-package generated ./...
@ginkgo --cover \
--race \
--json-report=report.json \
--output-dir=reports/go \
--skip-package generated \
--skip-file mock \
./...
173 changes: 172 additions & 1 deletion api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ paths:
get:
description: Refresh an access token
security:
- pinmanAuth: []
- pinmanAuth: [ ]
responses:
"200":
content:
Expand Down Expand Up @@ -173,6 +173,80 @@ paths:
$ref: "#/components/responses/notFound"
tags:
- leagues
###
# Location Endpoints
###
/locations:
get:
description: Retrieve a list of locations
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/locationListResponse'
description: Successful response
"400":
$ref: "#/components/responses/badRequest"
"401":
$ref: "#/components/responses/unauthorized"
"403":
$ref: "#/components/responses/forbidden"
tags:
- locations
post:
description: Create a new location
security:
- pinmanAuth:
- user
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/locationCreate'
required: true
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/locationResponse'
description: Location was created successfully
"400":
$ref: "#/components/responses/badRequest"
"401":
$ref: "#/components/responses/unauthorized"
"403":
$ref: "#/components/responses/forbidden"
tags:
- locations
/locations/{slug}:
get:
description: Retrieve a location by slug
parameters:
- in: path
name: slug
required: true
schema:
type: string
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/locationResponse'
description: Successful response
"400":
$ref: "#/components/responses/badRequest"
"401":
$ref: "#/components/responses/unauthorized"
"403":
$ref: "#/components/responses/forbidden"
"404":
$ref: "#/components/responses/notFound"
tags:
- locations

components:
responses:
unauthorized:
Expand Down Expand Up @@ -290,6 +364,55 @@ components:
- role
- created_at
- updated_at

location:
example:
id: id
name: name
address: address
slug: slug
pinball_map_id: pinball_map_id
created_at: created_at
updated_at: updated_at
properties:
id:
type: string
x-oapi-codegen-extra-tags:
binding: required
name:
type: string
x-oapi-codegen-extra-tags:
binding: required
address:
type: string
x-oapi-codegen-extra-tags:
binding: required
slug:
type: string
x-oapi-codegen-extra-tags:
binding: required
pinball_map_id:
type: integer
x-oapi-codegen-extra-tags:
binding: required
created_at:
type: string
x-oapi-codegen-extra-tags:
binding: required
updated_at:
type: string
x-oapi-codegen-extra-tags:
binding: required
type: object
required:
- id
- name
- address
- slug
- pinball_map_id
- created_at
- updated_at

###
# Generic Request/Response Schemas
###
Expand Down Expand Up @@ -429,6 +552,54 @@ components:
- name
- location
- slug

###
# Location Request/Response Schemas
###
locationResponse:
example:
location:
id: id
name: name
address: address
slug: slug
pinball_map_id: pinball_map_id
created_at: created_at
updated_at: updated_at
properties:
location:
$ref: '#/components/schemas/location'
type: object
locationListResponse:
example:
locations:
- id: id
name: name
address: address
slug: slug
pinball_map_id: pinball_map_id
created_at: created_at
updated_at: updated_at
properties:
locations:
type: array
items:
$ref: '#/components/schemas/location'
type: object
required:
- locations
locationCreate:
example:
pinball_map_id: pinball_map_id
properties:
pinball_map_id:
type: integer
x-oapi-codegen-extra-tags:
binding: required
type: object
required:
- pinball_map_id

securitySchemes:
pinmanAuth:
flows:
Expand Down
18 changes: 16 additions & 2 deletions internal/app/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"github.com/gin-gonic/gin"
"pinman/internal/app/api/league"
"pinman/internal/app/api/location"
"pinman/internal/app/api/user"
)

Expand All @@ -14,8 +15,9 @@ type AuthHandlers struct {
// Server
// implements generated.ServerInterface
type Server struct {
User *user.Controller
League *league.Controller
User *user.Controller
League *league.Controller
Location *location.Controller
AuthHandlers
}

Expand Down Expand Up @@ -46,3 +48,15 @@ func (s *Server) GetLeagues(c *gin.Context) {
func (s *Server) GetLeaguesSlug(c *gin.Context, slug string) {
s.League.GetLeagueWithSlug(c, slug)
}

func (s *Server) GetLocations(c *gin.Context) {
s.Location.ListLocations(c)
}

func (s *Server) PostLocations(c *gin.Context) {
s.Location.CreateLocation(c)
}

func (s *Server) GetLocationsSlug(c *gin.Context, slug string) {
s.Location.GetLocationWithSlug(c, slug)
}
Loading

0 comments on commit 1526974

Please sign in to comment.