Skip to content

Commit

Permalink
Merge pull request #201 from ctreminiom/feature/jira-announcement-banner
Browse files Browse the repository at this point in the history
✨ Added the Jira Announcement Banner Service.
  • Loading branch information
ctreminiom authored May 20, 2023
2 parents 326c39d + da95de3 commit 47d190e
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 0 deletions.
79 changes: 79 additions & 0 deletions jira/internal/announcement_banner_impl.go
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)
}
Loading

0 comments on commit 47d190e

Please sign in to comment.