Skip to content
Open
93 changes: 77 additions & 16 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ definitions:
handler.PingServerResponse:
properties:
data:
$ref: '#/definitions/schemas.PingResponse'
$ref: "#/definitions/schemas.PingResponse"
message:
type: string
type: object
Expand Down Expand Up @@ -65,50 +65,111 @@ definitions:
type: string
type: object
type: object
schema.TeamNamePayload:
properties:
teamname:
type: string
schema.TeamMembersResponse:
properties:
data:
type: array
items:
properties:
id:
type: integer
githubId:
type: integer
url:
type: string
login:
type: string
role:
type: string
team:
type: string
createdAt:
type: string
updatedAt:
type: string
deletedAt:
type: string
message:
type: string
type: object
info:
contact: {}
paths:
/ping:
get:
consumes:
- application/json
- application/json
description: Ping the server to check if it is running
produces:
- application/json
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.PingServerResponse'
$ref: "#/definitions/handler.PingServerResponse"
summary: Ping the server
tags:
- Ping
- Ping
/webhook:
post:
consumes:
- application/json
- application/json
description: Handle with GitHub Webhook Payload
parameters:
- description: Github webhook payload
in: body
name: request
required: true
schema:
$ref: '#/definitions/service.GithubWebhookUserManagePayload'
- description: Github webhook payload
in: body
name: request
required: true
schema:
$ref: "#/definitions/service.GithubWebhookUserManagePayload"
produces:
- application/json
- application/json
responses:
"200":
description: OK
"400":
description: Bad Request
schema:
$ref: '#/definitions/handler.ErrorResponse'
$ref: "#/definitions/handler.ErrorResponse"
"500":
description: Server Error
schema:
$ref: '#/definitions/handler.ErrorResponse'
$ref: "#/definitions/handler.ErrorResponse"
summary: Github Webhook Membership Receiver
tags:
- Webhook
- Webhook
/teams/:teamname/members:
get:
consumes:
- application/json
description: Returns list of members from a team
parameters:
- description: Team name
in: body
name: teamname
required: true
schema:
$ref: "#/definitions/schema.TeamNamePayload"
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: "#/definitions/schema.TeamMembersResponse"
"400":
description: Bad Request
schema:
$ref: "#/definitions/handler.ErrorResponse"
"500":
description: Server Error
schema:
$ref: "#/definitions/handler.ErrorResponse"
summary: Team members list
tags:
- Team
swagger: "2.0"
32 changes: 32 additions & 0 deletions handler/getTeamMembers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package handler

import (
"github.com/forjadev/gun-organization/schemas"
"github.com/gin-gonic/gin"
)

// @Summary Returns the list of team members
// @Description Returns the list of members of specific team
// @Tags Teams
// @Accept json
// @Produce json
// @Success 200 {object} ListTeamMembersResponse
// @Router /team/{teamname}/members [get]
func ListTeamMembersHandler(ctx *gin.Context) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names ListTeam and getTeam, they have the same meaning, what do you think about choosing one to have a consistent nomenclature? Make sense?

teamName := ctx.Param("teamname")

if teamName == "" {
sendError(ctx, 404, "Team name is required")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use the http.StatusNotFound instead of the hardcoded http code for easy documentation and reading, what you think?

return
}

members := []schemas.Member{}

err := db.Joins("JOIN teams ON teams.team_id = member.team_id").Where("teams.name = ?", teamName).Find(&schemas.Member{})
Comment thread
rodrigofmeneses marked this conversation as resolved.

if err != nil {
sendError(ctx, 404, "Team not found")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

sendSuccess(ctx, "ListTeamMembers", members)
}
8 changes: 8 additions & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ package handler
import (
"net/http"

"github.com/forjadev/gun-organization/config"
"github.com/forjadev/gun-organization/schemas"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

var db *gorm.DB

func InitiliazeHandler() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean Initialize?

db = config.GetDatabase()
}

// @BasePath /api/v1

// @Summary Ping the server
Expand Down
4 changes: 4 additions & 0 deletions router/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (

// initializeRoutes sets up the routes for the application
func initializeRoutes(r *gin.Engine) {
// Initialize handler
handler.InitiliazeHandler()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:
#23 (comment)


// Set the base path for all routes
basePath := "/api/v1"

Expand All @@ -24,6 +27,7 @@ func initializeRoutes(r *gin.Engine) {
// Define a GET route for the /ping endpoint
v1.GET("/ping", handler.PingServerHandler)
v1.POST("/webhook", handler.GitHubWebhookHandler)
v1.GET("/teams/:teamname/members", handler.ListTeamMembersHandler)
}

// Initialize Swagger documentation
Expand Down
4 changes: 4 additions & 0 deletions schemas/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ type Team struct {
Name string
}

type TeamNameRequest struct {
name string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute name should be in lowercase?

}

type TeamResponse struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"createdAt"`
Expand Down