Skip to content
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

Add project member count group by project role #235

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,12 @@ const docTemplate = `{
"name": "projectId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "project member search by query (query=all), (query=leader), (query=member), (query=viewer)",
"name": "query",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -3244,6 +3250,50 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/projects/{projectId}/members/project-roles/count": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get project member count group by project role",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Projects"
],
"summary": "Get project member count group by project role",
"parameters": [
{
"type": "string",
"description": "Organization ID",
"name": "organizationId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Project ID",
"name": "projectId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.GetProjectMemberCountResponse"
}
}
}
}
},
"/organizations/{organizationId}/projects/{projectId}/members/{projectMemberId}": {
"get": {
"security": [
Expand Down Expand Up @@ -6565,6 +6615,23 @@ const docTemplate = `{
}
}
},
"domain.GetProjectMemberCountResponse": {
"type": "object",
"properties": {
"projectLeaderCount": {
"type": "integer"
},
"projectMemberAllCount": {
"type": "integer"
},
"projectMemberCount": {
"type": "integer"
},
"projectViewerCount": {
"type": "integer"
}
}
},
"domain.GetProjectMemberResponse": {
"type": "object",
"properties": {
Expand Down
67 changes: 67 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3072,6 +3072,12 @@
"name": "projectId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "project member search by query (query=all), (query=leader), (query=member), (query=viewer)",
"name": "query",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -3237,6 +3243,50 @@
}
}
},
"/organizations/{organizationId}/projects/{projectId}/members/project-roles/count": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get project member count group by project role",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Projects"
],
"summary": "Get project member count group by project role",
"parameters": [
{
"type": "string",
"description": "Organization ID",
"name": "organizationId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Project ID",
"name": "projectId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.GetProjectMemberCountResponse"
}
}
}
}
},
"/organizations/{organizationId}/projects/{projectId}/members/{projectMemberId}": {
"get": {
"security": [
Expand Down Expand Up @@ -6558,6 +6608,23 @@
}
}
},
"domain.GetProjectMemberCountResponse": {
"type": "object",
"properties": {
"projectLeaderCount": {
"type": "integer"
},
"projectMemberAllCount": {
"type": "integer"
},
"projectMemberCount": {
"type": "integer"
},
"projectViewerCount": {
"type": "integer"
}
}
},
"domain.GetProjectMemberResponse": {
"type": "object",
"properties": {
Expand Down
44 changes: 44 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,17 @@ definitions:
type: string
type: object
type: object
domain.GetProjectMemberCountResponse:
properties:
projectLeaderCount:
type: integer
projectMemberAllCount:
type: integer
projectMemberCount:
type: integer
projectViewerCount:
type: integer
type: object
domain.GetProjectMemberResponse:
properties:
projectMember:
Expand Down Expand Up @@ -4170,6 +4181,11 @@ paths:
name: projectId
required: true
type: string
- description: project member search by query (query=all), (query=leader), (query=member),
(query=viewer)
in: query
name: query
type: string
produces:
- application/json
responses:
Expand Down Expand Up @@ -4352,6 +4368,34 @@ paths:
summary: Update project member Role
tags:
- Projects
/organizations/{organizationId}/projects/{projectId}/members/project-roles/count:
get:
consumes:
- application/json
description: Get project member count group by project role
parameters:
- description: Organization ID
in: path
name: organizationId
required: true
type: string
- description: Project ID
in: path
name: projectId
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.GetProjectMemberCountResponse'
security:
- JWT: []
summary: Get project member count group by project role
tags:
- Projects
/organizations/{organizationId}/projects/{projectId}/namespaces:
get:
consumes:
Expand Down
76 changes: 72 additions & 4 deletions internal/delivery/http/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type IProjectHandler interface {
AddProjectMember(w http.ResponseWriter, r *http.Request)
GetProjectMember(w http.ResponseWriter, r *http.Request)
GetProjectMembers(w http.ResponseWriter, r *http.Request)
GetProjectMemberCount(w http.ResponseWriter, r *http.Request)
RemoveProjectMember(w http.ResponseWriter, r *http.Request)
RemoveProjectMembers(w http.ResponseWriter, r *http.Request)
UpdateProjectMemberRole(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -563,6 +564,7 @@ func (p ProjectHandler) GetProjectMember(w http.ResponseWriter, r *http.Request)
// @Produce json
// @Param organizationId path string true "Organization ID"
// @Param projectId path string true "Project ID"
// @Param query query string false "project member search by query (query=all), (query=leader), (query=member), (query=viewer)"
// @Success 200 {object} domain.GetProjectMembersResponse
// @Router /organizations/{organizationId}/projects/{projectId}/members [get]
// @Security JWT
Expand All @@ -583,13 +585,38 @@ func (p ProjectHandler) GetProjectMembers(w http.ResponseWriter, r *http.Request
return
}

pms, err := p.usecase.GetProjectMembersByProjectId(projectId)
urlParams := r.URL.Query()

queryParam := urlParams.Get("query")
query := usecase.ProjectAll
if queryParam == "" || strings.EqualFold(queryParam, "all") {
query = usecase.ProjectAll
} else if strings.EqualFold(queryParam, "leader") {
query = usecase.ProjectLeader
} else if strings.EqualFold(queryParam, "member") {
query = usecase.ProjectMember
} else if strings.EqualFold(queryParam, "viewer") {
query = usecase.ProjectViewer
} else {
log.ErrorWithContext(r.Context(), "Invalid query params. Err: ")
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid query params"),
"C_INVALID_QUERY_PARAM", ""))
return
}

pms, err := p.usecase.GetProjectMembers(projectId, query)
if err != nil {
log.ErrorWithContext(r.Context(), "Failed to get project roles ", err)
log.ErrorWithContext(r.Context(), "Failed to get project members ", err)
ErrorJSON(w, r, err)
return
}

var out domain.GetProjectMembersResponse
if pms == nil {
ResponseJSON(w, r, http.StatusNotFound, out)
return
}

pmrs := make([]domain.ProjectMemberResponse, 0)
for _, pm := range pms {
pmr := domain.ProjectMemberResponse{
Expand All @@ -608,11 +635,52 @@ func (p ProjectHandler) GetProjectMembers(w http.ResponseWriter, r *http.Request
pmrs = append(pmrs, pmr)
}

out := domain.GetProjectMembersResponse{ProjectMembers: pmrs}

out = domain.GetProjectMembersResponse{ProjectMembers: pmrs}
ResponseJSON(w, r, http.StatusOK, out)
}

// GetProjectMemberCount godoc
// @Tags Projects
// @Summary Get project member count group by project role
// @Description Get project member count group by project role
// @Accept json
// @Produce json
// @Param organizationId path string true "Organization ID"
// @Param projectId path string true "Project ID"
// @Success 200 {object} domain.GetProjectMemberCountResponse
// @Router /organizations/{organizationId}/projects/{projectId}/members/project-roles/count [get]
// @Security JWT
func (p ProjectHandler) GetProjectMemberCount(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
log.Debugf("organizationId = [%v]\n", organizationId)
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid organizationId"),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

projectId, ok := vars["projectId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid projectId"),
"C_INVALID_PROJECT_ID", ""))
return
}

pmcr, err := p.usecase.GetProjectMemberCount(projectId)
if err != nil {
log.ErrorWithContext(r.Context(), "Failed to get project member count", err)
ErrorJSON(w, r, err)
return
}

if pmcr == nil {
ResponseJSON(w, r, http.StatusNotFound, domain.GetProjectMembersResponse{})
return
}
ResponseJSON(w, r, http.StatusOK, pmcr)
}

// RemoveProjectMember godoc
// @Tags Projects
// @Summary Remove project members to project
Expand Down
Loading
Loading