generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat-576-request-metrics
- Loading branch information
Showing
28 changed files
with
435 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
package contacts | ||
|
||
import "github.com/bitcoin-sv/spv-wallet/engine" | ||
import ( | ||
"github.com/bitcoin-sv/spv-wallet/engine" | ||
"github.com/bitcoin-sv/spv-wallet/models" | ||
) | ||
|
||
// CreateContact is the model for creating a contact | ||
type CreateContact struct { | ||
Metadata engine.Metadata `json:"metadata"` | ||
} | ||
|
||
// UpdateContact is the model for updating a contact | ||
type UpdateContact struct { | ||
XPubID string `json:"xpub_id"` | ||
FullName string `json:"full_name"` | ||
Paymail string `json:"paymail"` | ||
PubKey string `json:"pubKey"` | ||
Status models.ContactStatus `json:"status"` | ||
Metadata engine.Metadata `json:"metadata"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package contacts | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/actions" | ||
"github.com/bitcoin-sv/spv-wallet/engine" | ||
"github.com/bitcoin-sv/spv-wallet/mappings" | ||
"github.com/bitcoin-sv/spv-wallet/models" | ||
"github.com/bitcoin-sv/spv-wallet/server/auth" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Search will fetch a list of contacts | ||
// Get contacts godoc | ||
// @Summary Search contacts | ||
// @Description Search contacts | ||
// @Tags Contact | ||
// @Produce json | ||
// @Param page query int false "page" | ||
// @Param page_size query int false "page_size" | ||
// @Param order_by_field query string false "order_by_field" | ||
// @Param sort_direction query string false "sort_direction" | ||
// @Param conditions query string false "conditions" | ||
// @Success 200 | ||
// @Router /v1/contacts [get] | ||
// @Security x-auth-xpub | ||
func (a *Action) search(c *gin.Context) { | ||
reqXPubID := c.GetString(auth.ParamXPubHashKey) | ||
|
||
params := c.Request.URL.Query() | ||
|
||
queryParams, metadata, _, err := actions.GetQueryParameters(c) | ||
if err != nil { | ||
c.JSON(http.StatusExpectationFailed, err.Error()) | ||
return | ||
} | ||
|
||
dbConditions := make(map[string]interface{}) | ||
|
||
for key, value := range params { | ||
dbConditions[key] = value | ||
} | ||
|
||
dbConditions["xpub_id"] = reqXPubID | ||
|
||
var contacts []*engine.Contact | ||
if contacts, err = a.Services.SpvWalletEngine.GetContacts( | ||
c.Request.Context(), | ||
metadata, | ||
&dbConditions, | ||
queryParams, | ||
); err != nil { | ||
c.JSON(http.StatusExpectationFailed, err.Error()) | ||
return | ||
} | ||
|
||
contactContracts := make([]*models.Contact, 0) | ||
for _, contact := range contacts { | ||
contactContracts = append(contactContracts, mappings.MapToContactContract(contact)) | ||
} | ||
|
||
c.JSON(http.StatusOK, contactContracts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package contacts | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/engine" | ||
"github.com/bitcoin-sv/spv-wallet/mappings" | ||
"github.com/bitcoin-sv/spv-wallet/server/auth" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// update will update an existing model | ||
// Update Contact godoc | ||
// @Summary Update contact | ||
// @Description Update contact | ||
// @Tags Contacts | ||
// @Produce json | ||
// @Param metadata body string true "Contacts Metadata" | ||
// @Success 200 | ||
// @Router /v1/contact [patch] | ||
// @Security x-auth-xpub | ||
func (a *Action) update(c *gin.Context) { | ||
reqXPubID := c.GetString(auth.ParamXPubHashKey) | ||
|
||
var requestBody UpdateContact | ||
|
||
if err := c.ShouldBindJSON(&requestBody); err != nil { | ||
c.JSON(http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
if requestBody.XPubID == "" { | ||
c.JSON(http.StatusBadRequest, "Id is missing") | ||
} | ||
|
||
contact, err := a.Services.SpvWalletEngine.UpdateContact(c.Request.Context(), requestBody.FullName, requestBody.PubKey, reqXPubID, requestBody.Paymail, engine.ContactStatus(requestBody.Status), engine.WithMetadatas(requestBody.Metadata)) | ||
|
||
if err != nil { | ||
c.JSON(http.StatusExpectationFailed, err.Error()) | ||
return | ||
} | ||
|
||
contract := mappings.MapToContactContract(contact) | ||
|
||
c.JSON(http.StatusOK, contract) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.