-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from ctreminiom/feature/confluence-v2-endpoints
✨ Mapped more Confluence V2 endpoints
- Loading branch information
Showing
16 changed files
with
1,699 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
model "github.com/ctreminiom/go-atlassian/pkg/infra/models" | ||
"github.com/ctreminiom/go-atlassian/service" | ||
"github.com/ctreminiom/go-atlassian/service/confluence" | ||
"net/http" | ||
"net/url" | ||
"strconv" | ||
) | ||
|
||
// NewAttachmentVersionService returns a new Confluence V2 Attachment Version service | ||
func NewAttachmentVersionService(client service.Connector) *AttachmentVersionService { | ||
return &AttachmentVersionService{ | ||
internalClient: &internalAttachmentVersionImpl{c: client}, | ||
} | ||
} | ||
|
||
type AttachmentVersionService struct { | ||
internalClient confluence.AttachmentVersionConnector | ||
} | ||
|
||
// Gets returns the versions of specific attachment. | ||
// | ||
// GET /wiki/api/v2/attachments/{id}/versions | ||
// | ||
// https://docs.go-atlassian.io/confluence-cloud/v2/attachments/versions#get-attachment-versions | ||
func (a *AttachmentVersionService) Gets(ctx context.Context, attachmentID, cursor, sort string, limit int) (*model.AttachmentVersionPageScheme, *model.ResponseScheme, error) { | ||
return a.internalClient.Gets(ctx, attachmentID, cursor, sort, limit) | ||
} | ||
|
||
// Get retrieves version details for the specified attachment and version number. | ||
// | ||
// GET /wiki/api/v2/attachments/{attachment-id}/versions/{version-number} | ||
// | ||
// https://docs.go-atlassian.io/confluence-cloud/v2/attachments/versions#get-attachment-version | ||
func (a *AttachmentVersionService) Get(ctx context.Context, attachmentID string, versionID int) (*model.DetailedVersionScheme, *model.ResponseScheme, error) { | ||
return a.internalClient.Get(ctx, attachmentID, versionID) | ||
} | ||
|
||
type internalAttachmentVersionImpl struct { | ||
c service.Connector | ||
} | ||
|
||
func (i *internalAttachmentVersionImpl) Gets(ctx context.Context, attachmentID, cursor, sort string, limit int) (*model.AttachmentVersionPageScheme, *model.ResponseScheme, error) { | ||
|
||
if attachmentID == "" { | ||
return nil, nil, model.ErrNoContentAttachmentIDError | ||
} | ||
|
||
query := url.Values{} | ||
query.Add("limit", strconv.Itoa(limit)) | ||
|
||
if cursor != "" { | ||
query.Add("cursor", cursor) | ||
} | ||
|
||
if sort != "" { | ||
query.Add("sort", sort) | ||
} | ||
|
||
endpoint := fmt.Sprintf("wiki/api/v2/attachments/%v/versions?%v", attachmentID, query.Encode()) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
page := new(model.AttachmentVersionPageScheme) | ||
response, err := i.c.Call(request, page) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return page, response, nil | ||
} | ||
|
||
func (i *internalAttachmentVersionImpl) Get(ctx context.Context, attachmentID string, versionID int) (*model.DetailedVersionScheme, *model.ResponseScheme, error) { | ||
|
||
if attachmentID == "" { | ||
return nil, nil, model.ErrNoContentAttachmentIDError | ||
} | ||
|
||
endpoint := fmt.Sprintf("wiki/api/v2/attachments/%v/versions/%v", attachmentID, versionID) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
version := new(model.DetailedVersionScheme) | ||
response, err := i.c.Call(request, version) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return version, response, nil | ||
} |
Oops, something went wrong.