Skip to content

Commit

Permalink
Add #336 Add GET /service/organisation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 24, 2023
1 parent 243adb4 commit 9adde8a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/v2/handler/service/service_read_organisation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package service

import (
"encoding/json"
"fmt"
"net/http"

"github.com/bb-consent/api/src/common"
"github.com/bb-consent/api/src/config"
"github.com/bb-consent/api/src/org"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type organizationResp struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Sector string `json:"sector"`
Location string `json:"location"`
PolicyURL string `json:"policyUrl"`
CoverImageID string `json:"coverImageId"`
CoverImageURL string `json:"coverImageUrl"`
LogoImageID string `json:"logoImageId"`
LogoImageURL string `json:"logoImageUrl"`
}

type getOrgResp struct {
Organization organizationResp `json:"organisation"`
}

// ServiceReadOrganisation
func ServiceReadOrganisation(w http.ResponseWriter, r *http.Request) {
organizationID := r.Header.Get(config.OrganizationId)
o, err := org.Get(organizationID)
if err != nil {
m := fmt.Sprintf("Failed to get organization by ID :%v", organizationID)
common.HandleErrorV2(w, http.StatusNotFound, m, err)
return
}

oResp := organizationResp{
ID: o.ID,
Name: o.Name,
Description: o.Description,
Sector: o.Type.Type,
Location: o.Location,
PolicyURL: o.PolicyURL,
CoverImageID: o.CoverImageID,
CoverImageURL: o.CoverImageURL,
LogoImageID: o.LogoImageID,
LogoImageURL: o.LogoImageURL,
}

w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
response, _ := json.Marshal(getOrgResp{oResp})
w.Write(response)
}
2 changes: 2 additions & 0 deletions src/v2/http_path/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func SetRoutes(r *mux.Router, e *casbin.Enforcer) {

r.Handle(ServiceFetchRecordsHistory, m.Chain(serviceHandler.ServiceFetchRecordsHistory, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("GET")

r.Handle(ServiceReadOrganisation, m.Chain(serviceHandler.ServiceReadOrganisation, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("GET")

// Audit api(s)

r.Handle(AuditListDataAgreementRecords, m.Chain(auditHandler.AuditListDataAgreementRecords, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("GET")
Expand Down
2 changes: 2 additions & 0 deletions src/v2/http_path/service_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ const ServiceFetchRecordsHistory = "/v2/service/individual/record/data-agreement

// Idp
const ServiceReadIdp = "/v2/service/idp/open-id/{idpId}"

const ServiceReadOrganisation = "/v2/service/organisation"

0 comments on commit 9adde8a

Please sign in to comment.