Skip to content

Commit 67e5d13

Browse files
committed
[api] add device self-info endpoint
1 parent 7dd333e commit 67e5d13

File tree

18 files changed

+301
-62
lines changed

18 files changed

+301
-62
lines changed

.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ deployments/
5151
build/
5252

5353
# Example requests files
54-
*.http
54+
*.http
55+
56+
# Ignore Go workspace
57+
*.work

.gitignore

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
2-
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,go,terraform
3-
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,macos,linux,go,terraform
2+
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,terraform,macos,linux,go,dotenv
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,terraform,macos,linux,go,dotenv
4+
5+
### dotenv ###
6+
.env
47

58
### Go ###
69
# If you prefer the allow list template instead of the deny list, see community template:
@@ -47,7 +50,8 @@ go.work
4750
.LSOverride
4851

4952
# Icon must end with two \r
50-
Icon
53+
Icon
54+
5155

5256
# Thumbnails
5357
._*
@@ -153,7 +157,7 @@ $RECYCLE.BIN/
153157
# Windows shortcuts
154158
*.lnk
155159

156-
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,go,terraform
160+
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,terraform,macos,linux,go,dotenv
157161

158162
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
159163

@@ -166,4 +170,4 @@ $RECYCLE.BIN/
166170

167171
/api/docs.go
168172

169-
.env
173+
go.work*

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ init:
1212
go mod download
1313

1414
init-dev: init
15-
go install github.com/cosmtrek/air@latest \
15+
go install github.com/air-verse/air@latest \
1616
&& go install github.com/swaggo/swag/cmd/swag@latest \
1717
&& go install github.com/pressly/goose/v3/cmd/goose@latest
1818

api/mobile.http

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
@mobileToken={{$dotenv MOBILE__TOKEN}}
33
@phone={{$dotenv PHONE}}
44

5+
###
6+
GET {{baseUrl}}/device HTTP/1.1
7+
Authorization: Bearer {{mobileToken}}1
8+
59
###
610
POST {{baseUrl}}/device HTTP/1.1
711
Authorization: Bearer 123456789

api/swagger.json

+51-6
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,30 @@
423423
}
424424
},
425425
"/mobile/v1/device": {
426+
"get": {
427+
"description": "Returns device information",
428+
"produces": [
429+
"application/json"
430+
],
431+
"tags": [
432+
"Device"
433+
],
434+
"summary": "Get device information",
435+
"responses": {
436+
"200": {
437+
"description": "Device information",
438+
"schema": {
439+
"$ref": "#/definitions/smsgateway.MobileDeviceResponse"
440+
}
441+
},
442+
"500": {
443+
"description": "Internal server error",
444+
"schema": {
445+
"$ref": "#/definitions/smsgateway.ErrorResponse"
446+
}
447+
}
448+
}
449+
},
426450
"post": {
427451
"description": "Registers new device and returns credentials",
428452
"consumes": [
@@ -925,7 +949,7 @@
925949
]
926950
},
927951
"simNumber": {
928-
"description": "SIM card number (1-3)",
952+
"description": "SIM card number (1-3), if not set - default SIM will be used",
929953
"type": "integer",
930954
"maximum": 3,
931955
"example": 1
@@ -997,6 +1021,23 @@
9971021
}
9981022
}
9991023
},
1024+
"smsgateway.MobileDeviceResponse": {
1025+
"type": "object",
1026+
"properties": {
1027+
"device": {
1028+
"description": "Device information, empty if device is not registered on the server",
1029+
"allOf": [
1030+
{
1031+
"$ref": "#/definitions/smsgateway.Device"
1032+
}
1033+
]
1034+
},
1035+
"externalIp": {
1036+
"description": "External IP",
1037+
"type": "string"
1038+
}
1039+
}
1040+
},
10001041
"smsgateway.MobileRegisterRequest": {
10011042
"type": "object",
10021043
"properties": {
@@ -1165,7 +1206,7 @@
11651206
"description": "The type of event the webhook is triggered for.",
11661207
"allOf": [
11671208
{
1168-
"$ref": "#/definitions/webhooks.EventType"
1209+
"$ref": "#/definitions/smsgateway.WebhookEvent"
11691210
}
11701211
],
11711212
"example": "sms:received"
@@ -1183,17 +1224,21 @@
11831224
}
11841225
}
11851226
},
1186-
"webhooks.EventType": {
1227+
"smsgateway.WebhookEvent": {
11871228
"type": "string",
11881229
"enum": [
11891230
"sms:received",
11901231
"sms:sent",
1232+
"sms:delivered",
1233+
"sms:failed",
11911234
"system:ping"
11921235
],
11931236
"x-enum-varnames": [
1194-
"EventTypeSmsReceived",
1195-
"EventTypeSmsSent",
1196-
"EventTypeSystemPing"
1237+
"WebhookEventSmsReceived",
1238+
"WebhookEventSmsSent",
1239+
"WebhookEventSmsDelivered",
1240+
"WebhookEventSmsFailed",
1241+
"WebhookEventSystemPing"
11971242
]
11981243
}
11991244
},

