Skip to content

Commit

Permalink
Add #192 Align APIs to GovStack: Change URL paths for audit endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa committed Oct 4, 2023
1 parent 50f5b0f commit 3b474a9
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/config
14 changes: 14 additions & 0 deletions src/handlerv2/auditagreementlist_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package handlerv2

import (
"net/http"

"github.com/bb-consent/api/src/config"
)

func AuditAgreementList(w http.ResponseWriter, r *http.Request) {

w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
w.WriteHeader(http.StatusOK)

}
14 changes: 14 additions & 0 deletions src/handlerv2/auditconsentrecordlist_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package handlerv2

import (
"net/http"

"github.com/bb-consent/api/src/config"
)

func AuditConsentRecordList(w http.ResponseWriter, r *http.Request) {

w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
w.WriteHeader(http.StatusOK)

}
14 changes: 14 additions & 0 deletions src/handlerv2/auditconsentrecordread_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package handlerv2

import (
"net/http"

"github.com/bb-consent/api/src/config"
)

func AuditConsentRecordRead(w http.ResponseWriter, r *http.Request) {

w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
w.WriteHeader(http.StatusOK)

}
14 changes: 14 additions & 0 deletions src/handlerv2/auditreadrecord_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package handlerv2

import (
"net/http"

"github.com/bb-consent/api/src/config"
)

func AuditReadRecord(w http.ResponseWriter, r *http.Request) {

w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
w.WriteHeader(http.StatusOK)

}
56 changes: 56 additions & 0 deletions src/handlerv2/getorglogs_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package handlerv2

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

"github.com/bb-consent/api/src/actionlog"
"github.com/bb-consent/api/src/common"
"github.com/bb-consent/api/src/config"
"github.com/gorilla/mux"
)

type orgLog struct {
ID string
Type int
TypeStr string
UserID string
UserName string
TimeStamp string
Log string
}
type orgLogsResp struct {
Logs []orgLog
Links common.PaginationLinks
}

// GetOrgLogs Get action logs for the organization
func GetOrgLogs(w http.ResponseWriter, r *http.Request) {
orgID := mux.Vars(r)["orgID"]

startID, limit := common.ParsePaginationQueryParameters(r)
if limit == 0 {
limit = 50
}

sanitizedOrgId := common.Sanitize(orgID)

logs, lastID, err := actionlog.GetAccessLogByOrgID(sanitizedOrgId, startID, limit)
if err != nil {
m := fmt.Sprintf("Failed to get logs for organization: %v", orgID)
common.HandleError(w, http.StatusInternalServerError, m, err)
return
}

var ls orgLogsResp
for _, l := range logs {
ls.Logs = append(ls.Logs, orgLog{ID: l.ID.Hex(), Type: l.Type, TypeStr: l.TypeStr,
UserID: l.UserID, UserName: l.UserName, TimeStamp: l.ID.Timestamp().String(), Log: l.Action})
}

ls.Links = common.CreatePaginationLinks(r, startID, lastID, limit)
response, _ := json.Marshal(ls)
w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
w.Write(response)
}
8 changes: 8 additions & 0 deletions src/httppathsv2/audit_paths.go
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package httppathsv2

const AuditConsentRecordList = "/v2/audit/consentrecords/"
const AuditConsentRecordRead = "/v2/audit/consentrecord/{consentRecordId}/"
const AuditAgreementList = "/v2/audit/agreements/"
const AuditReadRecord = "/v2/audit/agreement/{agreementId}/"

// organization action logs
const GetOrgLogs = "/v2/audit/admin/logs"
10 changes: 10 additions & 0 deletions src/httppathsv2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ func SetRoutes(r *mux.Router, e *casbin.Enforcer) {
r.Handle(ServiceUpdateIndividualConsentRecord, m.Chain(handler.ServiceCreateIndividualConsentRecord, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("PUT")
r.Handle(ServiceListIndividualRecordList, m.Chain(handler.ServiceListIndividualRecordList, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")
r.Handle(ServiceReadIndividualRecordRead, m.Chain(handler.ServiceReadIndividualRecordRead, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")

// Audit api(s)

r.Handle(AuditConsentRecordList, m.Chain(handler.AuditConsentRecordList, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")
r.Handle(AuditConsentRecordRead, m.Chain(handler.AuditConsentRecordRead, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")
r.Handle(AuditAgreementList, m.Chain(handler.AuditAgreementList, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")
r.Handle(AuditReadRecord, m.Chain(handler.AuditReadRecord, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")

// organization action logs
r.Handle(GetOrgLogs, m.Chain(handler.GetOrgLogs, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate())).Methods("GET")
}

0 comments on commit 3b474a9

Please sign in to comment.