Skip to content

Commit

Permalink
feat: add final examples after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rek committed Jan 30, 2024
1 parent 2ca3baa commit ddf9db0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
4 changes: 2 additions & 2 deletions 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,7 +209,7 @@ 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 (only available to enterprise teams)
- [x] User Groups
- [x] Get User Group
- [x] Create User Group
- [x] Update User Group
Expand Down
8 changes: 4 additions & 4 deletions clickup/user_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *UserGroupsService) GetUserGroups(ctx context.Context, opts *GetUserGrou
return response.UserGroups, resp, nil
}

func (s *UserGroupsService) CreateUserGroup(ctx context.Context, teamID int, createUserGroupRequest *CreateUserGroupRequest) (*UserGroup, *Response, error) {
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 {
Expand All @@ -101,8 +101,8 @@ func (s *UserGroupsService) CreateUserGroup(ctx context.Context, teamID int, cre
return group, resp, nil
}

func (s *UserGroupsService) UpdateUserGroup(ctx context.Context, teamID int, updateUserGroupRequest *UpdateUserGroupRequest) (*UserGroup, *Response, error) {
u := fmt.Sprintf("group/%v", teamID)
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
Expand All @@ -117,7 +117,7 @@ func (s *UserGroupsService) UpdateUserGroup(ctx context.Context, teamID int, upd
return group, resp, nil
}

func (s *UserGroupsService) DeleteUserGroup(ctx context.Context, groupID int) (*Response, error) {
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 {
Expand Down
34 changes: 17 additions & 17 deletions clickup/user_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestUserGroupsService_GetUserGroups(t *testing.T) {
`{
"groups": [
{
"id": "d899ba3a-1cbf-4188-ae39-11e6acc5f93d",
"id": "a-b-c-d-e",
"team_id": "123",
"userid": 321,
"name": "Test Team",
Expand All @@ -36,7 +36,7 @@ func TestUserGroupsService_GetUserGroups(t *testing.T) {
"email": "testuser@test.com",
"color": "#7b68ee",
"initials": "TU",
"profilePicture": "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg"
"profilePicture": "test.jpg"
}
],
"avatar": {
Expand Down Expand Up @@ -66,10 +66,10 @@ func TestUserGroupsService_GetUserGroups(t *testing.T) {
Email: "testuser@test.com",
Color: "#7b68ee",
Initials: "TU",
ProfilePicture: "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg",
ProfilePicture: "test.jpg",
}
ug := UserGroup{
ID: "d899ba3a-1cbf-4188-ae39-11e6acc5f93d",
ID: "a-b-c-d-e",
TeamID: "123",
UserID: 321,
Name: "Test Team",
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestUserGroupsService_CreateUserGroup(t *testing.T) {
testMethod(t, r, "POST")
fmt.Fprint(w,
`{
"id": "d899ba3a-1cbf-4188-ae39-11e6acc5f93d",
"id": "a-b-c-d-e",
"team_id": "123",
"userid": 321,
"name": "Test Team",
Expand All @@ -112,7 +112,7 @@ func TestUserGroupsService_CreateUserGroup(t *testing.T) {
"email": "testuser@test.com",
"color": "#7b68ee",
"initials": "TU",
"profilePicture": "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg"
"profilePicture": "test.jpg"
}
],
"avatar": {
Expand All @@ -125,7 +125,7 @@ func TestUserGroupsService_CreateUserGroup(t *testing.T) {
)
})
ctx := context.Background()
artifacts, _, err := client.UserGroups.CreateUserGroup(ctx, 123, &CreateUserGroupRequest{
artifacts, _, err := client.UserGroups.CreateUserGroup(ctx, "123", &CreateUserGroupRequest{
Name: "Test Team",
Members: []int{321},
})
Expand All @@ -139,10 +139,10 @@ func TestUserGroupsService_CreateUserGroup(t *testing.T) {
Email: "testuser@test.com",
Color: "#7b68ee",
Initials: "TU",
ProfilePicture: "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg",
ProfilePicture: "test.jpg",
}
want := &UserGroup{
ID: "d899ba3a-1cbf-4188-ae39-11e6acc5f93d",
ID: "a-b-c-d-e",
TeamID: "123",
UserID: 321,
Name: "Test Team",
Expand Down Expand Up @@ -192,13 +192,13 @@ func TestUserGroupsService_UpdateUserGroup(t *testing.T) {
"email": fmt.Sprintf("testuser%d@test.com", id),
"color": "#7b68ee",
"initials": "TU",
"profilePicture": "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg",
"profilePicture": "test.jpg",
}
}

// Generate the response
response := map[string]interface{}{
"id": "d899ba3a-1cbf-4188-ae39-11e6acc5f93d",
"id": "a-b-c-d-e",
"team_id": "123",
"userid": 321,
"name": requestBody.Name,
Expand All @@ -223,7 +223,7 @@ func TestUserGroupsService_UpdateUserGroup(t *testing.T) {
fmt.Fprint(w, string(responseJSON))
})
ctx := context.Background()
artifacts, _, err := client.UserGroups.UpdateUserGroup(ctx, 123, &UpdateUserGroupRequest{
artifacts, _, err := client.UserGroups.UpdateUserGroup(ctx, "123", &UpdateUserGroupRequest{
Name: "Test Team Updated",
Handle: "New Handle",
Members: UpdateUserGroupMember{
Expand All @@ -240,18 +240,18 @@ func TestUserGroupsService_UpdateUserGroup(t *testing.T) {
Email: "testuser1@test.com",
Color: "#7b68ee",
Initials: "TU",
ProfilePicture: "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg",
ProfilePicture: "test.jpg",
}
m2 := GroupMember{
ID: 2,
Username: "Test User 2",
Email: "testuser2@test.com",
Color: "#7b68ee",
Initials: "TU",
ProfilePicture: "https://attachments-public.clickup.com/profilePictures/812_nx1.jpg",
ProfilePicture: "test.jpg",
}
want := &UserGroup{
ID: "d899ba3a-1cbf-4188-ae39-11e6acc5f93d",
ID: "a-b-c-d-e",
TeamID: "123",
UserID: 321,
Name: "Test Team Updated",
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestUserGroupsService_DeleteUserGroup(t *testing.T) {
fmt.Fprint(w, nil)
})
ctx := context.Background()
_, err := client.UserGroups.DeleteUserGroup(ctx, 123)
_, err := client.UserGroups.DeleteUserGroup(ctx, "123")
if err != nil {
t.Errorf("Actions.ListArtifacts returned error: %v", err)
}
Expand All @@ -296,7 +296,7 @@ func TestUserGroupsService_DeleteUserGroupError(t *testing.T) {
fmt.Fprint(w, "Internal server error")
})
ctx := context.Background()
response, err := client.UserGroups.DeleteUserGroup(ctx, 123)
response, err := client.UserGroups.DeleteUserGroup(ctx, "123")

if err == nil {
t.Errorf("Actions.ListArtifacts did not return error: %v", response)
Expand Down
52 changes: 47 additions & 5 deletions example/user-groups/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,66 @@ package main
import (
"context"
"fmt"
"os"

"github.com/raksul/go-clickup/clickup"
)

func fetchUserGroups() ([]clickup.UserGroup, error) {
api_key := os.Getenv("CLICKUP_API_KEY")
api_key := "CLICKUP_API_KEY"
team_id := "TEAM_ID"
client := clickup.NewClient(nil, api_key)

opts := &clickup.GetUserGroupsOptions{
TeamID: "123",
GroupIDs: []string{"321", "456"}, // optional parameter
TeamID: team_id,
GroupIDs: []string{"GROUP_ID"}, // optional parameter
}
groups, _, err := client.UserGroups.GetUserGroups(context.Background(), opts)

return groups, err
}

func createUserGroup() (*clickup.UserGroup, error) {
api_key := "CLICKUP_API_KEY"
team_id := "TEAM_ID"
member_id_to_add := 0
client := clickup.NewClient(nil, api_key)

opts := clickup.CreateUserGroupRequest{
Name: "test",
Members: []int{member_id_to_add}, // optional parameter
}
group, _, err := client.UserGroups.CreateUserGroup(context.Background(), team_id, &opts)

return group, err
}

func updateUserGroup() (*clickup.UserGroup, error) {
api_key := "CLICKUP_API_KEY"
group_id := "GROUP_ID"
client := clickup.NewClient(nil, api_key)

opts := clickup.UpdateUserGroupRequest{
// Name: "new name", // optional parameter
Members: clickup.UpdateUserGroupMember{
Add: []int{0}, // optional parameter
// Remove: []int{0}, // optional parameter
},
}
group, response, err := client.UserGroups.UpdateUserGroup(context.Background(), group_id, &opts)
fmt.Println(response)
return group, err
}

func deleteUserGroup() error {
api_key := "CLICKUP_API_KEY"
group_id := "GROUP_ID"
client := clickup.NewClient(nil, api_key)

_, err := client.UserGroups.DeleteUserGroup(context.Background(), group_id)

return err
}

func main() {
groups, err := fetchUserGroups()

Expand All @@ -33,6 +75,6 @@ func main() {
}

for _, group := range groups {
fmt.Println(group.Name)
fmt.Println(group.Name, group.ID, group.Members)
}
}

0 comments on commit ddf9db0

Please sign in to comment.