api/swagger.yaml

+37-6
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ definitions:
155155
minItems: 1
156156
type: array
157157
simNumber:
158-
description: SIM card number (1-3)
158+
description: SIM card number (1-3), if not set - default SIM will be used
159159
example: 1
160160
maximum: 3
161161
type: integer
@@ -211,6 +211,17 @@ definitions:
211211
- recipients
212212
- state
213213
type: object
214+
smsgateway.MobileDeviceResponse:
215+
properties:
216+
device:
217+
allOf:
218+
- $ref: '#/definitions/smsgateway.Device'
219+
description: Device information, empty if device is not registered on the
220+
server
221+
externalIp:
222+
description: External IP
223+
type: string
224+
type: object
214225
smsgateway.MobileRegisterRequest:
215226
properties:
216227
name:
@@ -331,7 +342,7 @@ definitions:
331342
properties:
332343
event:
333344
allOf:
334-
- $ref: '#/definitions/webhooks.EventType'
345+
- $ref: '#/definitions/smsgateway.WebhookEvent'
335346
description: The type of event the webhook is triggered for.
336347
example: sms:received
337348
id:
@@ -347,16 +358,20 @@ definitions:
347358
- event
348359
- url
349360
type: object
350-
webhooks.EventType:
361+
smsgateway.WebhookEvent:
351362
enum:
352363
- sms:received
353364
- sms:sent
365+
- sms:delivered
366+
- sms:failed
354367
- system:ping
355368
type: string
356369
x-enum-varnames:
357-
- EventTypeSmsReceived
358-
- EventTypeSmsSent
359-
- EventTypeSystemPing
370+
- WebhookEventSmsReceived
371+
- WebhookEventSmsSent
372+
- WebhookEventSmsDelivered
373+
- WebhookEventSmsFailed
374+
- WebhookEventSystemPing
360375
host: api.sms-gate.app
361376
info:
362377
contact:
@@ -635,6 +650,22 @@ paths:
635650
- User
636651
- Webhooks
637652
/mobile/v1/device:
653+
get:
654+
description: Returns device information
655+
produces:
656+
- application/json
657+
responses:
658+
"200":
659+
description: Device information
660+
schema:
661+
$ref: '#/definitions/smsgateway.MobileDeviceResponse'
662+
"500":
663+
description: Internal server error
664+
schema:
665+
$ref: '#/definitions/smsgateway.ErrorResponse'
666+
summary: Get device information
667+
tags:
668+
- Device
638669
patch:
639670
consumes:
640671
- application/json

deployments/docker-compose/docker-compose.yml

+5-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ services:
2626
condition: service_healthy
2727

