Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Modify API structur also
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Oct 11, 2023
1 parent 6f534f6 commit 52e9e23
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
14 changes: 9 additions & 5 deletions api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ type (
Error string `json:"error"`
}
GetStatusResponse struct {
ID string `json:"id"`
Replicas []Replica `json:"Replicas,omitempty"`
ID string `json:"id"`
Replica *Replica `json:"Replicas,omitempty"`
}
Replica struct {
Provider string `json:"provider"`
Status string `json:"status"`
LastVerified time.Time `json:"lastVerified"`
Provider string `json:"provider"`
Pieces []Piece `json:"pieces"`
}
Piece struct {
Expiration time.Time `json:"expiration"`
LastVerified time.Time `json:"lastVerified"`
PieceCID string `json:"pieceCid"`
Status string `json:"status"`
}
)
15 changes: 9 additions & 6 deletions api/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,19 @@ func (m *HttpServer) handleBlobGetStatusByID(w http.ResponseWriter, r *http.Requ
}

if blobDesc.Replica != nil && len(blobDesc.Replica.Pieces) != 0 {
response.Replicas = make([]api.Replica, 0, len(blobDesc.Replica.Pieces))
provider := blobDesc.Replica.Provider
apiPieces := make([]api.Piece, 0, len(blobDesc.Replica.Pieces))
for _, piece := range blobDesc.Replica.Pieces {
response.Replicas = append(response.Replicas, api.Replica{
Provider: provider,
Status: piece.Status,
LastVerified: piece.LastUpdated,
apiPieces = append(apiPieces, api.Piece{
Expiration: piece.Expiration,
LastVerified: piece.LastUpdated,
PieceCID: piece.PieceCID,
Status: piece.Status,
})
}
response.Replica = &api.Replica{
Provider: blobDesc.Replica.Provider,
Pieces: apiPieces,
}
}
respondWithJson(w, response, http.StatusOK)
}
Expand Down
11 changes: 4 additions & 7 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,16 @@ type (
ModificationTime time.Time
Replica *Replica
}

Replica struct {
Provider string
Pieces []Piece
}
Piece struct {
Expiration time.Time
LastUpdated time.Time
PieceCID string
Status string
}

Replica struct {
Provider string
Pieces []Piece
}

Store interface {
Put(context.Context, io.ReadCloser) (*Descriptor, error)
Describe(context.Context, ID) (*Descriptor, error)
Expand Down
10 changes: 6 additions & 4 deletions integration/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func TestRoundTripPutStatusAndFullStorage(t *testing.T) {
var decoded api.GetStatusResponse
err = jsonResp.Decode(&decoded)
assert.NoError(c, err)
assert.Equal(c, len(decoded.Replicas), 2)
assert.NotNil(c, decoded.Replica)
assert.Equal(c, len(decoded.Replica.Pieces), 2)
}, 2*time.Minute, 5*time.Second, "never initiated deal making")
}

Expand Down Expand Up @@ -142,9 +143,10 @@ func TestRoundTripPutStatusAndFullStorage(t *testing.T) {
var decoded api.GetStatusResponse
err = jsonResp.Decode(&decoded)
assert.NoError(c, err)
assert.Equal(c, len(decoded.Replicas), 2)
for _, replica := range decoded.Replicas {
assert.Contains(c, []string{"published", "active"}, replica.Status)
assert.NotNil(c, decoded.Replica)
assert.Equal(c, len(decoded.Replica.Pieces), 2)
for _, piece := range decoded.Replica.Pieces {
assert.Contains(c, []string{"published", "active"}, piece.Status)
}
}, 2*time.Minute, 5*time.Second, "published deals")
}
Expand Down

0 comments on commit 52e9e23

Please sign in to comment.