Skip to content

Commit

Permalink
chore: rename endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Feb 28, 2024
1 parent 20b2d80 commit 159621b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Notifies about new events matching the filter provided via webhooks.
<details>
<summary>
<code>POST</code> <code><b>/subscribe</b></code>
<code>POST</code> <code><b>/subscriptions</b></code>
</summary>
#### Request Body
Expand Down Expand Up @@ -130,7 +130,7 @@ Delete previously requested subscriptions.
<details>
<summary>
<code>DELETE</code> <code><b>/subscribe/:id</b></code>
<code>DELETE</code> <code><b>/subscriptions/:id</b></code>
</summary>
#### Parameter
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func main() {

e.POST("/nip47/info", svc.InfoHandler)
e.POST("/nip47", svc.NIP47Handler)
e.POST("/subscribe", svc.SubscriptionHandler)
e.DELETE("/subscribe/:id", svc.StopSubscriptionHandler)
e.POST("/subscriptions", svc.SubscriptionHandler)
e.DELETE("/subscriptions/:id", svc.StopSubscriptionHandler)
e.Use(echologrus.Middleware())

//start Echo server
Expand Down
10 changes: 5 additions & 5 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error {
subscription := Subscription{}
if err := svc.db.First(&subscription, subId).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return c.JSON(http.StatusBadRequest, ErrorResponse{
return c.JSON(http.StatusNotFound, ErrorResponse{
Message: "subscription does not exist",
})
} else {
Expand All @@ -422,12 +422,12 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error {

err := svc.stopSubscription(&subscription)
if err != nil {
return c.JSON(http.StatusNotFound, ErrorResponse{
Message: err.Error(),
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Message: fmt.Sprintf("subscription does not exist: %s", err.Error()),
})
}

return c.JSON(http.StatusOK, fmt.Sprintf("subscription %d stopped", subId))
return c.NoContent(http.StatusNoContent)
}

func (svc *Service) stopSubscription(sub *Subscription) error {
Expand All @@ -441,7 +441,7 @@ func (svc *Service) stopSubscription(sub *Subscription) error {
}
svc.mu.Unlock()
if (!exists) {
return fmt.Errorf("cancel function of subscription doesn't exist")
return fmt.Errorf("cancel function doesn't exist")
}
return nil
}
Expand Down

0 comments on commit 159621b

Please sign in to comment.