Skip to content

Commit

Permalink
updated list invitations to make it generic
Browse files Browse the repository at this point in the history
Signed-off-by: Saranya-jena <saranya.jena@harness.io>
  • Loading branch information
Saranya-jena committed Aug 3, 2023
1 parent 87eee12 commit f123d67
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ func getInvitation(service services.ApplicationService, member entities.MemberIn
func ListInvitations(service services.ApplicationService) gin.HandlerFunc {
return func(c *gin.Context) {
uID := c.MustGet("uid").(string)
invitation_state := c.Param("invitation_state")
var response []entities.ListInvitationResponse
projects, err := service.ListInvitations(uID)
projects, err := service.ListInvitations(uID, entities.Invitation(invitation_state))
if err != nil {
log.Errorf("Error while fetching invitations: %v", err)
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/authentication/api/routes/project_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ProjectRouter(router *gin.Engine, service services.ApplicationService) {
router.GET("/get_project_role/:project_id", rest.GetProjectRole(service))
router.GET("/list_projects", rest.GetProjectsByUserID(service))
router.GET("/get_projects_stats", rest.GetProjectStats(service))
router.GET("/list_invitations", rest.ListInvitations(service))
router.GET("/list_invitations_with_filters/:invitation_state", rest.ListInvitations(service))
router.POST("/create_project", rest.CreateProject(service))
router.POST("/send_invitation", rest.SendInvitation(service))
router.POST("/accept_invitation", rest.AcceptInvitation(service))
Expand Down
8 changes: 4 additions & 4 deletions chaoscenter/authentication/pkg/project/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Repository interface {
GetOwnerProjects(ctx context.Context, userID string) ([]*entities.Project, error)
GetProjectRole(projectID string, userID string) (*entities.MemberRole, error)
GetProjectMembers(projectID string, state string) ([]*entities.Member, error)
ListInvitations(userID string) ([]*entities.Project, error)
ListInvitations(userID string, invitationState entities.Invitation) ([]*entities.Project, error)
}

type repository struct {
Expand Down Expand Up @@ -468,7 +468,7 @@ func (r repository) GetProjectMembers(projectID string, state string) ([]*entiti
return res[0].Members, nil
}

func (r repository) ListInvitations(userID string) ([]*entities.Project, error) {
func (r repository) ListInvitations(userID string, invitationState entities.Invitation) ([]*entities.Project, error) {

var pipeline mongo.Pipeline
filter := bson.D{
Expand All @@ -477,7 +477,7 @@ func (r repository) ListInvitations(userID string) ([]*entities.Project, error)
{"$elemMatch", bson.D{
{"user_id", userID},
{"invitation", bson.D{
{"$eq", entities.PendingInvitation},
{"$eq", invitationState},
}},
}},
}}},
Expand All @@ -495,7 +495,7 @@ func (r repository) ListInvitations(userID string) ([]*entities.Project, error)
{"cond", bson.D{
{"$or", bson.A{
bson.D{{"$and", bson.A{
bson.D{{"$eq", bson.A{"$$member.invitation", entities.PendingInvitation}}},
bson.D{{"$eq", bson.A{"$$member.invitation", invitationState}}},
bson.D{{"$eq", bson.A{"$$member.user_id", userID}}},
}}},
bson.D{{"$eq", bson.A{"$$member.role", entities.RoleOwner}}},
Expand Down
6 changes: 3 additions & 3 deletions chaoscenter/authentication/pkg/services/project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type projectService interface {
GetOwnerProjectIDs(ctx context.Context, userID string) ([]*entities.Project, error)
GetProjectRole(projectID string, userID string) (*entities.MemberRole, error)
GetProjectMembers(projectID string, state string) ([]*entities.Member, error)
ListInvitations(userID string) ([]*entities.Project, error)
ListInvitations(userID string, invitationState entities.Invitation) ([]*entities.Project, error)
}

func (a applicationService) GetProjectByProjectID(projectID string) (*entities.Project, error) {
Expand Down Expand Up @@ -82,6 +82,6 @@ func (a applicationService) GetProjectMembers(projectID string, state string) ([
return a.projectRepository.GetProjectMembers(projectID, state)
}

func (a applicationService) ListInvitations(userID string) ([]*entities.Project, error) {
return a.projectRepository.ListInvitations(userID)
func (a applicationService) ListInvitations(userID string, invitationState entities.Invitation) ([]*entities.Project, error) {
return a.projectRepository.ListInvitations(userID, invitationState)
}
13 changes: 11 additions & 2 deletions mkdocs/docs/auth/v3.0.0/auth-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@
"produces": ["application/json"]
}
},
"/list_invitations": {
"/list_invitations_with_filters/{invitation_state}": {
"get": {
"description": "This API is used to list all the pending invitations of the user\n",
"operationId": "listInvitations",
Expand All @@ -1008,7 +1008,16 @@
}
}
},
"parameters": [],
"parameters": [
{
"name": "invitation_state",
"required": true,
"description": "state of the invitation",
"in": "path",
"type": "string",
"enum": ["Accepted", "Pending", "Declined", "Exited"]
}
],
"produces": ["application/json"]
}
},
Expand Down

0 comments on commit f123d67

Please sign in to comment.