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

feat: add create user group #52

Merged
merged 1 commit into from
Feb 5, 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
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).
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


## 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
Loading