Skip to content

Commit

Permalink
feat: json response for self-service api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Cihelka committed Apr 6, 2023
1 parent e4e4b3a commit 0669637
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/replications.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func handlePostReplications(c echo.Context, dldm *core.DeltaDM) error {
}

dealsToMake = append(dealsToMake, core.Deal{
Cid: c.PayloadCID,
PayloadCID: c.PayloadCID,
Wallet: core.Wallet{
Addr: wallet.Addr,
},
Expand Down
12 changes: 8 additions & 4 deletions api/selfservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (

const PROVIDER = "PROVIDER"

type SelfServiceResponse struct {
Cid string `json:"cid"`
}

func ConfigureSelfServiceRouter(e *echo.Group, dldm *core.DeltaDM) {
selfService := e.Group("/self-service")

Expand Down Expand Up @@ -122,7 +126,7 @@ func handleSelfServiceByCid(c echo.Context, dldm *core.DeltaDM) error {
}

dealsToMake = append(dealsToMake, core.Deal{
Cid: cnt.PayloadCID,
PayloadCID: cnt.PayloadCID,
Wallet: core.Wallet{
Addr: wallet.Addr,
},
Expand All @@ -144,7 +148,7 @@ func handleSelfServiceByCid(c echo.Context, dldm *core.DeltaDM) error {
return fmt.Errorf("unable to make deal for this CID: %s", err)
}

return c.JSON(200, fmt.Sprintf("successfully made deal with %s", p.ActorID))
return c.JSON(200, SelfServiceResponse{Cid: cnt.CommP})
}

func handleSelfServiceByDataset(c echo.Context, dldm *core.DeltaDM) error {
Expand Down Expand Up @@ -204,7 +208,7 @@ func handleSelfServiceByDataset(c echo.Context, dldm *core.DeltaDM) error {
var dealsToMake []core.Deal

dealsToMake = append(dealsToMake, core.Deal{
Cid: deal.PayloadCID,
PayloadCID: deal.PayloadCID,
Wallet: core.Wallet{
Addr: wallet.Addr,
},
Expand All @@ -226,5 +230,5 @@ func handleSelfServiceByDataset(c echo.Context, dldm *core.DeltaDM) error {
return fmt.Errorf("unable to make deal for this CID: %s", err)
}

return c.JSON(200, fmt.Sprintf("successfully made deal with %s", p.ActorID))
return c.JSON(200, SelfServiceResponse{Cid: deal.CommP})
}
2 changes: 1 addition & 1 deletion core/delta-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ type OfflineDealResponseElement struct {
}

type Deal struct { // AKA meta
Cid string `json:"cid"`
PayloadCID string `json:"cid"` // Payload CID
Wallet Wallet `json:"wallet"`
Miner string `json:"miner"` //TODO: rename to provider
PieceCommitment PieceCommitment `json:"piece_commitment"`
Expand Down

0 comments on commit 0669637

Please sign in to comment.