2828
db:
29-
image: mariadb:10.11
29+
image: mariadb:11.4
3030
environment:
3131
- MYSQL_ROOT_PASSWORD=root
3232
- MYSQL_DATABASE=sms
@@ -37,17 +37,11 @@ services:
3737
- mariadb-data:/var/lib/mysql
3838
restart: 'unless-stopped'
3939
healthcheck:
40-
test:
41-
[
42-
"CMD",
43-
"mysqladmin",
44-
"ping",
45-
"-proot",
46-
"-h",
47-
"127.0.0.1"
48-
]
40+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
41+
start_period: 10s
42+
interval: 10s
4943
timeout: 5s
50-
retries: 10
44+
retries: 3
5145

5246
volumes:
5347
mariadb-data:

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ go 1.22.0
44

55
require (
66
firebase.google.com/go/v4 v4.12.1
7-
github.com/android-sms-gateway/client-go v1.0.5
7+
github.com/android-sms-gateway/client-go v1.1.0
88
github.com/ansrivas/fiberprometheus/v2 v2.6.1
99
github.com/capcom6/go-helpers v0.0.0-20240521035631-865ee2879fa3
1010
github.com/capcom6/go-infra-fx v0.0.2
11+
github.com/go-playground/assert/v2 v2.2.0
1112
github.com/go-playground/validator/v10 v10.16.0
1213
github.com/go-sql-driver/mysql v1.7.1
1314
github.com/gofiber/fiber/v2 v2.52.5

go.sum

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
2626
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
2727
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
2828
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
29-
github.com/android-sms-gateway/client-go v1.0.4 h1:QZ72TRBJKm11WL/jim+ba7m2J5RLBaICMcy7f/RVfuQ=
30-
github.com/android-sms-gateway/client-go v1.0.4/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
31-
github.com/android-sms-gateway/client-go v1.0.5 h1:0jUnRJHk1VqV5K8kla1d8rOO/lXshHG5uChxj7YTzWE=
32-
github.com/android-sms-gateway/client-go v1.0.5/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
29+
github.com/android-sms-gateway/client-go v1.1.0 h1:mAPsueRrY/qOdQAU5yO3uLQAb7Po+3jBxB1tiqyClvg=
30+
github.com/android-sms-gateway/client-go v1.1.0/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
3331
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
3432
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
3533
github.com/ansrivas/fiberprometheus/v2 v2.6.1 h1:wac3pXaE6BYYTF04AC6K0ktk6vCD+MnDOJZ3SK66kXM=
@@ -193,8 +191,6 @@ github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
193191
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
194192
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
195193
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
196-
github.com/nyaruka/phonenumbers v1.3.0 h1:IFyyJfF2Elg8xGKFghWrRXzb6qAHk+Q3uPqmIgS20JQ=
197-
github.com/nyaruka/phonenumbers v1.3.0/go.mod h1:4jyKp/BFUokLbCHyoZag+T3S1KezFVoEKtgnbpzItC4=
198194
github.com/nyaruka/phonenumbers v1.4.0 h1:ddhWiHnHCIX3n6ETDA58Zq5dkxkjlvgrDWM2OHHPCzU=
199195
github.com/nyaruka/phonenumbers v1.4.0/go.mod h1:gv+CtldaFz+G3vHHnasBSirAi3O2XLqZzVWz4V1pl2E=
200196
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
@@ -305,8 +301,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
305301
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
306302
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
307303
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
308-
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4=
309-
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
310304
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d h1:N0hmiNbwsSNwHBAvR3QB5w25pUwH4tK0Y/RltD1j1h4=
311305
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
312306
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package converters
2+
3+
import (
4+
"github.com/android-sms-gateway/client-go/smsgateway"
5+
"github.com/capcom6/sms-gateway/internal/sms-gateway/models"
6+
)
7+
8+
func DeviceToDTO(device *models.Device) *smsgateway.Device {
9+
if device.IsEmpty() {
10+
return nil
11+
}
12+
13+
return &smsgateway.Device{
14+
ID: device.ID,
15+
Name: *device.Name,
16+
CreatedAt: device.CreatedAt,
17+
UpdatedAt: device.UpdatedAt,
18+
DeletedAt: device.DeletedAt,
19+
LastSeen: device.LastSeen,
20+
}
21+
}

0 commit comments

Comments
 (0)