-
Notifications
You must be signed in to change notification settings - Fork 2
[GUN-12] Create GET /teams/:teamname/members route #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
177a660
18c746f
9064219
e83fc1e
1394b9f
262c169
a3df2df
27dbced
69115a7
316c28d
d83fefb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { | ||
| teamName := ctx.Param("teamname") | ||
|
|
||
| if teamName == "" { | ||
| sendError(ctx, 404, "Team name is required") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{}) | ||
|
rodrigofmeneses marked this conversation as resolved.
|
||
|
|
||
| if err != nil { | ||
| sendError(ctx, 404, "Team not found") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| sendSuccess(ctx, "ListTeamMembers", members) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean |
||
| db = config.GetDatabase() | ||
| } | ||
|
|
||
| // @BasePath /api/v1 | ||
|
|
||
| // @Summary Ping the server | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ import ( | |
|
|
||
| // initializeRoutes sets up the routes for the application | ||
| func initializeRoutes(r *gin.Engine) { | ||
| // Initialize handler | ||
| handler.InitiliazeHandler() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: |
||
|
|
||
| // Set the base path for all routes | ||
| basePath := "/api/v1" | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,10 @@ type Team struct { | |
| Name string | ||
| } | ||
|
|
||
| type TeamNameRequest struct { | ||
| name string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attribute |
||
| } | ||
|
|
||
| type TeamResponse struct { | ||
| ID uint `json:"id"` | ||
| CreatedAt time.Time `json:"createdAt"` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names
ListTeamandgetTeam, they have the same meaning, what do you think about choosing one to have a consistent nomenclature? Make sense?