-
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 #201 from ctreminiom/feature/jira-announcement-banner
✨ Added the Jira Announcement Banner Service.
- Loading branch information
Showing
6 changed files
with
460 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
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/jira" | ||
"net/http" | ||
) | ||
|
||
func NewAnnouncementBannerService(client service.Client, version string) *AnnouncementBannerService { | ||
|
||
return &AnnouncementBannerService{ | ||
internalClient: &internalAnnouncementBannerImpl{c: client, version: version}, | ||
} | ||
} | ||
|
||
type AnnouncementBannerService struct { | ||
internalClient jira.AnnouncementBannerConnector | ||
} | ||
|
||
// Get returns the current announcement banner configuration. | ||
// | ||
// GET /rest/api/{2-3}/announcementBanner | ||
// | ||
// https://docs.go-atlassian.io/jira-software-cloud/announcement-banner#get-announcement-banner-configuration | ||
func (a *AnnouncementBannerService) Get(ctx context.Context) (*model.AnnouncementBannerScheme, *model.ResponseScheme, error) { | ||
return a.internalClient.Get(ctx) | ||
} | ||
|
||
// Update updates the announcement banner configuration. | ||
// | ||
// PUT /rest/api/{2-3}/announcementBanner | ||
// | ||
// https://docs.go-atlassian.io/jira-software-cloud/announcement-banner#get-announcement-banner-configuration | ||
func (a *AnnouncementBannerService) Update(ctx context.Context, payload *model.AnnouncementBannerPayloadScheme) (*model.ResponseScheme, error) { | ||
return a.internalClient.Update(ctx, payload) | ||
} | ||
|
||
type internalAnnouncementBannerImpl struct { | ||
c service.Client | ||
version string | ||
} | ||
|
||
func (i *internalAnnouncementBannerImpl) Get(ctx context.Context) (*model.AnnouncementBannerScheme, *model.ResponseScheme, error) { | ||
|
||
endpoint := fmt.Sprintf("rest/api/%v/announcementBanner", i.version) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
banner := new(model.AnnouncementBannerScheme) | ||
response, err := i.c.Call(request, banner) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return banner, response, nil | ||
} | ||
|
||
func (i *internalAnnouncementBannerImpl) Update(ctx context.Context, payload *model.AnnouncementBannerPayloadScheme) (*model.ResponseScheme, error) { | ||
|
||
reader, err := i.c.TransformStructToReader(payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
endpoint := fmt.Sprintf("rest/api/%v/announcementBanner", i.version) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodPut, endpoint, reader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return i.c.Call(request, nil) | ||
} |
Oops, something went wrong.