Skip to content

Commit

Permalink
indexer: rename index endpoint
Browse files Browse the repository at this point in the history
This makes the naming more consistent and adds the "Location" header to
the "201 Created" response.
  • Loading branch information
hdonnay committed Mar 5, 2020
1 parent 4c6a49b commit 10d2f54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions indexer/httptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"path"
"sort"
"strings"

Expand All @@ -15,7 +16,7 @@ import (
var _ http.Handler = (*HTTP)(nil)

const (
IndexAPIPath = "/api/v1/index"
IndexAPIPath = "/api/v1/index_report"
IndexReportAPIPath = "/api/v1/index_report/"
StateAPIPath = "/api/v1/state"
)
Expand All @@ -36,6 +37,7 @@ func NewHTTPTransport(service Service) (*HTTP, error) {
}

func (h *HTTP) IndexReportHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if r.Method != http.MethodGet {
resp := &je.Response{
Code: "method-not-allowed",
Expand Down Expand Up @@ -64,7 +66,7 @@ func (h *HTTP) IndexReportHandler(w http.ResponseWriter, r *http.Request) {
return
}

report, ok, err := h.serv.IndexReport(context.Background(), manifest)
report, ok, err := h.serv.IndexReport(ctx, manifest)
if !ok {
resp := &je.Response{
Code: "not-found",
Expand Down Expand Up @@ -114,8 +116,11 @@ func (h *HTTP) IndexHandler(w http.ResponseWriter, r *http.Request) {
return
}

// ToDo: manifest structure validation
report, err := h.serv.Index(context.Background(), &m)
// TODO Validate manifest structure.

// TODO Do we need some sort of background context embedded in the HTTP
// struct?
report, err := h.serv.Index(context.TODO(), &m)
if err != nil {
resp := &je.Response{
Code: "index-error",
Expand All @@ -126,6 +131,7 @@ func (h *HTTP) IndexHandler(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(http.StatusCreated)
w.Header().Set("location", path.Join(IndexReportAPIPath, m.Hash.String()))
err = json.NewEncoder(w).Encode(report)
if err != nil {
resp := &je.Response{
Expand Down
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ info:
url: "http://www.apache.org/licenses/"

paths:
/index:
/index_report:
post:
tags:
- Indexer
Expand Down

0 comments on commit 10d2f54

Please sign in to comment.