Skip to content

Commit

Permalink
docs: add user group docs to main readme
Browse files Browse the repository at this point in the history
feat: add crud for user groups

feat: add test for update

test: add delete error tests

feat: add final examples after testing
  • Loading branch information
rek committed Feb 3, 2024
1 parent a255630 commit f883c30
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 23 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Contribution, in any kind of way, is highly welcome! It doesn't matter if you ar
- Sharing the love of go-clickup and help people to get use to it
- Writing test code

If you are new to pull requests, checkout Collaborating on projects using issues and pull requests / Creating a pull request.
If you are new to pull requests, checkout [Collaborating on projects using issues and pull requests / Creating a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests).

## Progress
- [x] Rate Limit
Expand Down Expand Up @@ -209,6 +209,11 @@ If you are new to pull requests, checkout Collaborating on projects using issues
- [ ] Edit User On Workspace
- [ ] Remove User From Workspace
- [ ] Get User
- [x] User Groups
- [x] Get User Group
- [x] Create User Group
- [x] Update User Group
- [x] Delete User Group
- [x] Views
- [x] Create Team View
- [x] Create Space View
Expand Down
100 changes: 88 additions & 12 deletions clickup/user_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clickup

import (
"context"
"fmt"
)

type UserGroupsService service
Expand All @@ -11,15 +12,22 @@ type GetUserGroupsResponse struct {
}

type UserGroup struct {
ID string `json:"id"`
TeamID string `json:"team_id"`
UserID int `json:"userid"`
Name string `json:"name"`
Handle string `json:"handle"`
DateCreated string `json:"date_created"`
Initials string `json:"initials"`
Members []GroupMember `json:"members"`
Avatar interface{} `json:"avatar"`
ID string `json:"id"`
TeamID string `json:"team_id"`
UserID int `json:"userid"`
Name string `json:"name"`
Handle string `json:"handle"`
DateCreated string `json:"date_created"`
Initials string `json:"initials"`
Members []GroupMember `json:"members"`
Avatar UserGroupAvatar `json:"avatar"`
}

type UserGroupAvatar struct {
AttachmentId *string `json:"attachment_id"`
Color *string `json:"color"`
Source *string `json:"source"`
Icon *string `json:"icon"`
}

type GroupMember struct {
Expand All @@ -31,11 +39,32 @@ type GroupMember struct {
ProfilePicture string `json:"profilePicture"`
}

type UserGroupRequest struct {
Name string `json:"name"`
Members []int `json:"members"`
}

type GetUserGroupsOptions struct {
TeamID string `url:"team_id,omitempty"`
GroupIDs []string `url:"group_ids,omitempty"`
}

type UpdateUserGroupMember struct {
Add []int `json:"add"`
Remove []int `json:"rem"`
}

type UpdateUserGroupRequest struct {
Name string `json:"name"`
Handle string `json:"handle"`
Members UpdateUserGroupMember `json:"members"`
}

type CreateUserGroupRequest struct {
Name string `json:"name"`
Members []int `json:"add"`
}

func (s *UserGroupsService) GetUserGroups(ctx context.Context, opts *GetUserGroupsOptions) ([]UserGroup, *Response, error) {
u, err := addOptions("group", opts)
if err != nil {
Expand All @@ -47,11 +76,58 @@ func (s *UserGroupsService) GetUserGroups(ctx context.Context, opts *GetUserGrou
return nil, nil, err
}

gugr := new(GetUserGroupsResponse)
resp, err := s.client.Do(ctx, req, gugr)
response := new(GetUserGroupsResponse)
resp, err := s.client.Do(ctx, req, response)
if err != nil {
return nil, resp, err
}

return response.UserGroups, resp, nil
}

func (s *UserGroupsService) CreateUserGroup(ctx context.Context, teamID string, createUserGroupRequest *CreateUserGroupRequest) (*UserGroup, *Response, error) {
u := fmt.Sprintf("team/%v/group", teamID)
req, err := s.client.NewRequest("POST", u, createUserGroupRequest)
if err != nil {
return nil, nil, err
}

group := new(UserGroup)
resp, err := s.client.Do(ctx, req, group)
if err != nil {
return nil, resp, err
}

return gugr.UserGroups, resp, nil
return group, resp, nil
}

func (s *UserGroupsService) UpdateUserGroup(ctx context.Context, groupID string, updateUserGroupRequest *UpdateUserGroupRequest) (*UserGroup, *Response, error) {
u := fmt.Sprintf("group/%v", groupID)
req, err := s.client.NewRequest("PUT", u, updateUserGroupRequest)
if err != nil {
return nil, nil, err
}

group := new(UserGroup)
resp, err := s.client.Do(ctx, req, group)
if err != nil {
return nil, resp, err
}

return group, resp, nil
}

func (s *UserGroupsService) DeleteUserGroup(ctx context.Context, groupID string) (*Response, error) {
u := fmt.Sprintf("group/%v", groupID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}

resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}

return resp, nil
}
Loading

0 comments on commit f883c30

Please sign in to comment.