added search endpoint

* check whether one or more phone numbers are registered with
  the signal service.

see #50
This commit is contained in:
Bernhard B
2022-01-02 14:52:45 +01:00
parent 18dcc49ff4
commit 43747af9d4
6 changed files with 270 additions and 0 deletions

View File

@@ -110,6 +110,11 @@ var connectionUpgrader = websocket.Upgrader{
},
}
type SearchResponse struct {
Number string `json:"number"`
Registered bool `json:"registered"`
}
type Api struct {
signalClient *client.SignalClient
}
@@ -1050,3 +1055,34 @@ func (a *Api) SendStopTyping(c *gin.Context) {
}
c.Status(http.StatusNoContent)
}
// @Summary Check if one or more phone numbers are registered with the Signal Service.
// @Tags Search
// @Description Check if one or more phone numbers are registered with the Signal Service.
// @Accept json
// @Produce json
// @Param numbers query []string true "Numbers to check" collectionFormat(multi)
// @Success 204 {object} SearchResponse
// @Failure 400 {object} Error
// @Router /v1/search [get]
func (a *Api) SearchForNumbers(c *gin.Context) {
query := c.Request.URL.Query()
if _, ok := query["numbers"]; !ok {
c.JSON(400, Error{Msg: "Please provide numbers to query for"})
return
}
searchResults, err := a.signalClient.SearchForNumbers(query["numbers"])
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
searchResponse := []SearchResponse{}
for _, val := range searchResults {
entry := SearchResponse{Number: val.Number, Registered: val.Registered}
searchResponse = append(searchResponse, entry)
}
c.JSON(200, searchResponse)
}