Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69a20cfbbe | ||
|
|
a51979e724 | ||
|
|
4e250d095c | ||
|
|
cac1a9d97d | ||
|
|
a33af13f45
|
||
|
|
0e956da330
|
||
|
|
a0bab48f40
|
||
|
|
400490b633
|
||
|
|
b33c05531b
|
||
|
|
08650619dc
|
||
|
|
161d0da377
|
||
|
|
0334c67c36
|
||
|
|
49f5e0ea40
|
||
|
|
f73c959830
|
||
|
|
57619759d5
|
||
|
|
59c9aa0ff1 | ||
|
|
6641f384ab | ||
|
|
8860d6c801 | ||
|
|
29f8c943a6
|
||
|
|
996b67d890
|
||
|
|
b58174eef2
|
||
|
|
1a3a244c07
|
||
|
|
aefa26199d
|
||
|
|
8728fe9b60
|
||
|
|
d3ce3583a2 | ||
|
|
14f50a118f
|
||
|
|
fb17c02f69
|
||
|
|
0062811cb6
|
||
|
|
84fed38a67
|
||
|
|
6fa5ede358 | ||
|
|
f5f753fe02 | ||
|
|
69b5f4ff89
|
||
|
|
09744d4cdf
|
||
|
|
fa8c7062fc
|
||
|
|
fd8fdd93b9
|
||
|
|
fbaa95b2e9
|
||
|
|
37dcc437de
|
||
|
|
0d252bc261 | ||
|
|
20ffc45f89 | ||
|
|
fddf0f7f87 | ||
|
|
34262cda68 | ||
|
|
a8dbd693ba | ||
|
|
1646428016 | ||
|
|
f69d56f527 |
@@ -5,3 +5,8 @@ DB_PASSWORD=password
|
|||||||
DB_HOST=main_db
|
DB_HOST=main_db
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_SSLMODE=disable
|
DB_SSLMODE=disable
|
||||||
|
TWILIO_AUTH_SID=9M438C93R943U4329MCU43C34U
|
||||||
|
TWILIO_SERVICE_SID=9M4J3X8439U398NUVT3342MC349C348T
|
||||||
|
TWILIO_AUTH_TOKEN="f4a1f2b0b79ea3735078c2d8ee9684e1"
|
||||||
|
TWILIO_PHONE_NUMBER=+10123456789
|
||||||
|
ALLOWED_ORIGINS="http://textsender.com"
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
JWT_SECRET=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
||||||
|
DB_NAME=textsender_db
|
||||||
|
DB_USER=textsender
|
||||||
|
DB_PASSWORD=password
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_SSLMODE=disable
|
||||||
|
TWILIO_AUTH_SID=9M438C93R943U4329MCU43C34U
|
||||||
|
TWILIO_SERVICE_SID=9M4J3X8439U398NUVT3342MC349C348T
|
||||||
|
TWILIO_AUTH_TOKEN="f4a1f2b0b79ea3735078c2d8ee9684e1"
|
||||||
|
TWILIO_PHONE_NUMBER=+10123456789
|
||||||
|
ALLOWED_ORIGINS="http://textsender.com"
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
JWT_SECRET=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
|
||||||
DB_NAME=textsender_db
|
|
||||||
DB_USER=textsender
|
|
||||||
DB_PASSWORD=password
|
|
||||||
DB_HOST=localhost
|
|
||||||
DB_PORT=5432
|
|
||||||
DB_SSLMODE=disable
|
|
||||||
@@ -14,9 +14,9 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.3' # You can specify a specific version or 'stable'
|
go-version: '1.26.1' # You can specify a specific version or 'stable'
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
@@ -24,7 +24,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender_models_deploy_key
|
chmod 600 ~/.ssh/textsender_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:18.0
|
image: postgres:18.3-alpine
|
||||||
env:
|
env:
|
||||||
POSTGRES_USER: ${{ secrets.DB_TEST_USER }}
|
POSTGRES_USER: ${{ secrets.DB_TEST_USER }}
|
||||||
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD }}
|
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD }}
|
||||||
@@ -96,22 +96,24 @@ jobs:
|
|||||||
DB_SSLMODE: disable
|
DB_SSLMODE: disable
|
||||||
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
||||||
run: |
|
run: |
|
||||||
echo "Parent directory"
|
echo "JWT_SECRET=$SECRET_KEY" > .env
|
||||||
echo `pwd`
|
echo "DB_NAME=$DB_NAME" >> .env
|
||||||
|
|
||||||
echo "JWT_SECRET=$SECRET_KEY" >> .env
|
|
||||||
echo "DB_NAME=$DB_NAME" > .env
|
|
||||||
echo "DB_USER=$DB_USER" >> .env
|
echo "DB_USER=$DB_USER" >> .env
|
||||||
echo "DB_PASSWORD=$DB_PASSWORD" >> .env
|
echo "DB_PASSWORD=$DB_PASSWORD" >> .env
|
||||||
echo "DB_HOST=$DB_HOST" >> .env
|
echo "DB_HOST=$DB_HOST" >> .env
|
||||||
echo "DB_PORT=$DB_PORT" >> .env
|
echo "DB_PORT=$DB_PORT" >> .env
|
||||||
echo "DB_SSLMODE=$DB_SSLMODE" >> .env
|
echo "DB_SSLMODE=$DB_SSLMODE" >> .env
|
||||||
|
echo "TWILIO_AUTH_SID=9M438C93R943U4329MCU43C34U" >> .env
|
||||||
|
echo "TWILIO_SERVICE_SID=9M4J3X8439U398NUVT3342MC349C348T" >> .env
|
||||||
|
echo "TWILIO_AUTH_TOKEN=f4a1f2b0b79ea3735078c2d8ee9684e1" >> .env
|
||||||
|
echo "TWILIO_PHONE_NUMBER=10123456789" >> .env
|
||||||
|
echo "ALLOWED_ORIGINS=http://localhost:5173" >> .env
|
||||||
|
|
||||||
echo "Initializing config"
|
echo "Initializing config"
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender_models_deploy_key
|
chmod 600 ~/.ssh/textsender_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,5 @@
|
|||||||
# Multi-stage Dockerfile for Go application
|
# Multi-stage Dockerfile for Go application
|
||||||
FROM golang:1.25.3 AS builder
|
FROM golang:1.26.1 AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ COPY ./internal ./internal
|
|||||||
COPY ./Makefile .
|
COPY ./Makefile .
|
||||||
COPY ./.env .
|
COPY ./.env .
|
||||||
COPY ./migrations ./migrations
|
COPY ./migrations ./migrations
|
||||||
|
COPY ./docs ./docs
|
||||||
|
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN CGO_ENABLED=0 GOOS=linux make build
|
RUN CGO_ENABLED=0 GOOS=linux make build
|
||||||
|
|||||||
@@ -4,7 +4,18 @@ A software system to process Text messaging queueing
|
|||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
```BASH
|
```SHELL
|
||||||
make build
|
make build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Generate API documentation
|
||||||
|
```
|
||||||
|
go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
|
|
||||||
|
swag init --generalInfo main.go --dir ./cmd/api,./internal/handler --output docs/ --parseDependency --parseInternal
|
||||||
|
```
|
||||||
|
|
||||||
|
The API documentation can be viewed from `http://localhost:8080/swagger/index.html`.
|
||||||
|
|||||||
+61
-25
@@ -12,7 +12,11 @@ import (
|
|||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
|
"github.com/go-chi/cors"
|
||||||
|
"github.com/swaggo/http-swagger/v2"
|
||||||
|
|
||||||
|
_ "git.kundeng.us/phoenix/textsender-api/docs"
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/config"
|
"git.kundeng.us/phoenix/textsender-api/internal/config"
|
||||||
database "git.kundeng.us/phoenix/textsender-api/internal/db"
|
database "git.kundeng.us/phoenix/textsender-api/internal/db"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/handler"
|
"git.kundeng.us/phoenix/textsender-api/internal/handler"
|
||||||
@@ -22,19 +26,32 @@ import (
|
|||||||
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// @title textsender-api
|
||||||
|
// @version 1.0
|
||||||
|
// @description Core API to send text messages
|
||||||
|
|
||||||
|
// @host localhost:8080
|
||||||
|
// @BasePath /api/v1
|
||||||
|
|
||||||
|
// @securityDefinitions.apikey BearerAuth
|
||||||
|
// @in header
|
||||||
|
// @name Authorization
|
||||||
|
// @description JWT Bearer Token
|
||||||
func main() {
|
func main() {
|
||||||
cfg := config.Load()
|
cfg, tCfg, err := config.Load()
|
||||||
if cfg == nil {
|
if err != nil {
|
||||||
fmt.Println("Error initializing config")
|
log.Fatal("Error:", err)
|
||||||
os.Exit(-1)
|
} else if cfg == nil {
|
||||||
|
log.Fatal("Error initializing config")
|
||||||
} else if cfg.JWTSecret == "" {
|
} else if cfg.JWTSecret == "" {
|
||||||
fmt.Println("Error: JWTSecret not initialized")
|
log.Fatal("Error: JWTSecret not initialized")
|
||||||
os.Exit(-1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiApp := app.App{TwilioConfig: tCfg}
|
||||||
|
|
||||||
db, err := database.NewDatabase(cfg.GetDBConnString())
|
db, err := database.NewDatabase(cfg.GetDBConnString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to connect to database: %v", err)
|
log.Fatal("Failed to connect to database:", err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
@@ -43,19 +60,18 @@ func main() {
|
|||||||
if cfg.ResetDB {
|
if cfg.ResetDB {
|
||||||
log.Println("Resetting database")
|
log.Println("Resetting database")
|
||||||
if err := db.ResetDatabase(ctx); err != nil {
|
if err := db.ResetDatabase(ctx); err != nil {
|
||||||
log.Fatalf("Failed to reset database: %v", err)
|
log.Fatal("Failed to reset database:", err)
|
||||||
}
|
}
|
||||||
log.Println("Database reset completed. Exiting.")
|
log.Println("Database reset completed. Exiting.")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if exists, err := database.TableExists(ctx, db.Pool, "contacts "); err == nil && !exists {
|
if exists, err := database.TableExists(ctx, db.Pool, "contacts"); err == nil && !exists {
|
||||||
fmt.Println("Resetting database")
|
log.Println("Resetting database")
|
||||||
err = db.ResetDatabase(ctx)
|
if err = db.ResetDatabase(ctx); err != nil {
|
||||||
if err != nil {
|
log.Fatal("Error:", err)
|
||||||
fmt.Printf("Error:%v", err)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error:%v", err)
|
log.Fatal("Error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,31 +81,51 @@ func main() {
|
|||||||
messageStore := store.NewMessageStore(db.Pool)
|
messageStore := store.NewMessageStore(db.Pool)
|
||||||
schStore := store.NewScheduledMessageStore(db.Pool)
|
schStore := store.NewScheduledMessageStore(db.Pool)
|
||||||
schMsgEventStore := store.NewScheduledMessageEventStore(db.Pool)
|
schMsgEventStore := store.NewScheduledMessageEventStore(db.Pool)
|
||||||
|
merStore := store.NewMessageEventResponseStore(db.Pool)
|
||||||
|
|
||||||
contactHandler := handler.NewContactHandler(contactStore)
|
contactHandler := handler.NewContactHandler(&apiApp, contactStore)
|
||||||
messageHandler := handler.NewMessageHandler(messageStore)
|
messageHandler := handler.NewMessageHandler(&apiApp, messageStore)
|
||||||
scheduledMessageHandler := handler.NewScheduledMessageHandler(schStore)
|
scheduledMessageHandler := handler.NewScheduledMessageHandler(&apiApp, schStore)
|
||||||
scheduledMessageEventHandler := handler.NewScheduledMessageEventHandler(schMsgEventStore, schStore)
|
scheduledMessageEventHandler := handler.NewScheduledMessageEventHandler(&apiApp, schMsgEventStore, schStore)
|
||||||
scheduledMessageStatusHandler := handler.NewScheduledMessageStatusHandler(schMsgEventStore, schStore)
|
scheduledMessageStatusHandler := handler.NewScheduledMessageStatusHandler(&apiApp, schMsgEventStore, schStore)
|
||||||
|
eventHandler := handler.NewEventResponseHandler(&apiApp, merStore)
|
||||||
|
instantMessageHandler := handler.NewSendInstantMessageHandler(&apiApp, merStore, contactStore, messageStore)
|
||||||
|
|
||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
|
|
||||||
|
// Configure CORS
|
||||||
|
router.Use(cors.Handler(cors.Options{
|
||||||
|
AllowedOrigins: cfg.AllowedOrigins,
|
||||||
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
|
||||||
|
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
|
||||||
|
ExposedHeaders: []string{"Link", "X-Total-Count"},
|
||||||
|
AllowCredentials: true,
|
||||||
|
MaxAge: 300, // 5 minutes
|
||||||
|
}))
|
||||||
router.Use(middleware.Logger)
|
router.Use(middleware.Logger)
|
||||||
router.Use(middleware.Recoverer)
|
router.Use(middleware.Recoverer)
|
||||||
router.Use(middleware.Timeout(60 * time.Second))
|
router.Use(middleware.Timeout(60 * time.Second))
|
||||||
router.Use(mdlware.JSONContentType)
|
router.Use(mdlware.JSONContentType)
|
||||||
|
|
||||||
router.Handle(endpoint.ADD_CONTACT_ENDPOINT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.AddContact)))
|
router.Method("POST", endpoint.ADD_CONTACT_ENDPOINT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.AddContact)))
|
||||||
router.Handle(endpoint.GET_CONTACT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.GetContact)))
|
router.Method("GET", endpoint.GET_CONTACT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.GetContact)))
|
||||||
router.Handle(endpoint.ADD_MESSAGE, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(messageHandler.AddMessage)))
|
router.Method("POST", endpoint.ADD_MESSAGE, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(messageHandler.AddMessage)))
|
||||||
router.Handle(endpoint.GET_MESSAGE, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(messageHandler.GetMessage)))
|
router.Method("GET", endpoint.GET_MESSAGE, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(messageHandler.GetMessage)))
|
||||||
router.Handle(endpoint.ScheduleMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.AddScheduledMessage)))
|
router.Method("POST", endpoint.ScheduleMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.AddScheduledMessage)))
|
||||||
router.Handle(endpoint.AddEventToScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageEventHandler.AddScheduledMessageEvent)))
|
router.Method("POST", endpoint.AddEventToScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageEventHandler.AddScheduledMessageEvent)))
|
||||||
router.Method("GET", endpoint.GetScheduledMessageEventEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageEventHandler.GetScheduledMessageEvent)))
|
router.Method("GET", endpoint.GetScheduledMessageEventEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageEventHandler.GetScheduledMessageEvent)))
|
||||||
router.Method("DELETE", endpoint.DeleteScheduledMessageEventEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageEventHandler.DeleteScheduledMessageEvent)))
|
router.Method("DELETE", endpoint.DeleteScheduledMessageEventEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageEventHandler.DeleteScheduledMessageEvent)))
|
||||||
router.Method("PATCH", endpoint.UpdateScheduledMessageStatusEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageStatusHandler.UpdateStatus)))
|
router.Method("PATCH", endpoint.UpdateScheduledMessageStatusEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageStatusHandler.UpdateStatus)))
|
||||||
router.Method("GET", endpoint.GetScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.GetScheduledMessage)))
|
router.Method("GET", endpoint.GetScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.GetScheduledMessage)))
|
||||||
router.Method("GET", endpoint.FetchNextScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.FetchNextMessage)))
|
router.Method("GET", endpoint.FetchNextScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.FetchNextMessage)))
|
||||||
|
router.Method("POST", endpoint.RecordEventResponse, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(eventHandler.RecordResponse)))
|
||||||
|
router.Method("GET", endpoint.FetchMessageEventResponse, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(eventHandler.Fetch)))
|
||||||
|
router.Method("POST", endpoint.SendInstantMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(instantMessageHandler.Send)))
|
||||||
|
router.Method("PATCH", endpoint.Update_Names_Endpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.UpdateName)))
|
||||||
|
|
||||||
|
router.Method("GET", "/swagger/*", httpSwagger.Handler(
|
||||||
|
httpSwagger.URL(fmt.Sprintf("http://localhost:%s/swagger/doc.json", config.PORT)),
|
||||||
|
))
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
|
|||||||
+32
-19
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/config"
|
"git.kundeng.us/phoenix/textsender-api/internal/config"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/db"
|
"git.kundeng.us/phoenix/textsender-api/internal/db"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/handler"
|
"git.kundeng.us/phoenix/textsender-api/internal/handler"
|
||||||
@@ -24,12 +25,12 @@ import (
|
|||||||
var testRouter *chi.Mux
|
var testRouter *chi.Mux
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := load()
|
cfg, apiApp := load()
|
||||||
|
|
||||||
database, err := db.NewDatabase(cfg.GetDBConnString())
|
database, err := db.NewDatabase(cfg.GetDBConnString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
log.Println(err.Error())
|
||||||
panic("Failed to initialize database")
|
log.Fatal("Failed to initialize database")
|
||||||
}
|
}
|
||||||
defer database.Close()
|
defer database.Close()
|
||||||
|
|
||||||
@@ -37,18 +38,18 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
if cfg.ResetDB {
|
if cfg.ResetDB {
|
||||||
if err = database.ResetDatabase(ctx); err != nil {
|
if err = database.ResetDatabase(ctx); err != nil {
|
||||||
fmt.Println(err.Error())
|
log.Println(err.Error())
|
||||||
panic("Failed to initialize database")
|
log.Fatalln("Failed to initialize database")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if exists, err := db.TableExists(ctx, database.Pool, "contacts "); err == nil && !exists {
|
if exists, err := db.TableExists(ctx, database.Pool, "contacts "); err == nil && !exists {
|
||||||
fmt.Println("Resetting database")
|
log.Println("Resetting database")
|
||||||
err = database.ResetDatabase(ctx)
|
err = database.ResetDatabase(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error:%v", err)
|
log.Println("Error:", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error:%v", err)
|
log.Println("Error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +59,15 @@ func TestMain(m *testing.M) {
|
|||||||
messageStore := store.NewMessageStore(db.Pool)
|
messageStore := store.NewMessageStore(db.Pool)
|
||||||
schStore := store.NewScheduledMessageStore(db.Pool)
|
schStore := store.NewScheduledMessageStore(db.Pool)
|
||||||
schMsgEventStore := store.NewScheduledMessageEventStore(db.Pool)
|
schMsgEventStore := store.NewScheduledMessageEventStore(db.Pool)
|
||||||
|
merStore := store.NewMessageEventResponseStore(db.Pool)
|
||||||
|
|
||||||
contactHandler := handler.NewContactHandler(contactStore)
|
contactHandler := handler.NewContactHandler(apiApp, contactStore)
|
||||||
messageHandler := handler.NewMessageHandler(messageStore)
|
messageHandler := handler.NewMessageHandler(apiApp, messageStore)
|
||||||
scheduledMessageHandler := handler.NewScheduledMessageHandler(schStore)
|
scheduledMessageHandler := handler.NewScheduledMessageHandler(apiApp, schStore)
|
||||||
scheduledMessageEventHandler := handler.NewScheduledMessageEventHandler(schMsgEventStore, schStore)
|
scheduledMessageEventHandler := handler.NewScheduledMessageEventHandler(apiApp, schMsgEventStore, schStore)
|
||||||
scheduledMessageStatusHandler := handler.NewScheduledMessageStatusHandler(schMsgEventStore, schStore)
|
scheduledMessageStatusHandler := handler.NewScheduledMessageStatusHandler(apiApp, schMsgEventStore, schStore)
|
||||||
|
eventHandler := handler.NewEventResponseHandler(apiApp, merStore)
|
||||||
|
instantMessageHandler := handler.NewSendInstantMessageHandler(apiApp, merStore, contactStore, messageStore)
|
||||||
|
|
||||||
testRouter = chi.NewRouter()
|
testRouter = chi.NewRouter()
|
||||||
testRouter.Handle(endpoint.ADD_CONTACT_ENDPOINT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.AddContact)))
|
testRouter.Handle(endpoint.ADD_CONTACT_ENDPOINT, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.AddContact)))
|
||||||
@@ -76,12 +80,16 @@ func TestMain(m *testing.M) {
|
|||||||
testRouter.Method("PATCH", endpoint.UpdateScheduledMessageStatusEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageStatusHandler.UpdateStatus)))
|
testRouter.Method("PATCH", endpoint.UpdateScheduledMessageStatusEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageStatusHandler.UpdateStatus)))
|
||||||
testRouter.Method("GET", endpoint.GetScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.GetScheduledMessage)))
|
testRouter.Method("GET", endpoint.GetScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.GetScheduledMessage)))
|
||||||
testRouter.Method("GET", endpoint.FetchNextScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.FetchNextMessage)))
|
testRouter.Method("GET", endpoint.FetchNextScheduledMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(scheduledMessageHandler.FetchNextMessage)))
|
||||||
|
testRouter.Method("POST", endpoint.RecordEventResponse, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(eventHandler.RecordResponse)))
|
||||||
|
testRouter.Method("GET", endpoint.FetchMessageEventResponse, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(eventHandler.Fetch)))
|
||||||
|
testRouter.Method("POST", endpoint.SendInstantMessageEndpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(instantMessageHandler.Send)))
|
||||||
|
testRouter.Method("PATCH", endpoint.Update_Names_Endpoint, mdlware.AuthMiddleware(jwtService)(http.HandlerFunc(contactHandler.UpdateName)))
|
||||||
|
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func load() *config.Config {
|
func load() (*config.Config, *app.App) {
|
||||||
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
||||||
port := flag.String("port", config.PORT, "Server port")
|
port := flag.String("port", config.PORT, "Server port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -100,10 +108,15 @@ func load() *config.Config {
|
|||||||
unpackedConnString := config.UnpackDBConnString()
|
unpackedConnString := config.UnpackDBConnString()
|
||||||
dbConnString := unpackedConnString.Parse()
|
dbConnString := unpackedConnString.Parse()
|
||||||
|
|
||||||
return &config.Config{
|
if tCfg, err := config.TwilioConfig(); err != nil {
|
||||||
DBConnString: dbConnString,
|
log.Fatal("Error: ", err)
|
||||||
ServerPort: *port,
|
return nil, nil
|
||||||
ResetDB: *resetDb,
|
} else {
|
||||||
|
return &config.Config{
|
||||||
|
DBConnString: dbConnString,
|
||||||
|
ServerPort: *port,
|
||||||
|
ResetDB: *resetDb,
|
||||||
|
}, &app.App{TwilioConfig: tCfg}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-4
@@ -5,7 +5,7 @@ services:
|
|||||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
build: # Tells docker-compose to build the Dockerfile in the current directory
|
||||||
context: .
|
context: .
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"] # Uses host's SSH agent
|
||||||
container_name: textsender # Optional: Give the container a specific name
|
container_name: textsender_api # Optional: Give the container a specific name
|
||||||
ports:
|
ports:
|
||||||
# Map host port 8000 to container port 3000 (adjust as needed)
|
# Map host port 8000 to container port 3000 (adjust as needed)
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
@@ -19,7 +19,7 @@ services:
|
|||||||
restart: unless-stopped # Optional: Restart policy
|
restart: unless-stopped # Optional: Restart policy
|
||||||
|
|
||||||
auth_api:
|
auth_api:
|
||||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
build:
|
||||||
context: ../textsender-auth
|
context: ../textsender-auth
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"] # Uses host's SSH agent
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
@@ -36,9 +36,24 @@ services:
|
|||||||
- textsender-network
|
- textsender-network
|
||||||
restart: unless-stopped # Optional: Restart policy
|
restart: unless-stopped # Optional: Restart policy
|
||||||
|
|
||||||
|
catapult:
|
||||||
|
build:
|
||||||
|
context: ../catapult
|
||||||
|
ssh: ["default"]
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: catapult
|
||||||
|
env_file:
|
||||||
|
- ../catapult/.env
|
||||||
|
depends_on:
|
||||||
|
- auth_api
|
||||||
|
- api
|
||||||
|
networks:
|
||||||
|
- textsender-network
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
# PostgreSQL Database Service
|
# PostgreSQL Database Service
|
||||||
main_db:
|
main_db:
|
||||||
image: postgres:18.0-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
|
||||||
container_name: textsender_db # Optional: Give the container a specific name
|
container_name: textsender_db # Optional: Give the container a specific name
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
@@ -62,7 +77,7 @@ services:
|
|||||||
restart: always # Optional: Restart policy
|
restart: always # Optional: Restart policy
|
||||||
|
|
||||||
auth_db:
|
auth_db:
|
||||||
image: postgres:18.0-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
|
||||||
container_name: textsender_auth_db # Optional: Give the container a specific name
|
container_name: textsender_auth_db # Optional: Give the container a specific name
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
|
|||||||
+1282
File diff suppressed because it is too large
Load Diff
+1258
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,810 @@
|
|||||||
|
basePath: /api/v1
|
||||||
|
definitions:
|
||||||
|
contact.Contact:
|
||||||
|
properties:
|
||||||
|
first_name:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
last_name:
|
||||||
|
type: string
|
||||||
|
nickname:
|
||||||
|
type: string
|
||||||
|
phone_number:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
event.MessageEventResponse:
|
||||||
|
properties:
|
||||||
|
contact_id:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
message_id:
|
||||||
|
type: string
|
||||||
|
response:
|
||||||
|
additionalProperties: {}
|
||||||
|
type: object
|
||||||
|
scheduled_message_event_id:
|
||||||
|
type: string
|
||||||
|
sent:
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.AddContactResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/contact.Contact'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.AddMessageResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/message.Message'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.AddScheduledMessageEventResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessageEvent'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.AddScheduledMessageResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessage'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.DeleteScheduledMessageEventResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessageEvent'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.FetchNextMessageResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessage'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.GetContactResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/contact.Contact'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.GetMessageEventResponseFetchedResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/event.MessageEventResponse'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.GetMessageResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/message.Message'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.GetScheduledMessageEventResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessageEvent'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.GetScheduledMessageResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessage'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RecordEventRequest:
|
||||||
|
properties:
|
||||||
|
contact_id:
|
||||||
|
type: string
|
||||||
|
message_id:
|
||||||
|
type: string
|
||||||
|
response:
|
||||||
|
additionalProperties: {}
|
||||||
|
type: object
|
||||||
|
scheduled_message_event_id:
|
||||||
|
type: string
|
||||||
|
sent:
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RecordEventResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/event.MessageEventResponse'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RequestAddContact:
|
||||||
|
properties:
|
||||||
|
first_name:
|
||||||
|
type: string
|
||||||
|
last_name:
|
||||||
|
type: string
|
||||||
|
nickname:
|
||||||
|
type: string
|
||||||
|
phone_number:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RequestAddMessage:
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RequestAddScheduledMessage:
|
||||||
|
properties:
|
||||||
|
scheduled:
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RequestAddScheduledMessageEvent:
|
||||||
|
properties:
|
||||||
|
contact_id:
|
||||||
|
type: string
|
||||||
|
message_id:
|
||||||
|
type: string
|
||||||
|
scheduled_message_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.RequestScheduledMessageStatus:
|
||||||
|
properties:
|
||||||
|
scheduled_message_id:
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.ScheduledMessageChange:
|
||||||
|
properties:
|
||||||
|
old_status:
|
||||||
|
type: string
|
||||||
|
scheduled_message:
|
||||||
|
$ref: '#/definitions/scheduling.ScheduledMessage'
|
||||||
|
type: object
|
||||||
|
handler.ScheduledMessageStatusResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/handler.ScheduledMessageChange'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.SendInstantMessageRequest:
|
||||||
|
properties:
|
||||||
|
contact_ids:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
message_id:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.SendInstantMessageResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/event.MessageEventResponse'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.UpdateNameRequest:
|
||||||
|
properties:
|
||||||
|
contact_id:
|
||||||
|
type: string
|
||||||
|
first_name:
|
||||||
|
type: string
|
||||||
|
last_name:
|
||||||
|
type: string
|
||||||
|
nickname:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
handler.UpdateNameResponse:
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/contact.Contact'
|
||||||
|
type: array
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
message.Message:
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
scheduling.ScheduledMessage:
|
||||||
|
properties:
|
||||||
|
created:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
scheduled:
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
user_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
scheduling.ScheduledMessageEvent:
|
||||||
|
properties:
|
||||||
|
contact_id:
|
||||||
|
type: string
|
||||||
|
created:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
message_id:
|
||||||
|
type: string
|
||||||
|
scheduled_message_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
host: localhost:8080
|
||||||
|
info:
|
||||||
|
contact: {}
|
||||||
|
description: Core API to send text messages
|
||||||
|
title: textsender-api
|
||||||
|
version: "1.0"
|
||||||
|
paths:
|
||||||
|
/contact:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Get a contact record to have a recipient to send a text to (requires
|
||||||
|
JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Contact Id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: User Id
|
||||||
|
in: path
|
||||||
|
name: user_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetContactResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetContactResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetContactResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Get contact
|
||||||
|
tags:
|
||||||
|
- contacts
|
||||||
|
/contact/new:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Add a contact record to have a recipient to send a text to (requires
|
||||||
|
JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Data to add contact
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RequestAddContact'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddContactResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddContactResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddContactResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Add contact
|
||||||
|
tags:
|
||||||
|
- contacts
|
||||||
|
/contact/update:
|
||||||
|
patch:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Update the first, last, or nickname of a Contact (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Data to update contact's names
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.UpdateNameRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.UpdateNameResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.UpdateNameResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.UpdateNameResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Update names of Contact
|
||||||
|
tags:
|
||||||
|
- contacts
|
||||||
|
/instant/message:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Send a message without the constraints of scheduled messages (requires
|
||||||
|
JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Send an instnt message
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.SendInstantMessageRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.SendInstantMessageResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.SendInstantMessageResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.SendInstantMessageResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Send instant message
|
||||||
|
tags:
|
||||||
|
- messages
|
||||||
|
/message:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Get a message record to have a recipient to send a text to (requires
|
||||||
|
JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Message Id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: User Id
|
||||||
|
in: path
|
||||||
|
name: user_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetMessageResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetMessageResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetMessageResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Get message
|
||||||
|
tags:
|
||||||
|
- messages
|
||||||
|
/message/new:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Add a message record to send a text to (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Data to add message
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RequestAddMessage'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddMessageResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddMessageResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddMessageResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Add message
|
||||||
|
tags:
|
||||||
|
- messages
|
||||||
|
/schedule/message:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Get a scheduled message (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Contact Id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: User Id
|
||||||
|
in: path
|
||||||
|
name: user_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetScheduledMessageResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetScheduledMessageResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetScheduledMessageResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Get scheduled message
|
||||||
|
tags:
|
||||||
|
- scheduled messages
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Adds a scheduled message (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Data to add scheduled message
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RequestAddScheduledMessage'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddScheduledMessageResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddScheduledMessageResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddScheduledMessageResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Add scheduled message
|
||||||
|
tags:
|
||||||
|
- scheduled messages
|
||||||
|
/schedule/message/event:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Gets a scheduled message event (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Contact Id
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Scheduled Message Id
|
||||||
|
in: path
|
||||||
|
name: scheduled_message_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetScheduledMessageEventResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetScheduledMessageEventResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetScheduledMessageEventResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Get scheduled message event
|
||||||
|
tags:
|
||||||
|
- scheduled message events
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Add a scheduled message event (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Data to add scheduled message event
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RequestAddScheduledMessageEvent'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddScheduledMessageEventResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddScheduledMessageEventResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.AddScheduledMessageEventResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Add scheduled message event
|
||||||
|
tags:
|
||||||
|
- scheduled message events
|
||||||
|
/schedule/message/event/{id}:
|
||||||
|
delete:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Deletes a scheduled message event (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: scheduled message event Id
|
||||||
|
format: uuid
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.DeleteScheduledMessageEventResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.DeleteScheduledMessageEventResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.DeleteScheduledMessageEventResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Delete scheduled message event
|
||||||
|
tags:
|
||||||
|
- scheduled message events
|
||||||
|
/schedule/message/event/response:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Fetches a MessageEventResponse given a user id (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: User Id
|
||||||
|
in: path
|
||||||
|
name: user_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetMessageEventResponseFetchedResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetMessageEventResponseFetchedResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.GetMessageEventResponseFetchedResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Fetcht MessageEventResponse
|
||||||
|
tags:
|
||||||
|
- message
|
||||||
|
/schedule/message/event/response/record:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Saves the result of sending a text message (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Data to add MessageEventResponse
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RecordEventRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RecordEventResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RecordEventResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RecordEventResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Record MessageEventResponse
|
||||||
|
tags:
|
||||||
|
- message
|
||||||
|
/schedule/message/fetch:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Fetches a scheduled message that is available to be processed (requires
|
||||||
|
JWT)
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.FetchNextMessageResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.FetchNextMessageResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.FetchNextMessageResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Fetch scheduled message
|
||||||
|
tags:
|
||||||
|
- scheduled messages
|
||||||
|
/schedule/message/status/update:
|
||||||
|
patch:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Update the status of a scheduled message (requires JWT)
|
||||||
|
parameters:
|
||||||
|
- description: Used to update scheduled message status
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.RequestScheduledMessageStatus'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Created
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.ScheduledMessageStatusResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.ScheduledMessageStatusResponse'
|
||||||
|
"404":
|
||||||
|
description: Not Found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.ScheduledMessageStatusResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/handler.ScheduledMessageStatusResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Update status
|
||||||
|
tags:
|
||||||
|
- status
|
||||||
|
securityDefinitions:
|
||||||
|
BearerAuth:
|
||||||
|
description: JWT Bearer Token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
type: apiKey
|
||||||
|
swagger: "2.0"
|
||||||
@@ -1,28 +1,48 @@
|
|||||||
module git.kundeng.us/phoenix/textsender-api
|
module git.kundeng.us/phoenix/textsender-api
|
||||||
|
|
||||||
go 1.25.3
|
go 1.26.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.6-4-e124bcfda8-556
|
git.kundeng.us/phoenix/swoosh v0.2.0
|
||||||
github.com/go-chi/chi/v5 v5.2.3
|
git.kundeng.us/phoenix/textsender-models v0.2.0
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0
|
github.com/go-chi/chi/v5 v5.2.5
|
||||||
|
github.com/go-chi/cors v1.2.2
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.3.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/mux v1.8.1
|
github.com/jackc/pgx/v5 v5.9.1
|
||||||
github.com/jackc/pgx/v5 v5.7.6
|
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/stretchr/testify v1.11.1
|
github.com/stretchr/testify v1.11.1
|
||||||
|
github.com/swaggo/http-swagger/v2 v2.0.2
|
||||||
|
github.com/swaggo/swag v1.16.6
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/go-openapi/jsonpointer v0.22.5 // indirect
|
||||||
|
github.com/go-openapi/jsonreference v0.21.5 // indirect
|
||||||
|
github.com/go-openapi/spec v0.22.4 // indirect
|
||||||
|
github.com/go-openapi/swag/conv v0.25.5 // indirect
|
||||||
|
github.com/go-openapi/swag/jsonname v0.25.5 // indirect
|
||||||
|
github.com/go-openapi/swag/jsonutils v0.25.5 // indirect
|
||||||
|
github.com/go-openapi/swag/loading v0.25.5 // indirect
|
||||||
|
github.com/go-openapi/swag/stringutils v0.25.5 // indirect
|
||||||
|
github.com/go-openapi/swag/typeutils v0.25.5 // indirect
|
||||||
|
github.com/go-openapi/swag/yamlutils v0.25.5 // indirect
|
||||||
|
github.com/golang/mock v1.6.0 // indirect
|
||||||
|
github.com/google/go-cmp v0.7.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||||
golang.org/x/crypto v0.42.0 // indirect
|
github.com/swaggo/files/v2 v2.0.2 // indirect
|
||||||
golang.org/x/sync v0.17.0 // indirect
|
github.com/twilio/twilio-go v1.30.4 // indirect
|
||||||
golang.org/x/text v0.29.0 // indirect
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
|
golang.org/x/mod v0.34.0 // indirect
|
||||||
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
|
golang.org/x/text v0.35.0 // indirect
|
||||||
|
golang.org/x/tools v0.43.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,23 +1,57 @@
|
|||||||
git.kundeng.us/phoenix/textsender-models v0.0.6-4-e124bcfda8-556 h1:2shgOKmglCODswpCJeCuyPiUAph3wfc0Ep1z6b/ifis=
|
git.kundeng.us/phoenix/swoosh v0.2.0 h1:aecJdtRhgQofaOfki0fm+YszUuwKyfKqF5YVb20yxHI=
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.6-4-e124bcfda8-556/go.mod h1:lx5MCnOgGgsdpwzrfi9uph5xmkeb6H8AuexUNGss2no=
|
git.kundeng.us/phoenix/swoosh v0.2.0/go.mod h1:NxWD9iUunLIJRgTvlZbZa6jyDHc0JPPRuTmsrxV/hMs=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
git.kundeng.us/phoenix/textsender-models v0.2.0 h1:smz8Fs8VOs1Ya23txbOM0YPRidZIsM0yE9unHF0D/nQ=
|
||||||
|
git.kundeng.us/phoenix/textsender-models v0.2.0/go.mod h1:3CkqA/HFKPhpMYxkKn5uVbZEzEbG3sofLZE8pZ1BHO4=
|
||||||
|
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||||
|
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE=
|
github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
|
||||||
github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
|
github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
|
github.com/go-chi/cors v1.2.2 h1:Jmey33TE+b+rB7fT8MUy1u0I4L+NARQlK6LhzKPSyQE=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
github.com/go-chi/cors v1.2.2/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||||
|
github.com/go-openapi/jsonpointer v0.22.5 h1:8on/0Yp4uTb9f4XvTrM2+1CPrV05QPZXu+rvu2o9jcA=
|
||||||
|
github.com/go-openapi/jsonpointer v0.22.5/go.mod h1:gyUR3sCvGSWchA2sUBJGluYMbe1zazrYWIkWPjjMUY0=
|
||||||
|
github.com/go-openapi/jsonreference v0.21.5 h1:6uCGVXU/aNF13AQNggxfysJ+5ZcU4nEAe+pJyVWRdiE=
|
||||||
|
github.com/go-openapi/jsonreference v0.21.5/go.mod h1:u25Bw85sX4E2jzFodh1FOKMTZLcfifd1Q+iKKOUxExw=
|
||||||
|
github.com/go-openapi/spec v0.22.4 h1:4pxGjipMKu0FzFiu/DPwN3CTBRlVM2yLf/YTWorYfDQ=
|
||||||
|
github.com/go-openapi/spec v0.22.4/go.mod h1:WQ6Ai0VPWMZgMT4XySjlRIE6GP1bGQOtEThn3gcWLtQ=
|
||||||
|
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
|
||||||
|
github.com/go-openapi/swag/conv v0.25.5 h1:wAXBYEXJjoKwE5+vc9YHhpQOFj2JYBMF2DUi+tGu97g=
|
||||||
|
github.com/go-openapi/swag/conv v0.25.5/go.mod h1:CuJ1eWvh1c4ORKx7unQnFGyvBbNlRKbnRyAvDvzWA4k=
|
||||||
|
github.com/go-openapi/swag/jsonname v0.25.5 h1:8p150i44rv/Drip4vWI3kGi9+4W9TdI3US3uUYSFhSo=
|
||||||
|
github.com/go-openapi/swag/jsonname v0.25.5/go.mod h1:jNqqikyiAK56uS7n8sLkdaNY/uq6+D2m2LANat09pKU=
|
||||||
|
github.com/go-openapi/swag/jsonutils v0.25.5 h1:XUZF8awQr75MXeC+/iaw5usY/iM7nXPDwdG3Jbl9vYo=
|
||||||
|
github.com/go-openapi/swag/jsonutils v0.25.5/go.mod h1:48FXUaz8YsDAA9s5AnaUvAmry1UcLcNVWUjY42XkrN4=
|
||||||
|
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.5 h1:SX6sE4FrGb4sEnnxbFL/25yZBb5Hcg1inLeErd86Y1U=
|
||||||
|
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.5/go.mod h1:/2KvOTrKWjVA5Xli3DZWdMCZDzz3uV/T7bXwrKWPquo=
|
||||||
|
github.com/go-openapi/swag/loading v0.25.5 h1:odQ/umlIZ1ZVRteI6ckSrvP6e2w9UTF5qgNdemJHjuU=
|
||||||
|
github.com/go-openapi/swag/loading v0.25.5/go.mod h1:I8A8RaaQ4DApxhPSWLNYWh9NvmX2YKMoB9nwvv6oW6g=
|
||||||
|
github.com/go-openapi/swag/stringutils v0.25.5 h1:NVkoDOA8YBgtAR/zvCx5rhJKtZF3IzXcDdwOsYzrB6M=
|
||||||
|
github.com/go-openapi/swag/stringutils v0.25.5/go.mod h1:PKK8EZdu4QJq8iezt17HM8RXnLAzY7gW0O1KKarrZII=
|
||||||
|
github.com/go-openapi/swag/typeutils v0.25.5 h1:EFJ+PCga2HfHGdo8s8VJXEVbeXRCYwzzr9u4rJk7L7E=
|
||||||
|
github.com/go-openapi/swag/typeutils v0.25.5/go.mod h1:itmFmScAYE1bSD8C4rS0W+0InZUBrB2xSPbWt6DLGuc=
|
||||||
|
github.com/go-openapi/swag/yamlutils v0.25.5 h1:kASCIS+oIeoc55j28T4o8KwlV2S4ZLPT6G0iq2SSbVQ=
|
||||||
|
github.com/go-openapi/swag/yamlutils v0.25.5/go.mod h1:Gek1/SjjfbYvM+Iq4QGwa/2lEXde9n2j4a3wI3pNuOQ=
|
||||||
|
github.com/go-openapi/testify/enable/yaml/v2 v2.4.0 h1:7SgOMTvJkM8yWrQlU8Jm18VeDPuAvB/xWrdxFJkoFag=
|
||||||
|
github.com/go-openapi/testify/enable/yaml/v2 v2.4.0/go.mod h1:14iV8jyyQlinc9StD7w1xVPW3CO3q1Gj04Jy//Kw4VM=
|
||||||
|
github.com/go-openapi/testify/v2 v2.4.0 h1:8nsPrHVCWkQ4p8h1EsRVymA2XABB4OT40gcvAu+voFM=
|
||||||
|
github.com/go-openapi/testify/v2 v2.4.0/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||||
|
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||||
|
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
|
||||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
|
github.com/jackc/pgx/v5 v5.9.1 h1:uwrxJXBnx76nyISkhr33kQLlUqjv7et7b9FjCen/tdc=
|
||||||
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
github.com/jackc/pgx/v5 v5.9.1/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
|
||||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
@@ -26,6 +60,10 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
|||||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275 h1:IZycmTpoUtQK3PD60UYBwjaCUHUP7cML494ao9/O8+Q=
|
||||||
|
github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275/go.mod h1:zt6UU74K6Z6oMOYJbJzYpYucqdcQwSMPBEdSvGiaUMw=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
@@ -35,12 +73,47 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
github.com/swaggo/files/v2 v2.0.2 h1:Bq4tgS/yxLB/3nwOMcul5oLEUKa877Ykgz3CJMVbQKU=
|
||||||
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
github.com/swaggo/files/v2 v2.0.2/go.mod h1:TVqetIzZsO9OhHX1Am9sRf9LdrFZqoK49N37KON/jr0=
|
||||||
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
|
github.com/swaggo/http-swagger/v2 v2.0.2 h1:FKCdLsl+sFCx60KFsyM0rDarwiUSZ8DqbfSyIKC9OBg=
|
||||||
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
github.com/swaggo/http-swagger/v2 v2.0.2/go.mod h1:r7/GBkAWIfK6E/OLnE8fXnviHiDeAHmgIyooa4xm3AQ=
|
||||||
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
|
github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI=
|
||||||
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
|
github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg=
|
||||||
|
github.com/twilio/twilio-go v1.30.4 h1:Whrz37IykDD9KJI2YX4LWaGxYWZoYB7va8fASGDrLng=
|
||||||
|
github.com/twilio/twilio-go v1.30.4/go.mod h1:QbitvbvtkV77Jn4BABAKVmxabYSjMyQG4tHey9gfPqg=
|
||||||
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
|
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||||
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI=
|
||||||
|
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||||
|
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
|
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
|
||||||
|
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
auxcfg "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
TwilioConfig *auxcfg.TwilioConfig
|
||||||
|
}
|
||||||
+53
-14
@@ -3,20 +3,23 @@ package config
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
auxcfg "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/version"
|
"git.kundeng.us/phoenix/textsender-api/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DBConnString string
|
DBConnString string
|
||||||
ServerPort string
|
ServerPort string
|
||||||
ResetDB bool
|
ResetDB bool
|
||||||
JWTSecret string `env:"JWT_SECRET" required:"true"`
|
JWTSecret string `env:"JWT_SECRET" required:"true"`
|
||||||
|
TwilioConfig *auxcfg.TwilioConfig
|
||||||
|
AllowedOrigins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionInfo struct {
|
type ConnectionInfo struct {
|
||||||
@@ -46,7 +49,7 @@ func PrintName() {
|
|||||||
fmt.Println(version.String())
|
fmt.Println(version.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() *Config {
|
func Load() (*Config, *auxcfg.TwilioConfig, error) {
|
||||||
versionFlag := flag.Bool("version", false, "Print version information")
|
versionFlag := flag.Bool("version", false, "Print version information")
|
||||||
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
||||||
port := flag.String("port", PORT, "Server port")
|
port := flag.String("port", PORT, "Server port")
|
||||||
@@ -57,19 +60,24 @@ func Load() *Config {
|
|||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := godotenv.Load()
|
if err := godotenv.Load(); err != nil {
|
||||||
if err != nil {
|
return nil, nil, fmt.Errorf("Error loading .env file")
|
||||||
log.Fatal("Error loading .env file")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unpackedConnString := UnpackDBConnString()
|
unpackedConnString := UnpackDBConnString()
|
||||||
dbConnString := unpackedConnString.Parse()
|
dbConnString := unpackedConnString.Parse()
|
||||||
|
|
||||||
return &Config{
|
if cfg, err := TwilioConfig(); err != nil {
|
||||||
DBConnString: dbConnString,
|
return nil, nil, err
|
||||||
ServerPort: *port,
|
} else {
|
||||||
ResetDB: *resetDb,
|
allowedOrigins := unpackAllowedOrigins()
|
||||||
JWTSecret: os.Getenv("JWT_SECRET"),
|
return &Config{
|
||||||
|
DBConnString: dbConnString,
|
||||||
|
ServerPort: *port,
|
||||||
|
ResetDB: *resetDb,
|
||||||
|
JWTSecret: os.Getenv("JWT_SECRET"),
|
||||||
|
AllowedOrigins: allowedOrigins,
|
||||||
|
}, cfg, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +132,37 @@ func UnpackDBConnString() (connInfo ConnectionInfo) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unpackAllowedOrigins() []string {
|
||||||
|
allowedOriginsRaw := os.Getenv("ALLOWED_ORIGINS")
|
||||||
|
allowedOriginsSplit := strings.Split(allowedOriginsRaw, ",")
|
||||||
|
return allowedOriginsSplit
|
||||||
|
}
|
||||||
|
|
||||||
|
func TwilioConfig() (*auxcfg.TwilioConfig, error) {
|
||||||
|
authSid := os.Getenv("TWILIO_AUTH_SID")
|
||||||
|
serviceSid := os.Getenv("TWILIO_SERVICE_SID")
|
||||||
|
authToken := os.Getenv("TWILIO_AUTH_TOKEN")
|
||||||
|
phoneNumber := os.Getenv("TWILIO_PHONE_NUMBER")
|
||||||
|
|
||||||
|
if len(authSid) == 0 {
|
||||||
|
return nil, fmt.Errorf("Twilio config account sid not found")
|
||||||
|
} else if len(serviceSid) == 0 {
|
||||||
|
return nil, fmt.Errorf("Twilio config service sid not found")
|
||||||
|
} else if len(authToken) == 0 {
|
||||||
|
return nil, fmt.Errorf("Twilio config auth token not found")
|
||||||
|
} else if len(phoneNumber) == 0 {
|
||||||
|
return nil, fmt.Errorf("Twilio config phone number not found")
|
||||||
|
} else {
|
||||||
|
var cfg auxcfg.TwilioConfig
|
||||||
|
cfg.AccountSID = authSid
|
||||||
|
cfg.ServiceSID = serviceSid
|
||||||
|
cfg.AuthToken = authToken
|
||||||
|
cfg.Number = phoneNumber
|
||||||
|
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) GetDBConnString() string {
|
func (c *Config) GetDBConnString() string {
|
||||||
return c.DBConnString
|
return c.DBConnString
|
||||||
}
|
}
|
||||||
|
|||||||
+116
-24
@@ -2,17 +2,31 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ContactHandler struct {
|
||||||
|
App *app.App
|
||||||
|
ContactStore store.ContactStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewContactHandler(apiApp *app.App, str store.ContactStore) *ContactHandler {
|
||||||
|
return &ContactHandler{App: apiApp, ContactStore: str}
|
||||||
|
}
|
||||||
|
|
||||||
type RequestAddContact struct {
|
type RequestAddContact struct {
|
||||||
PhoneNumber string `json:"phone_number"`
|
PhoneNumber string `json:"phone_number"`
|
||||||
UserId uuid.UUID `json:"user_id"`
|
UserId uuid.UUID `json:"user_id"`
|
||||||
|
Firstname *string `json:"first_name,omitempty"`
|
||||||
|
Lastname *string `json:"last_name,omitempty"`
|
||||||
|
Nickname *string `json:"nickname,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddContactResponse struct {
|
type AddContactResponse struct {
|
||||||
@@ -20,40 +34,34 @@ type AddContactResponse struct {
|
|||||||
Data []contact.Contact `json:"data"`
|
Data []contact.Contact `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetContactResponse struct {
|
// AddContact godoc
|
||||||
Message string `json:"message"`
|
// @Summary Add contact
|
||||||
Data []contact.Contact `json:"data"`
|
// @Description Add a contact record to have a recipient to send a text to (requires JWT)
|
||||||
}
|
// @Tags contacts
|
||||||
|
// @Accept json
|
||||||
type ContactHandler struct {
|
// @Produce json
|
||||||
ContactStore store.ContactStore
|
// @Security BearerAuth
|
||||||
}
|
// @Param request body RequestAddContact true "Data to add contact"
|
||||||
|
// @Success 201 {object} AddContactResponse
|
||||||
func NewContactHandler(str store.ContactStore) *ContactHandler {
|
// @Failure 400 {object} AddContactResponse
|
||||||
return &ContactHandler{ContactStore: str}
|
// @Failure 500 {object} AddContactResponse
|
||||||
}
|
// @Router /contact/new [post]
|
||||||
|
|
||||||
func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
|
func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req RequestAddContact
|
var req RequestAddContact
|
||||||
if err := ExtractFromRequest(r, &req); err != nil {
|
if err := ExtractFromRequest(r, &req); err != nil {
|
||||||
http.Error(w, "Invalid JSON: "+err.Error(), http.StatusBadRequest)
|
http.Error(w, "Invalid JSON: "+err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
|
||||||
newContact := contact.Contact{PhoneNumber: req.PhoneNumber, UserId: req.UserId}
|
newContact := contact.Contact{PhoneNumber: req.PhoneNumber, UserId: &req.UserId, Firstname: req.Firstname, Lastname: req.Lastname, Nickname: req.Nickname}
|
||||||
|
|
||||||
var statusCode int
|
var statusCode int
|
||||||
var resp AddContactResponse
|
var resp AddContactResponse
|
||||||
|
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
if exists, err := c.ContactStore.ContactExists(ctx, newContact.PhoneNumber, newContact.UserId); err != nil {
|
if exists, err := c.ContactStore.ContactExists(ctx, newContact.PhoneNumber, *newContact.UserId); err != nil {
|
||||||
fmt.Printf("Error: %v", err)
|
log.Printf("Error: %v", err)
|
||||||
statusCode = http.StatusInternalServerError
|
statusCode = http.StatusInternalServerError
|
||||||
resp.Message = err.Error()
|
resp.Message = err.Error()
|
||||||
} else {
|
} else {
|
||||||
@@ -62,7 +70,7 @@ func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp.Message = "Cannot create contact"
|
resp.Message = "Cannot create contact"
|
||||||
} else {
|
} else {
|
||||||
if err := c.ContactStore.CreateContact(ctx, &newContact); err != nil {
|
if err := c.ContactStore.CreateContact(ctx, &newContact); err != nil {
|
||||||
fmt.Printf("Error: %v", err)
|
log.Printf("Error: %v", err)
|
||||||
statusCode = http.StatusInternalServerError
|
statusCode = http.StatusInternalServerError
|
||||||
resp.Message = err.Error()
|
resp.Message = err.Error()
|
||||||
} else {
|
} else {
|
||||||
@@ -76,6 +84,24 @@ func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
|
|||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetContactResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []contact.Contact `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetContact godoc
|
||||||
|
// @Summary Get contact
|
||||||
|
// @Description Get a contact record to have a recipient to send a text to (requires JWT)
|
||||||
|
// @Tags contacts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Contact Id"
|
||||||
|
// @Param user_id path string true "User Id"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Success 200 {object} GetContactResponse
|
||||||
|
// @Failure 400 {object} GetContactResponse
|
||||||
|
// @Failure 500 {object} GetContactResponse
|
||||||
|
// @Router /contact [get]
|
||||||
func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
|
func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
fmt.Println("Method:", r.Method)
|
fmt.Println("Method:", r.Method)
|
||||||
@@ -83,6 +109,7 @@ func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// One or the other
|
||||||
var id, userId uuid.UUID
|
var id, userId uuid.UUID
|
||||||
queryParams := r.URL.Query()
|
queryParams := r.URL.Query()
|
||||||
|
|
||||||
@@ -129,7 +156,7 @@ func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Println("Checking with User Id")
|
fmt.Println("Checking with User Id")
|
||||||
if contacts, err := c.ContactStore.GetAllContacts(ctx); err == nil {
|
if contacts, err := c.ContactStore.GetAllContacts(ctx); err == nil {
|
||||||
for _, con := range contacts {
|
for _, con := range contacts {
|
||||||
if con.UserId == userId {
|
if *con.UserId == userId {
|
||||||
resp.Data = append(resp.Data, *con)
|
resp.Data = append(resp.Data, *con)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,3 +179,68 @@ func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateNameRequest struct {
|
||||||
|
Nickname *string `json:"nickname,omitempty"`
|
||||||
|
Firstname *string `json:"first_name,omitempty"`
|
||||||
|
Lastname *string `json:"last_name,omitempty"`
|
||||||
|
ContactId uuid.UUID `json:"contact_id"`
|
||||||
|
UserId uuid.UUID `json:"user_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateNameResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []contact.Contact `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateName godoc
|
||||||
|
// @Summary Update names of Contact
|
||||||
|
// @Description Update the first, last, or nickname of a Contact (requires JWT)
|
||||||
|
// @Tags contacts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param request body UpdateNameRequest true "Data to update contact's names"
|
||||||
|
// @Success 200 {object} UpdateNameResponse
|
||||||
|
// @Failure 400 {object} UpdateNameResponse
|
||||||
|
// @Failure 500 {object} UpdateNameResponse
|
||||||
|
// @Router /contact/update [patch]
|
||||||
|
func (c *ContactHandler) UpdateName(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req UpdateNameRequest
|
||||||
|
if err := ExtractFromRequest(r, &req); err != nil {
|
||||||
|
http.Error(w, "Invalid JSON: "+err.Error(), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
var statusCode int
|
||||||
|
var resp UpdateNameResponse
|
||||||
|
|
||||||
|
if req.UserId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "User Id not provided"
|
||||||
|
} else if req.ContactId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Contact Id not provided"
|
||||||
|
} else if req.Firstname == nil && req.Lastname == nil && req.Nickname == nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "No name provided"
|
||||||
|
} else {
|
||||||
|
ctx := r.Context()
|
||||||
|
if con, err := c.ContactStore.GetContactByID(ctx, req.ContactId); err != nil {
|
||||||
|
resp.Message = err.Error()
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
} else {
|
||||||
|
if affectedRows, err := c.ContactStore.UpdateNames(ctx, con, req.Firstname, req.Lastname, req.Nickname); err != nil {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
log.Println("Updated", affectedRows, "rows")
|
||||||
|
statusCode = http.StatusOK
|
||||||
|
resp.Message = "Successful"
|
||||||
|
resp.Data = append(resp.Data, *con)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,11 +8,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/db"
|
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/handler/endpoint"
|
"git.kundeng.us/phoenix/textsender-api/internal/handler/endpoint"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/store/mock"
|
"git.kundeng.us/phoenix/textsender-api/internal/store/mock"
|
||||||
)
|
)
|
||||||
@@ -25,7 +23,10 @@ type Request struct {
|
|||||||
|
|
||||||
func TestCreateContactWithMock(t *testing.T) {
|
func TestCreateContactWithMock(t *testing.T) {
|
||||||
mockstore := mock.NewMockContactStore()
|
mockstore := mock.NewMockContactStore()
|
||||||
handler := NewContactHandler(mockstore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
|
||||||
|
handler := NewContactHandler(apiApp, mockstore)
|
||||||
|
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
testBody := Request{PhoneNumber: "+12335403383", UserId: testUserId}
|
testBody := Request{PhoneNumber: "+12335403383", UserId: testUserId}
|
||||||
@@ -39,7 +40,7 @@ func TestCreateContactWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusCreated, rr.Code)
|
assert.Equal(t, http.StatusCreated, rr.Code)
|
||||||
|
|
||||||
var response AddContactResponse
|
var response AddContactResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error Creating contact %v", err)
|
assert.NoError(t, err, "Error Creating contact %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No Contact created")
|
assert.NotEmpty(t, response.Data, "No Contact created")
|
||||||
@@ -51,7 +52,7 @@ func TestGetContactWithMock(t *testing.T) {
|
|||||||
mockstore := mock.NewMockContactStore()
|
mockstore := mock.NewMockContactStore()
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
|
|
||||||
testCon := contact.Contact{PhoneNumber: "+12335403383", UserId: testUserId}
|
testCon := contact.Contact{PhoneNumber: "+12335403383", UserId: &testUserId}
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
if err := mockstore.CreateContact(ctx, &testCon); err != nil {
|
if err := mockstore.CreateContact(ctx, &testCon); err != nil {
|
||||||
assert.NoError(t, err, "Error creating contact")
|
assert.NoError(t, err, "Error creating contact")
|
||||||
@@ -62,13 +63,15 @@ func TestGetContactWithMock(t *testing.T) {
|
|||||||
req, _ := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
contactHandler := NewContactHandler(mockstore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
contactHandler := NewContactHandler(apiApp, mockstore)
|
||||||
contactHandler.GetContact(rr, req)
|
contactHandler.GetContact(rr, req)
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response GetContactResponse
|
var response GetContactResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error getting contact %v", err)
|
assert.NoError(t, err, "Error getting contact %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No Contact retrieved")
|
assert.NotEmpty(t, response.Data, "No Contact retrieved")
|
||||||
@@ -76,10 +79,45 @@ func TestGetContactWithMock(t *testing.T) {
|
|||||||
assert.NotNil(t, response.Data[0].Id, "Id should not be nil")
|
assert.NotNil(t, response.Data[0].Id, "Id should not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetTestDB(t *testing.T) {
|
func TestUpdateContactNamesWithMock(t *testing.T) {
|
||||||
t.Helper()
|
mockstore := mock.NewMockContactStore()
|
||||||
_, err := db.Pool.Exec(context.Background(), "DELETE FROM contacts")
|
testUserId := uuid.New()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to reset test database: %v", err)
|
testCon := contact.Contact{PhoneNumber: "+12335403383", UserId: &testUserId}
|
||||||
|
ctx := t.Context()
|
||||||
|
var firstname, lastname, nickname string
|
||||||
|
firstname = "Bob"
|
||||||
|
lastname = "De-Buildor"
|
||||||
|
nickname = "With The Tool"
|
||||||
|
if err := mockstore.CreateContact(ctx, &testCon); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating contact")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var requestBody UpdateNameRequest
|
||||||
|
requestBody.Firstname = &firstname
|
||||||
|
requestBody.Lastname = &lastname
|
||||||
|
requestBody.Nickname = &nickname
|
||||||
|
requestBody.ContactId = *testCon.Id
|
||||||
|
requestBody.UserId = testUserId
|
||||||
|
jsonValue, _ := json.Marshal(requestBody)
|
||||||
|
req, _ := http.NewRequest("PATCH", endpoint.Update_Names_Endpoint, strings.NewReader(string(jsonValue)))
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
contactHandler := NewContactHandler(apiApp, mockstore)
|
||||||
|
contactHandler.UpdateName(rr, req)
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
|
var response UpdateNameResponse
|
||||||
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
|
assert.NoError(t, err, "Error updating names of contact %v", err)
|
||||||
|
|
||||||
|
assert.NotEmpty(t, response.Data, "No Contact updated")
|
||||||
|
|
||||||
|
assert.NotNil(t, response.Data[0].Firstname, "Firstname should not be nil")
|
||||||
|
assert.NotNil(t, response.Data[0].Lastname, "Lastname should not be nil")
|
||||||
|
assert.NotNil(t, response.Data[0].Nickname, "Nickname should not be nil")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import "net/http"
|
|||||||
|
|
||||||
import "git.kundeng.us/phoenix/textsender-api/internal/model"
|
import "git.kundeng.us/phoenix/textsender-api/internal/model"
|
||||||
|
|
||||||
|
// TODO: Remove file
|
||||||
func DraftMessageHandler(w http.ResponseWriter, r *http.Request) {
|
func DraftMessageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
da := model.MessageItem{
|
da := model.MessageItem{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
|
|||||||
@@ -1,14 +1,29 @@
|
|||||||
package endpoint
|
package endpoint
|
||||||
|
|
||||||
const MESSAGE_DRAFT_ENDPOINT = "/api/v1/message/draft"
|
const (
|
||||||
const ADD_MESSAGE = "/api/v1/message/new"
|
MESSAGE_DRAFT_ENDPOINT = "/api/v1/message/draft"
|
||||||
const GET_MESSAGE = "/api/v1/message"
|
|
||||||
const GET_CONTACT = "/api/v1/contact"
|
ADD_MESSAGE = "/api/v1/message/new"
|
||||||
const ADD_CONTACT_ENDPOINT = "/api/v1/contact/new"
|
GET_MESSAGE = "/api/v1/message"
|
||||||
const ScheduleMessageEndpoint = "/api/v1/schedule/message"
|
|
||||||
const GetScheduledMessageEndpoint = "/api/v1/schedule/message"
|
GET_CONTACT = "/api/v1/contact"
|
||||||
const AddEventToScheduledMessageEndpoint = "/api/v1/schedule/message/event"
|
ADD_CONTACT_ENDPOINT = "/api/v1/contact/new"
|
||||||
const GetScheduledMessageEventEndpoint = "/api/v1/schedule/message/event"
|
Update_Names_Endpoint = "/api/v1/contact/update"
|
||||||
const DeleteScheduledMessageEventEndpoint = "/api/v1/schedule/message/event/{id}"
|
|
||||||
const UpdateScheduledMessageStatusEndpoint = "/api/v1/schedule/message/status/update"
|
ScheduleMessageEndpoint = "/api/v1/schedule/message"
|
||||||
const FetchNextScheduledMessageEndpoint = "/api/v1/schedule/message/fetch"
|
GetScheduledMessageEndpoint = "/api/v1/schedule/message"
|
||||||
|
|
||||||
|
AddEventToScheduledMessageEndpoint = "/api/v1/schedule/message/event"
|
||||||
|
GetScheduledMessageEventEndpoint = "/api/v1/schedule/message/event"
|
||||||
|
DeleteScheduledMessageEventEndpoint = "/api/v1/schedule/message/event/{id}"
|
||||||
|
UpdateScheduledMessageStatusEndpoint = "/api/v1/schedule/message/status/update"
|
||||||
|
|
||||||
|
FetchNextScheduledMessageEndpoint = "/api/v1/schedule/message/fetch"
|
||||||
|
|
||||||
|
// TODO: Tweak endpoint verbage for MessageEventResponse endpoint
|
||||||
|
// TODO: Make RecordEventResponse more consistent with MessageEventResponse
|
||||||
|
RecordEventResponse = "/api/v1/schedule/message/event/response/record"
|
||||||
|
FetchMessageEventResponse = "/api/v1/schedule/message/event/response"
|
||||||
|
|
||||||
|
SendInstantMessageEndpoint = "/api/v1/instant/message"
|
||||||
|
)
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ func ExtractFromRequest(r *http.Request, reqItem interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InvalidJson(err error) string {
|
||||||
|
return fmt.Sprintf("Invalid JSON: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to send JSON responses
|
// Helper function to send JSON responses
|
||||||
|
// TODO: Change type of data to any
|
||||||
func RespondWithJSON(w http.ResponseWriter, statusCode int, data interface{}) {
|
func RespondWithJSON(w http.ResponseWriter, statusCode int, data interface{}) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(statusCode)
|
w.WriteHeader(statusCode)
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/config"
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetApp() (*app.App, error) {
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
|
envPath := path.Join(cwd, ".env")
|
||||||
|
|
||||||
|
err := godotenv.Load(envPath)
|
||||||
|
if err != nil {
|
||||||
|
envPath = path.Join(cwd, "../..", ".env")
|
||||||
|
if err := godotenv.Load(envPath); err != nil {
|
||||||
|
panic("Error loading .env file: " + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if tCfg, err := config.TwilioConfig(); err != nil {
|
||||||
|
return nil, fmt.Errorf("Error: %v", err)
|
||||||
|
} else {
|
||||||
|
return &app.App{TwilioConfig: tCfg}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResetTestDB(t *testing.T, tableName string) {
|
||||||
|
t.Helper()
|
||||||
|
_, err := db.Pool.Exec(context.Background(), fmt.Sprintf("DELETE FROM %s", tableName))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to reset test database: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ContactTest(id uuid.UUID, userId uuid.UUID) contact.Contact {
|
||||||
|
if id == uuid.Nil {
|
||||||
|
id = uuid.New()
|
||||||
|
return contact.Contact{Id: &id, PhoneNumber: "+10123456789", UserId: &userId}
|
||||||
|
} else {
|
||||||
|
return contact.Contact{Id: &id, PhoneNumber: "+10123456789", UserId: &userId}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MessageTest(id uuid.UUID, userId uuid.UUID) message.Message {
|
||||||
|
if id == uuid.Nil {
|
||||||
|
id = uuid.New()
|
||||||
|
return message.Message{Id: &id, Content: "Oh how the mighty have fallen", UserId: &userId}
|
||||||
|
} else {
|
||||||
|
return message.Message{Id: &id, Content: "Oh how the mighty have fallen", UserId: &userId}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ScheduledMessageTest(id uuid.UUID, userId uuid.UUID, now time.Time) scheduling.ScheduledMessage {
|
||||||
|
if id == uuid.Nil {
|
||||||
|
return scheduling.ScheduledMessage{Id: uuid.New(), UserId: userId, Scheduled: now.Add(20 * time.Minute), Status: scheduling.Pending}
|
||||||
|
} else {
|
||||||
|
return scheduling.ScheduledMessage{Id: id, UserId: userId, Scheduled: now.Add(20 * time.Minute), Status: scheduling.Pending}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ScheduledMessageEventTest(messageId, contactId, scheduledMessageId uuid.UUID) scheduling.ScheduledMessageEvent {
|
||||||
|
return scheduling.ScheduledMessageEvent{MessageId: messageId, ContactId: contactId, ScheduledMessageId: scheduledMessageId}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MERResponseInString() string {
|
||||||
|
return `{
|
||||||
|
"body": "Whoknows?",
|
||||||
|
"num_segments": "0",
|
||||||
|
"direction": "outbound-api",
|
||||||
|
"from": "+12243026041",
|
||||||
|
"to": "+16303831708",
|
||||||
|
"date_updated": "Sat,29Nov202519:06:59+0000",
|
||||||
|
"uri": "/2010-04-01/Accounts/ACefa1ef516314c9d1a68cbd657de49277/Messages/SM1193a529e7f7a840667cd1e0f13ea95a.json",
|
||||||
|
"account_sid": "ACefa1ef516314c9d1a68cbd657de49277",
|
||||||
|
"num_media": "0",
|
||||||
|
"status": "scheduled",
|
||||||
|
"messaging_service_sid": "MG803f3676706b92eb02e18dd820c447f2",
|
||||||
|
"sid": "SM1193a529e7f7a840667cd1e0f13ea95a",
|
||||||
|
"date_created": "Sat,29Nov202519:06:59+0000",
|
||||||
|
"api_version": "2010-04-01",
|
||||||
|
"subresource_uris": {
|
||||||
|
"media": "/2010-04-01/Accounts/ACefa1ef516314c9d1a68cbd657de49277/Messages/SM1193a529e7f7a840667cd1e0f13ea95a/Media.json"
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertStringToMapOfAny(response string) (map[string]any, error) {
|
||||||
|
bytes := []byte(response)
|
||||||
|
var merResponse map[string]any
|
||||||
|
err := json.Unmarshal(bytes, &merResponse)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return merResponse, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/swoosh/swoop/send"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Contact_Limit = 400
|
||||||
|
|
||||||
|
type SendInstantMessageHandler struct {
|
||||||
|
App *app.App
|
||||||
|
MERStore store.MessageEventResponseStore
|
||||||
|
ContactStore store.ContactStore
|
||||||
|
MessageStore store.MessageStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSendInstantMessageHandler(apiApp *app.App, str store.MessageEventResponseStore, cStore store.ContactStore, mStore store.MessageStore) *SendInstantMessageHandler {
|
||||||
|
return &SendInstantMessageHandler{App: apiApp, MERStore: str, ContactStore: cStore, MessageStore: mStore}
|
||||||
|
}
|
||||||
|
|
||||||
|
type SendInstantMessageRequest struct {
|
||||||
|
ContactIds []uuid.UUID `json:"contact_ids"`
|
||||||
|
MessageId uuid.UUID `json:"message_id"`
|
||||||
|
UserId uuid.UUID `json:"user_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SendInstantMessageResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []*event.MessageEventResponse `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sent godoc
|
||||||
|
// @Summary Send instant message
|
||||||
|
// @Description Send a message without the constraints of scheduled messages (requires JWT)
|
||||||
|
// @Tags messages
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param request body SendInstantMessageRequest true "Send an instnt message"
|
||||||
|
// @Success 201 {object} SendInstantMessageResponse
|
||||||
|
// @Failure 400 {object} SendInstantMessageResponse
|
||||||
|
// @Failure 500 {object} SendInstantMessageResponse
|
||||||
|
// @Router /instant/message [post]
|
||||||
|
func (s *SendInstantMessageHandler) Send(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req SendInstantMessageRequest
|
||||||
|
if err := ExtractFromRequest(r, &req); err != nil {
|
||||||
|
http.Error(w, InvalidJson(err), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
var statusCode int
|
||||||
|
var resp SendInstantMessageResponse
|
||||||
|
|
||||||
|
if req.UserId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "User Id is nil"
|
||||||
|
} else if req.MessageId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Message Id is nil"
|
||||||
|
} else if len(req.ContactIds) == 0 {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "No contacts provided"
|
||||||
|
} else {
|
||||||
|
if len(req.ContactIds) > Contact_Limit {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Too many contacts"
|
||||||
|
} else {
|
||||||
|
ctx := r.Context()
|
||||||
|
if msg, contacts, err := s.verify(ctx, &req); err != nil {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
if msg == nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Message is empty"
|
||||||
|
} else if len(contacts) == 0 {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Contacts not found"
|
||||||
|
} else {
|
||||||
|
if s.App != nil {
|
||||||
|
msgSender := send.MessageSender{Config: s.App.TwilioConfig}
|
||||||
|
for _, c := range contacts {
|
||||||
|
if twilioResp, twilioRespObject, err := msgSender.Send(*msg, *c, nil); err != nil {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
dateStr := strings.TrimSpace(*twilioResp.DateUpdated)
|
||||||
|
if parsedTime, err := time.Parse(time.RFC1123Z, dateStr); err != nil {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
mer := event.MessageEventResponse{}
|
||||||
|
mer.Response = twilioRespObject
|
||||||
|
mer.UserId = req.UserId
|
||||||
|
mer.Sent = parsedTime
|
||||||
|
mer.Status = event.Message_Event_Response_Status_Instant
|
||||||
|
mer.ContactId = c.Id
|
||||||
|
mer.MessageId = msg.Id
|
||||||
|
if err := s.MERStore.Create(ctx, &mer); err != nil {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
statusCode = http.StatusOK
|
||||||
|
resp.Message = "Successful"
|
||||||
|
resp.Data = append(resp.Data, &mer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = "Config not properly configured"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SendInstantMessageHandler) verify(ctx context.Context, req *SendInstantMessageRequest) (*message.Message, []*contact.Contact, error) {
|
||||||
|
if msg, err := s.verifyMessage(ctx, req.MessageId); err != nil {
|
||||||
|
log.Println("Huh?")
|
||||||
|
return nil, nil, fmt.Errorf("Error:%v", err)
|
||||||
|
} else {
|
||||||
|
log.Println("Okay")
|
||||||
|
if msg != nil {
|
||||||
|
if contacts, err := s.verifyContacts(ctx, req.ContactIds); err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("Error:%v", err)
|
||||||
|
} else {
|
||||||
|
if len(contacts) == 0 {
|
||||||
|
return msg, nil, nil
|
||||||
|
} else {
|
||||||
|
return msg, contacts, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Println("How can this be?")
|
||||||
|
return nil, nil, fmt.Errorf("Could not verify message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SendInstantMessageHandler) verifyMessage(ctx context.Context, messageId uuid.UUID) (*message.Message, error) {
|
||||||
|
if msg, err := s.MessageStore.GetMessageByID(ctx, messageId); err != nil {
|
||||||
|
return nil, fmt.Errorf("Error getting message:%v", err)
|
||||||
|
} else {
|
||||||
|
if msg == nil {
|
||||||
|
log.Println("Message is nil")
|
||||||
|
return nil, nil
|
||||||
|
} else {
|
||||||
|
return msg, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SendInstantMessageHandler) verifyContacts(ctx context.Context, contactIds []uuid.UUID) ([]*contact.Contact, error) {
|
||||||
|
var contacts []*contact.Contact
|
||||||
|
|
||||||
|
for _, contactId := range contactIds {
|
||||||
|
if c, err := s.ContactStore.GetContactByID(ctx, contactId); err != nil {
|
||||||
|
return nil, fmt.Errorf("Error getting contacts:%v", err)
|
||||||
|
} else {
|
||||||
|
if c != nil {
|
||||||
|
contacts = append(contacts, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(contacts) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
} else {
|
||||||
|
return contacts, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
-35
@@ -2,14 +2,27 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type MessageHandler struct {
|
||||||
|
App *app.App
|
||||||
|
MessageStore store.MessageStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMessageHandler(apiApp *app.App, str store.MessageStore) *MessageHandler {
|
||||||
|
return &MessageHandler{App: apiApp, MessageStore: str}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Message_Limit = 200
|
||||||
|
|
||||||
type RequestAddMessage struct {
|
type RequestAddMessage struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
UserId uuid.UUID `json:"user_id"`
|
UserId uuid.UUID `json:"user_id"`
|
||||||
@@ -20,25 +33,19 @@ type AddMessageResponse struct {
|
|||||||
Data []message.Message `json:"data"`
|
Data []message.Message `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetMessageResponse struct {
|
// AddMessage godoc
|
||||||
Message string `json:"message"`
|
// @Summary Add message
|
||||||
Data []message.Message `json:"data"`
|
// @Description Add a message record to send a text to (requires JWT)
|
||||||
}
|
// @Tags messages
|
||||||
|
// @Accept json
|
||||||
type MessageHandler struct {
|
// @Produce json
|
||||||
MessageStore store.MessageStore
|
// @Security BearerAuth
|
||||||
}
|
// @Param request body RequestAddMessage true "Data to add message"
|
||||||
|
// @Success 201 {object} AddMessageResponse
|
||||||
func NewMessageHandler(str store.MessageStore) *MessageHandler {
|
// @Failure 400 {object} AddMessageResponse
|
||||||
return &MessageHandler{MessageStore: str}
|
// @Failure 500 {object} AddMessageResponse
|
||||||
}
|
// @Router /message/new [post]
|
||||||
|
|
||||||
func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
|
func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req RequestAddMessage
|
var req RequestAddMessage
|
||||||
if err := ExtractFromRequest(r, &req); err != nil {
|
if err := ExtractFromRequest(r, &req); err != nil {
|
||||||
http.Error(w, "Invalid JSON: "+err.Error(), http.StatusBadRequest)
|
http.Error(w, "Invalid JSON: "+err.Error(), http.StatusBadRequest)
|
||||||
@@ -47,23 +54,54 @@ func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var statusCode int
|
var statusCode int
|
||||||
var resp AddMessageResponse
|
var resp AddMessageResponse
|
||||||
newMessage := message.Message{Content: req.Content, UserId: req.UserId}
|
newMessage := message.Message{Content: req.Content, UserId: &req.UserId}
|
||||||
|
|
||||||
ctx := r.Context()
|
if isMessageValid(&newMessage) {
|
||||||
|
ctx := r.Context()
|
||||||
|
|
||||||
if err := m.MessageStore.CreateMessage(ctx, &newMessage); err != nil {
|
if err := m.MessageStore.CreateMessage(ctx, &newMessage); err != nil {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
statusCode = http.StatusInternalServerError
|
statusCode = http.StatusInternalServerError
|
||||||
resp.Message = err.Error()
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
statusCode = http.StatusCreated
|
||||||
|
resp.Message = "Message created"
|
||||||
|
resp.Data = append(resp.Data, newMessage)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
statusCode = http.StatusCreated
|
statusCode = http.StatusBadRequest
|
||||||
resp.Message = "Message created"
|
resp.Message = fmt.Sprintf("Message length exceeds maximum limit. Current size: %d Limit: %d", len(newMessage.Content), Message_Limit)
|
||||||
resp.Data = append(resp.Data, newMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isMessageValid(msg *message.Message) bool {
|
||||||
|
if len(msg.Content) <= Message_Limit {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetMessageResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []message.Message `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMessage godoc
|
||||||
|
// @Summary Get message
|
||||||
|
// @Description Get a message record to have a recipient to send a text to (requires JWT)
|
||||||
|
// @Tags messages
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Message Id"
|
||||||
|
// @Param user_id path string true "User Id"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Success 200 {object} GetMessageResponse
|
||||||
|
// @Failure 400 {object} GetMessageResponse
|
||||||
|
// @Failure 500 {object} GetMessageResponse
|
||||||
|
// @Router /message [get]
|
||||||
func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
|
func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
@@ -103,7 +141,7 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
if id != uuid.Nil {
|
if id != uuid.Nil {
|
||||||
fmt.Println("Checking with Id")
|
log.Println("Checking with Id")
|
||||||
if con, err := c.MessageStore.GetMessageByID(ctx, id); err == nil {
|
if con, err := c.MessageStore.GetMessageByID(ctx, id); err == nil {
|
||||||
statusCode = http.StatusOK
|
statusCode = http.StatusOK
|
||||||
resp.Message = "Successful"
|
resp.Message = "Successful"
|
||||||
@@ -113,11 +151,12 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp.Message = err.Error()
|
resp.Message = err.Error()
|
||||||
}
|
}
|
||||||
} else if userId != uuid.Nil {
|
} else if userId != uuid.Nil {
|
||||||
fmt.Println("Checking with User Id")
|
log.Println("Checking with User Id")
|
||||||
if contacts, err := c.MessageStore.GetAllMessages(ctx); err == nil {
|
if messages, err := c.MessageStore.GetAllMessages(ctx); err == nil {
|
||||||
for _, con := range contacts {
|
log.Println("Amount of messages:", len(messages))
|
||||||
if con.UserId == userId {
|
for _, msg := range messages {
|
||||||
resp.Data = append(resp.Data, *con)
|
if *msg.UserId == userId {
|
||||||
|
resp.Data = append(resp.Data, *msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +165,7 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp.Message = "Successful"
|
resp.Message = "Successful"
|
||||||
} else {
|
} else {
|
||||||
statusCode = http.StatusNotFound
|
statusCode = http.StatusNotFound
|
||||||
resp.Message = "Contact not found"
|
resp.Message = "Message not found"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
statusCode = http.StatusInternalServerError
|
statusCode = http.StatusInternalServerError
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EventResponseHandler struct {
|
||||||
|
App *app.App
|
||||||
|
MessageEventResponseStore store.MessageEventResponseStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEventResponseHandler(apiApp *app.App, str store.MessageEventResponseStore) *EventResponseHandler {
|
||||||
|
return &EventResponseHandler{App: apiApp, MessageEventResponseStore: str}
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecordEventRequest struct {
|
||||||
|
ScheduledMessageEventId uuid.UUID `json:"scheduled_message_event_id"`
|
||||||
|
Response map[string]any `json:"response"`
|
||||||
|
UserId uuid.UUID `json:"user_id"`
|
||||||
|
Sent *time.Time `json:"sent,omitempty"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
ContactId *uuid.UUID `json:"contact_id"`
|
||||||
|
MessageId *uuid.UUID `json:"message_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecordEventResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []*event.MessageEventResponse `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecordMessageEventResponse godoc
|
||||||
|
// @Summary Record MessageEventResponse
|
||||||
|
// @Description Saves the result of sending a text message (requires JWT)
|
||||||
|
// @Tags message
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param request body RecordEventRequest true "Data to add MessageEventResponse"
|
||||||
|
// @Success 201 {object} RecordEventResponse
|
||||||
|
// @Failure 400 {object} RecordEventResponse
|
||||||
|
// @Failure 500 {object} RecordEventResponse
|
||||||
|
// @Router /schedule/message/event/response/record [post]
|
||||||
|
func (e *EventResponseHandler) RecordResponse(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req RecordEventRequest
|
||||||
|
if err := ExtractFromRequest(r, &req); err != nil {
|
||||||
|
http.Error(w, "Invalid JSON: "+err.Error(), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
var statusCode int
|
||||||
|
var rp event.MessageEventResponse
|
||||||
|
var resp RecordEventResponse
|
||||||
|
|
||||||
|
if req.Sent == nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Sent time is empty"
|
||||||
|
} else if req.UserId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "User Id is empty"
|
||||||
|
} else if len(req.Response) == 0 {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Response is empty"
|
||||||
|
} else if req.ScheduledMessageEventId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Scheduled message event Id is empty"
|
||||||
|
} else {
|
||||||
|
log.Println("Starting process to record Message Event Response")
|
||||||
|
rp.ScheduledMessageEventId = req.ScheduledMessageEventId
|
||||||
|
rp.Response = req.Response
|
||||||
|
rp.UserId = req.UserId
|
||||||
|
rp.Sent = *req.Sent
|
||||||
|
|
||||||
|
switch req.Status {
|
||||||
|
case event.Message_Event_Response_Status_Instant:
|
||||||
|
{
|
||||||
|
log.Println("Status:", req.Status)
|
||||||
|
rp.Status = req.Status
|
||||||
|
rp.MessageId = req.MessageId
|
||||||
|
rp.ContactId = req.ContactId
|
||||||
|
}
|
||||||
|
case event.Message_Event_Response_Status_Scheduled:
|
||||||
|
{
|
||||||
|
log.Println("Status:", req.Status)
|
||||||
|
rp.Status = req.Status
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "Status is invalid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := r.Context()
|
||||||
|
if err := e.MessageEventResponseStore.Create(ctx, &rp); err != nil {
|
||||||
|
log.Println("Error:", err)
|
||||||
|
resp.Message = err.Error()
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
} else {
|
||||||
|
log.Println("Created Message Event Response")
|
||||||
|
statusCode = http.StatusCreated
|
||||||
|
resp.Message = "Successful"
|
||||||
|
resp.Data = append(resp.Data, &rp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetMessageEventResponseFetchedResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []*event.MessageEventResponse `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FetchtMessageEventResponse godoc
|
||||||
|
// @Summary Fetcht MessageEventResponse
|
||||||
|
// @Description Fetches a MessageEventResponse given a user id (requires JWT)
|
||||||
|
// @Tags message
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param user_id path string true "User Id"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Success 200 {object} GetMessageEventResponseFetchedResponse
|
||||||
|
// @Failure 400 {object} GetMessageEventResponseFetchedResponse
|
||||||
|
// @Failure 500 {object} GetMessageEventResponseFetchedResponse
|
||||||
|
// @Router /schedule/message/event/response [get]
|
||||||
|
func (e *EventResponseHandler) Fetch(w http.ResponseWriter, r *http.Request) {
|
||||||
|
queryParams := r.URL.Query()
|
||||||
|
var userId uuid.UUID
|
||||||
|
|
||||||
|
if _, exists := queryParams["user_id"]; !exists {
|
||||||
|
http.Error(w, "Query params", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
userId, err = uuid.Parse(queryParams.Get("user_id"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Query params", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var statusCode int
|
||||||
|
var resp GetMessageEventResponseFetchedResponse
|
||||||
|
|
||||||
|
if userId == uuid.Nil {
|
||||||
|
statusCode = http.StatusBadRequest
|
||||||
|
resp.Message = "User Id is nil"
|
||||||
|
} else {
|
||||||
|
ctx := r.Context()
|
||||||
|
if sentMessages, err := e.MessageEventResponseStore.GetWithUserId(ctx, userId); err != nil {
|
||||||
|
statusCode = http.StatusInternalServerError
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
if len(sentMessages) == 0 {
|
||||||
|
statusCode = http.StatusNotFound
|
||||||
|
resp.Message = "Not MessageEventResponses found"
|
||||||
|
} else {
|
||||||
|
statusCode = http.StatusOK
|
||||||
|
resp.Message = "Successful"
|
||||||
|
resp.Data = sentMessages
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
evnt "git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/handler/endpoint"
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/store/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRecordMessageEventResponseWithMock(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
mockStore := mock.NewMockScheduledMessageEventStore()
|
||||||
|
contactStore := mock.NewMockContactStore()
|
||||||
|
messageStore := mock.NewMockMessageStore()
|
||||||
|
schMsgStore := mock.NewMockScheduledMessageStore()
|
||||||
|
merStore := mock.NewMockMessageEventResponseStore()
|
||||||
|
|
||||||
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewEventResponseHandler(apiApp, merStore)
|
||||||
|
|
||||||
|
contactId := uuid.New()
|
||||||
|
messageId := uuid.New()
|
||||||
|
scheduledMessageId := uuid.New()
|
||||||
|
testUserId := uuid.New()
|
||||||
|
|
||||||
|
con := ContactTest(contactId, testUserId)
|
||||||
|
msg := MessageTest(messageId, testUserId)
|
||||||
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
|
event := scheduling.ScheduledMessageEvent{}
|
||||||
|
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
|
if err := contactStore.CreateContact(ctx, &con); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating contact: %v", err)
|
||||||
|
} else if err = messageStore.CreateMessage(ctx, &msg); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating message: %v", err)
|
||||||
|
} else if err = schMsgStore.CreateScheduledMessage(ctx, &schMsg); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating scheduled message: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
event.MessageId = *msg.Id
|
||||||
|
event.ContactId = *con.Id
|
||||||
|
event.ScheduledMessageId = schMsg.Id
|
||||||
|
if err := mockStore.CreateScheduledMessageEvent(ctx, &event); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating scheduled message event: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sent := now.Add(30 * time.Minute)
|
||||||
|
var merResponse map[string]any
|
||||||
|
merResponse, err = ConvertStringToMapOfAny(MERResponseInString())
|
||||||
|
assert.NoError(t, err, "Error Converting to map[string]any")
|
||||||
|
|
||||||
|
testReq := RecordEventRequest{ScheduledMessageEventId: event.Id, Response: merResponse, UserId: schMsg.UserId, Sent: &sent, Status: evnt.Message_Event_Response_Status_Scheduled}
|
||||||
|
jsonValue, _ := json.Marshal(testReq)
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("POST", endpoint.RecordEventResponse, strings.NewReader(string(jsonValue)))
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler.RecordResponse(rr, req)
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusCreated, rr.Code)
|
||||||
|
|
||||||
|
var response RecordEventResponse
|
||||||
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
|
assert.NoError(t, err, "Error parsing message event response:%v", err)
|
||||||
|
|
||||||
|
assert.NotEmpty(t, response.Data, "No message event response created")
|
||||||
|
|
||||||
|
var msgEventResp evnt.MessageEventResponse
|
||||||
|
msgEventResp = *response.Data[0]
|
||||||
|
|
||||||
|
assert.NotEmpty(t, msgEventResp.Response, "The response of the message event response is empty")
|
||||||
|
assert.Equal(t, msgEventResp.Response, testReq.Response, "Responses do not match")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetMessageEventResponse(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
mockStore := mock.NewMockScheduledMessageEventStore()
|
||||||
|
contactStore := mock.NewMockContactStore()
|
||||||
|
messageStore := mock.NewMockMessageStore()
|
||||||
|
schMsgStore := mock.NewMockScheduledMessageStore()
|
||||||
|
merStore := mock.NewMockMessageEventResponseStore()
|
||||||
|
|
||||||
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewEventResponseHandler(apiApp, merStore)
|
||||||
|
|
||||||
|
contactId := uuid.New()
|
||||||
|
messageId := uuid.New()
|
||||||
|
scheduledMessageId := uuid.New()
|
||||||
|
testUserId := uuid.New()
|
||||||
|
|
||||||
|
con := ContactTest(contactId, testUserId)
|
||||||
|
msg := MessageTest(messageId, testUserId)
|
||||||
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
|
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
|
if err := contactStore.CreateContact(ctx, &con); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating contact: %v", err)
|
||||||
|
} else if err = messageStore.CreateMessage(ctx, &msg); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating message: %v", err)
|
||||||
|
} else if err = schMsgStore.CreateScheduledMessage(ctx, &schMsg); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating scheduled message: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
event := scheduling.ScheduledMessageEvent{}
|
||||||
|
event.MessageId = *msg.Id
|
||||||
|
event.ContactId = *con.Id
|
||||||
|
event.ScheduledMessageId = schMsg.Id
|
||||||
|
sent := now.Add(30 * time.Minute)
|
||||||
|
if err := mockStore.CreateScheduledMessageEvent(ctx, &event); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating scheduled message event: %v", err)
|
||||||
|
} else {
|
||||||
|
m := evnt.MessageEventResponse{}
|
||||||
|
m.ScheduledMessageEventId = event.Id
|
||||||
|
m.UserId = schMsg.UserId
|
||||||
|
m.Status = evnt.Message_Event_Response_Status_Scheduled
|
||||||
|
m.Sent = sent
|
||||||
|
var merResponse map[string]any
|
||||||
|
merResponse, err = ConvertStringToMapOfAny(MERResponseInString())
|
||||||
|
assert.NoError(t, err, "Error Converting to map[string]any")
|
||||||
|
m.Response = merResponse
|
||||||
|
|
||||||
|
if err := merStore.Create(ctx, &m); err != nil {
|
||||||
|
assert.NoError(t, err, "Error creating MessageEventResponse: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s?user_id=%s", endpoint.FetchMessageEventResponse, testUserId)
|
||||||
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler.Fetch(rr, req)
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
|
var response GetMessageEventResponseFetchedResponse
|
||||||
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
|
assert.NoError(t, err, "Error parsing message event response: %v", err)
|
||||||
|
|
||||||
|
assert.NotEmpty(t, response.Data, "No message event response found")
|
||||||
|
|
||||||
|
var msgEventResp evnt.MessageEventResponse
|
||||||
|
msgEventResp = *response.Data[0]
|
||||||
|
|
||||||
|
assert.NotEmpty(t, msgEventResp.Response, "The response of the message event response is empty")
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@@ -16,17 +16,14 @@ import (
|
|||||||
"git.kundeng.us/phoenix/textsender-api/internal/store/mock"
|
"git.kundeng.us/phoenix/textsender-api/internal/store/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateMessageRequest struct {
|
|
||||||
Content string `json:"content"`
|
|
||||||
UserId uuid.UUID `json:"user_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateMessageWithMock(t *testing.T) {
|
func TestCreateMessageWithMock(t *testing.T) {
|
||||||
mockStore := mock.NewMockMessageStore()
|
mockStore := mock.NewMockMessageStore()
|
||||||
handler := NewMessageHandler(mockStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewMessageHandler(apiApp, mockStore)
|
||||||
|
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
testBody := CreateMessageRequest{Content: "Who could tell?", UserId: testUserId}
|
testBody := RequestAddMessage{Content: "Who could tell?", UserId: testUserId}
|
||||||
jsonValue, _ := json.Marshal(testBody)
|
jsonValue, _ := json.Marshal(testBody)
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", endpoint.ADD_MESSAGE, strings.NewReader(string(jsonValue)))
|
req, _ := http.NewRequest("POST", endpoint.ADD_MESSAGE, strings.NewReader(string(jsonValue)))
|
||||||
@@ -37,7 +34,7 @@ func TestCreateMessageWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusCreated, rr.Code)
|
assert.Equal(t, http.StatusCreated, rr.Code)
|
||||||
|
|
||||||
var response AddMessageResponse
|
var response AddMessageResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error Creating message %v", err)
|
assert.NoError(t, err, "Error Creating message %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No Message created")
|
assert.NotEmpty(t, response.Data, "No Message created")
|
||||||
@@ -49,7 +46,7 @@ func TestGetMessageWithMock(t *testing.T) {
|
|||||||
mockstore := mock.NewMockMessageStore()
|
mockstore := mock.NewMockMessageStore()
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
|
|
||||||
testCon := message.Message{Content: "Who is the one that benefits?", UserId: testUserId}
|
testCon := message.Message{Content: "Who is the one that benefits?", UserId: &testUserId}
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
if err := mockstore.CreateMessage(ctx, &testCon); err != nil {
|
if err := mockstore.CreateMessage(ctx, &testCon); err != nil {
|
||||||
assert.NoError(t, err, "Error creating message")
|
assert.NoError(t, err, "Error creating message")
|
||||||
@@ -60,13 +57,15 @@ func TestGetMessageWithMock(t *testing.T) {
|
|||||||
req, _ := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
messageHandler := NewMessageHandler(mockstore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
messageHandler := NewMessageHandler(apiApp, mockstore)
|
||||||
messageHandler.GetMessage(rr, req)
|
messageHandler.GetMessage(rr, req)
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response GetMessageResponse
|
var response GetMessageResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error getting message %v", err)
|
assert.NoError(t, err, "Error getting message %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No Message retrieved")
|
assert.NotEmpty(t, response.Data, "No Message retrieved")
|
||||||
|
|||||||
@@ -3,12 +3,23 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ScheduledMessageStatusHandler struct {
|
||||||
|
App *app.App
|
||||||
|
ScheduledMessageEventStore store.ScheduledMessageEventStore
|
||||||
|
ScheduledMessageStore store.ScheduledMessageStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScheduledMessageStatusHandler(apiApp *app.App, str store.ScheduledMessageEventStore, schStore store.ScheduledMessageStore) *ScheduledMessageStatusHandler {
|
||||||
|
return &ScheduledMessageStatusHandler{App: apiApp, ScheduledMessageEventStore: str, ScheduledMessageStore: schStore}
|
||||||
|
}
|
||||||
|
|
||||||
type RequestScheduledMessageStatus struct {
|
type RequestScheduledMessageStatus struct {
|
||||||
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
|
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
@@ -24,15 +35,19 @@ type ScheduledMessageStatusResponse struct {
|
|||||||
Data []ScheduledMessageChange `json:"data"`
|
Data []ScheduledMessageChange `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScheduledMessageStatusHandler struct {
|
// UpdateStatus godoc
|
||||||
ScheduledMessageEventStore store.ScheduledMessageEventStore
|
// @Summary Update status
|
||||||
ScheduledMessageStore store.ScheduledMessageStore
|
// @Description Update the status of a scheduled message (requires JWT)
|
||||||
}
|
// @Tags status
|
||||||
|
// @Accept json
|
||||||
func NewScheduledMessageStatusHandler(str store.ScheduledMessageEventStore, schStore store.ScheduledMessageStore) *ScheduledMessageStatusHandler {
|
// @Produce json
|
||||||
return &ScheduledMessageStatusHandler{ScheduledMessageEventStore: str, ScheduledMessageStore: schStore}
|
// @Security BearerAuth
|
||||||
}
|
// @Param request body RequestScheduledMessageStatus true "Used to update scheduled message status"
|
||||||
|
// @Success 201 {object} ScheduledMessageStatusResponse
|
||||||
|
// @Failure 400 {object} ScheduledMessageStatusResponse
|
||||||
|
// @Failure 404 {object} ScheduledMessageStatusResponse
|
||||||
|
// @Failure 500 {object} ScheduledMessageStatusResponse
|
||||||
|
// @Router /schedule/message/status/update [patch]
|
||||||
func (s *ScheduledMessageStatusHandler) UpdateStatus(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageStatusHandler) UpdateStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPatch {
|
if r.Method != http.MethodPatch {
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@@ -24,15 +24,15 @@ func TestUpdateScheduledMessageStatusWithMock(t *testing.T) {
|
|||||||
messageStore := mock.NewMockMessageStore()
|
messageStore := mock.NewMockMessageStore()
|
||||||
schMsgStore := mock.NewMockScheduledMessageStore()
|
schMsgStore := mock.NewMockScheduledMessageStore()
|
||||||
|
|
||||||
recipientId := uuid.New()
|
contactId := uuid.New()
|
||||||
messageId := uuid.New()
|
messageId := uuid.New()
|
||||||
scheduledMessageId := uuid.New()
|
scheduledMessageId := uuid.New()
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
|
|
||||||
con := testContact(recipientId, testUserId)
|
con := ContactTest(contactId, testUserId)
|
||||||
msg := testMessage(messageId, testUserId)
|
msg := MessageTest(messageId, testUserId)
|
||||||
schMsg := testScheduledMessage(scheduledMessageId, testUserId, now)
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
event := testScheduledMessageEvent(msg.Id, con.Id, schMsg.Id)
|
event := ScheduledMessageEventTest(*msg.Id, *con.Id, schMsg.Id)
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
@@ -55,13 +55,15 @@ func TestUpdateScheduledMessageStatusWithMock(t *testing.T) {
|
|||||||
req, _ := http.NewRequest("PATCH", endpoint.UpdateScheduledMessageStatusEndpoint, jsonBody)
|
req, _ := http.NewRequest("PATCH", endpoint.UpdateScheduledMessageStatusEndpoint, jsonBody)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewScheduledMessageStatusHandler(schMsgEventStore, schMsgStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageStatusHandler(apiApp, schMsgEventStore, schMsgStore)
|
||||||
handler.UpdateStatus(rr, req)
|
handler.UpdateStatus(rr, req)
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response ScheduledMessageStatusResponse
|
var response ScheduledMessageStatusResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error creating event %v", err)
|
assert.NoError(t, err, "Error creating event %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "Data should not be empty")
|
assert.NotEmpty(t, response.Data, "Data should not be empty")
|
||||||
|
|||||||
@@ -6,15 +6,24 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ScheduledMessageHandler struct {
|
||||||
|
App *app.App
|
||||||
|
ScheduledMessageStore store.ScheduledMessageStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScheduledMessageHandler(apiApp *app.App, str store.ScheduledMessageStore) *ScheduledMessageHandler {
|
||||||
|
return &ScheduledMessageHandler{App: apiApp, ScheduledMessageStore: str}
|
||||||
|
}
|
||||||
|
|
||||||
type RequestAddScheduledMessage struct {
|
type RequestAddScheduledMessage struct {
|
||||||
Scheduled time.Time `json:"scheduled"`
|
Scheduled time.Time `json:"scheduled"`
|
||||||
Created time.Time `json:"created"`
|
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UserId uuid.UUID `json:"user_id"`
|
UserId uuid.UUID `json:"user_id"`
|
||||||
}
|
}
|
||||||
@@ -24,24 +33,18 @@ type AddScheduledMessageResponse struct {
|
|||||||
Data []scheduling.ScheduledMessage `json:"data"`
|
Data []scheduling.ScheduledMessage `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetScheduledMessageResponse struct {
|
// AddScheduledMessage godoc
|
||||||
Message string `json:"message"`
|
// @Summary Add scheduled message
|
||||||
Data []scheduling.ScheduledMessage `json:"data"`
|
// @Description Adds a scheduled message (requires JWT)
|
||||||
}
|
// @Tags scheduled messages
|
||||||
|
// @Accept json
|
||||||
type FetchNextMessageResponse struct {
|
// @Produce json
|
||||||
Message string `json:"message"`
|
// @Security BearerAuth
|
||||||
Data []scheduling.ScheduledMessage `json:"data"`
|
// @Param request body RequestAddScheduledMessage true "Data to add scheduled message"
|
||||||
}
|
// @Success 201 {object} AddScheduledMessageResponse
|
||||||
|
// @Failure 400 {object} AddScheduledMessageResponse
|
||||||
type ScheduledMessageHandler struct {
|
// @Failure 500 {object} AddScheduledMessageResponse
|
||||||
ScheduledMessageStore store.ScheduledMessageStore
|
// @Router /schedule/message [post]
|
||||||
}
|
|
||||||
|
|
||||||
func NewScheduledMessageHandler(str store.ScheduledMessageStore) *ScheduledMessageHandler {
|
|
||||||
return &ScheduledMessageHandler{ScheduledMessageStore: str}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ScheduledMessageHandler) AddScheduledMessage(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageHandler) AddScheduledMessage(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
@@ -93,6 +96,24 @@ func (s *ScheduledMessageHandler) AddScheduledMessage(w http.ResponseWriter, r *
|
|||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetScheduledMessageResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []scheduling.ScheduledMessage `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScheduledMessage godoc
|
||||||
|
// @Summary Get scheduled message
|
||||||
|
// @Description Get a scheduled message (requires JWT)
|
||||||
|
// @Tags scheduled messages
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param id path string true "Contact Id"
|
||||||
|
// @Param user_id path string true "User Id"
|
||||||
|
// @Success 200 {object} GetScheduledMessageResponse
|
||||||
|
// @Failure 400 {object} GetScheduledMessageResponse
|
||||||
|
// @Failure 500 {object} GetScheduledMessageResponse
|
||||||
|
// @Router /schedule/message [get]
|
||||||
func (s *ScheduledMessageHandler) GetScheduledMessage(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageHandler) GetScheduledMessage(w http.ResponseWriter, r *http.Request) {
|
||||||
var id, userId uuid.UUID
|
var id, userId uuid.UUID
|
||||||
|
|
||||||
@@ -157,6 +178,22 @@ func (s *ScheduledMessageHandler) GetScheduledMessage(w http.ResponseWriter, r *
|
|||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FetchNextMessageResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []scheduling.ScheduledMessage `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FetchNextMessage godoc
|
||||||
|
// @Summary Fetch scheduled message
|
||||||
|
// @Description Fetches a scheduled message that is available to be processed (requires JWT)
|
||||||
|
// @Tags scheduled messages
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Success 200 {object} FetchNextMessageResponse
|
||||||
|
// @Failure 400 {object} FetchNextMessageResponse
|
||||||
|
// @Failure 500 {object} FetchNextMessageResponse
|
||||||
|
// @Router /schedule/message/fetch [get]
|
||||||
func (s *ScheduledMessageHandler) FetchNextMessage(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageHandler) FetchNextMessage(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
var resp FetchNextMessageResponse
|
var resp FetchNextMessageResponse
|
||||||
|
|||||||
@@ -4,15 +4,26 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||||
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
"git.kundeng.us/phoenix/textsender-api/internal/store"
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ScheduledMessageEventHandler struct {
|
||||||
|
App *app.App
|
||||||
|
ScheduledMessageEventStore store.ScheduledMessageEventStore
|
||||||
|
ScheduledMessageStore store.ScheduledMessageStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScheduledMessageEventHandler(apiApp *app.App, str store.ScheduledMessageEventStore, schStore store.ScheduledMessageStore) *ScheduledMessageEventHandler {
|
||||||
|
return &ScheduledMessageEventHandler{App: apiApp, ScheduledMessageEventStore: str, ScheduledMessageStore: schStore}
|
||||||
|
}
|
||||||
|
|
||||||
type RequestAddScheduledMessageEvent struct {
|
type RequestAddScheduledMessageEvent struct {
|
||||||
RecipientId uuid.UUID `json:"recipient_id"`
|
ContactId uuid.UUID `json:"contact_id"`
|
||||||
MessageId uuid.UUID `json:"message_id"`
|
MessageId uuid.UUID `json:"message_id"`
|
||||||
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
|
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
|
||||||
}
|
}
|
||||||
@@ -22,25 +33,18 @@ type AddScheduledMessageEventResponse struct {
|
|||||||
Data []scheduling.ScheduledMessageEvent `json:"data"`
|
Data []scheduling.ScheduledMessageEvent `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetScheduledMessageEventResponse struct {
|
// AddScheduledMessageEvent godoc
|
||||||
Message string `json:"message"`
|
// @Summary Add scheduled message event
|
||||||
Data []scheduling.ScheduledMessageEvent `json:"data"`
|
// @Description Add a scheduled message event (requires JWT)
|
||||||
}
|
// @Tags scheduled message events
|
||||||
|
// @Accept json
|
||||||
type DeleteScheduledMessageEventResponse struct {
|
// @Produce json
|
||||||
Message string `json:"message"`
|
// @Security BearerAuth
|
||||||
Data []scheduling.ScheduledMessageEvent `json:"data"`
|
// @Param request body RequestAddScheduledMessageEvent true "Data to add scheduled message event"
|
||||||
}
|
// @Success 201 {object} AddScheduledMessageEventResponse
|
||||||
|
// @Failure 400 {object} AddScheduledMessageEventResponse
|
||||||
type ScheduledMessageEventHandler struct {
|
// @Failure 500 {object} AddScheduledMessageEventResponse
|
||||||
ScheduledMessageEventStore store.ScheduledMessageEventStore
|
// @Router /schedule/message/event [post]
|
||||||
ScheduledMessageStore store.ScheduledMessageStore
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewScheduledMessageEventHandler(str store.ScheduledMessageEventStore, schStore store.ScheduledMessageStore) *ScheduledMessageEventHandler {
|
|
||||||
return &ScheduledMessageEventHandler{ScheduledMessageEventStore: str, ScheduledMessageStore: schStore}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ScheduledMessageEventHandler) AddScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageEventHandler) AddScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
@@ -53,14 +57,14 @@ func (s *ScheduledMessageEventHandler) AddScheduledMessageEvent(w http.ResponseW
|
|||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
|
||||||
event := scheduling.ScheduledMessageEvent{RecipientId: req.RecipientId, MessageId: req.MessageId, ScheduledMessageId: req.ScheduledMessageId}
|
event := scheduling.ScheduledMessageEvent{ContactId: req.ContactId, MessageId: req.MessageId, ScheduledMessageId: req.ScheduledMessageId}
|
||||||
|
|
||||||
var statusCode int
|
var statusCode int
|
||||||
var resp AddScheduledMessageEventResponse
|
var resp AddScheduledMessageEventResponse
|
||||||
|
|
||||||
if event.RecipientId == uuid.Nil {
|
if event.ContactId == uuid.Nil {
|
||||||
statusCode = http.StatusBadRequest
|
statusCode = http.StatusBadRequest
|
||||||
resp.Message = "Recipient Id is nil"
|
resp.Message = "Contact Id is nil"
|
||||||
} else if event.MessageId == uuid.Nil {
|
} else if event.MessageId == uuid.Nil {
|
||||||
statusCode = http.StatusBadRequest
|
statusCode = http.StatusBadRequest
|
||||||
resp.Message = "Message Id is nil"
|
resp.Message = "Message Id is nil"
|
||||||
@@ -103,6 +107,24 @@ func (s *ScheduledMessageEventHandler) AddScheduledMessageEvent(w http.ResponseW
|
|||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetScheduledMessageEventResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []scheduling.ScheduledMessageEvent `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScheduledMessageEvent godoc
|
||||||
|
// @Summary Get scheduled message event
|
||||||
|
// @Description Gets a scheduled message event (requires JWT)
|
||||||
|
// @Tags scheduled message events
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Contact Id"
|
||||||
|
// @Param scheduled_message_id path string true "Scheduled Message Id"
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Success 200 {object} GetScheduledMessageEventResponse
|
||||||
|
// @Failure 400 {object} GetScheduledMessageEventResponse
|
||||||
|
// @Failure 500 {object} GetScheduledMessageEventResponse
|
||||||
|
// @Router /schedule/message/event [get]
|
||||||
func (s *ScheduledMessageEventHandler) GetScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageEventHandler) GetScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet {
|
||||||
http.Error(w, "Metnot allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Metnot allowed", http.StatusMethodNotAllowed)
|
||||||
@@ -154,6 +176,23 @@ func (s *ScheduledMessageEventHandler) GetScheduledMessageEvent(w http.ResponseW
|
|||||||
RespondWithJSON(w, statusCode, &resp)
|
RespondWithJSON(w, statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteScheduledMessageEventResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []scheduling.ScheduledMessageEvent `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteScheduledMessageEvent godoc
|
||||||
|
// @Summary Delete scheduled message event
|
||||||
|
// @Description Deletes a scheduled message event (requires JWT)
|
||||||
|
// @Tags scheduled message events
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param id path string true "scheduled message event Id" Format(uuid)
|
||||||
|
// @Success 201 {object} DeleteScheduledMessageEventResponse
|
||||||
|
// @Failure 400 {object} DeleteScheduledMessageEventResponse
|
||||||
|
// @Failure 500 {object} DeleteScheduledMessageEventResponse
|
||||||
|
// @Router /schedule/message/event/{id} [delete]
|
||||||
func (s *ScheduledMessageEventHandler) DeleteScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
|
func (s *ScheduledMessageEventHandler) DeleteScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodDelete {
|
if r.Method != http.MethodDelete {
|
||||||
http.Error(w, "Metnot allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Metnot allowed", http.StatusMethodNotAllowed)
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@@ -20,14 +18,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
recipientId = uuid.New()
|
contactId = uuid.New()
|
||||||
messageId = uuid.New()
|
messageId = uuid.New()
|
||||||
scheduledMessageId = uuid.New()
|
scheduledMessageId = uuid.New()
|
||||||
testUserId = uuid.New()
|
testUserId = uuid.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateScheduledMessageEventRequest struct {
|
type CreateScheduledMessageEventRequest struct {
|
||||||
RecipientId uuid.UUID `json:"recipient_id"`
|
ContactId uuid.UUID `json:"contact_id"`
|
||||||
MessageId uuid.UUID `json:"message_id"`
|
MessageId uuid.UUID `json:"message_id"`
|
||||||
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
|
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
|
||||||
}
|
}
|
||||||
@@ -40,16 +38,18 @@ func TestCreateScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
messageStore := mock.NewMockMessageStore()
|
messageStore := mock.NewMockMessageStore()
|
||||||
schMsgStore := mock.NewMockScheduledMessageStore()
|
schMsgStore := mock.NewMockScheduledMessageStore()
|
||||||
|
|
||||||
handler := NewScheduledMessageEventHandler(mockStore, schMsgStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageEventHandler(apiApp, mockStore, schMsgStore)
|
||||||
|
|
||||||
recipientId := uuid.New()
|
contactId := uuid.New()
|
||||||
messageId := uuid.New()
|
messageId := uuid.New()
|
||||||
scheduledMessageId := uuid.New()
|
scheduledMessageId := uuid.New()
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
|
|
||||||
con := testContact(recipientId, testUserId)
|
con := ContactTest(contactId, testUserId)
|
||||||
msg := testMessage(messageId, testUserId)
|
msg := MessageTest(messageId, testUserId)
|
||||||
schMsg := testScheduledMessage(scheduledMessageId, testUserId, now)
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ func TestCreateScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
assert.NoError(t, err, "Error creating scheduled message: %v", err)
|
assert.NoError(t, err, "Error creating scheduled message: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
testReq := CreateScheduledMessageEventRequest{RecipientId: recipientId, MessageId: messageId, ScheduledMessageId: scheduledMessageId}
|
testReq := CreateScheduledMessageEventRequest{ContactId: contactId, MessageId: messageId, ScheduledMessageId: scheduledMessageId}
|
||||||
jsonValue, _ := json.Marshal(testReq)
|
jsonValue, _ := json.Marshal(testReq)
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", endpoint.AddEventToScheduledMessageEndpoint, strings.NewReader(string(jsonValue)))
|
req, _ := http.NewRequest("POST", endpoint.AddEventToScheduledMessageEndpoint, strings.NewReader(string(jsonValue)))
|
||||||
@@ -72,7 +72,7 @@ func TestCreateScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusCreated, rr.Code)
|
assert.Equal(t, http.StatusCreated, rr.Code)
|
||||||
|
|
||||||
var response AddScheduledMessageEventResponse
|
var response AddScheduledMessageEventResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error creating event %v", err)
|
assert.NoError(t, err, "Error creating event %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No event created")
|
assert.NotEmpty(t, response.Data, "No event created")
|
||||||
@@ -90,17 +90,19 @@ func TestGetScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
messageStore := mock.NewMockMessageStore()
|
messageStore := mock.NewMockMessageStore()
|
||||||
schMsgStore := mock.NewMockScheduledMessageStore()
|
schMsgStore := mock.NewMockScheduledMessageStore()
|
||||||
schMsgEventStore := mock.NewMockScheduledMessageEventStore()
|
schMsgEventStore := mock.NewMockScheduledMessageEventStore()
|
||||||
handler := NewScheduledMessageEventHandler(schMsgEventStore, schMsgStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageEventHandler(apiApp, schMsgEventStore, schMsgStore)
|
||||||
|
|
||||||
recipientId := uuid.New()
|
contactId := uuid.New()
|
||||||
messageId := uuid.New()
|
messageId := uuid.New()
|
||||||
scheduledMessageId := uuid.New()
|
scheduledMessageId := uuid.New()
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
|
|
||||||
con := testContact(recipientId, testUserId)
|
con := ContactTest(contactId, testUserId)
|
||||||
msg := testMessage(messageId, testUserId)
|
msg := MessageTest(messageId, testUserId)
|
||||||
schMsg := testScheduledMessage(scheduledMessageId, testUserId, now)
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
event := testScheduledMessageEvent(msg.Id, con.Id, schMsg.Id)
|
event := ScheduledMessageEventTest(*msg.Id, *con.Id, schMsg.Id)
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
@@ -123,7 +125,7 @@ func TestGetScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response GetScheduledMessageEventResponse
|
var response GetScheduledMessageEventResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error creating event %v", err)
|
assert.NoError(t, err, "Error creating event %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No event created")
|
assert.NotEmpty(t, response.Data, "No event created")
|
||||||
@@ -139,12 +141,14 @@ func TestDeleteScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
messageStore := mock.NewMockMessageStore()
|
messageStore := mock.NewMockMessageStore()
|
||||||
schMsgStore := mock.NewMockScheduledMessageStore()
|
schMsgStore := mock.NewMockScheduledMessageStore()
|
||||||
schMsgEventStore := mock.NewMockScheduledMessageEventStore()
|
schMsgEventStore := mock.NewMockScheduledMessageEventStore()
|
||||||
handler := NewScheduledMessageEventHandler(schMsgEventStore, schMsgStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageEventHandler(apiApp, schMsgEventStore, schMsgStore)
|
||||||
|
|
||||||
con := testContact(recipientId, testUserId)
|
con := ContactTest(contactId, testUserId)
|
||||||
msg := testMessage(messageId, testUserId)
|
msg := MessageTest(messageId, testUserId)
|
||||||
schMsg := testScheduledMessage(scheduledMessageId, testUserId, now)
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
event := testScheduledMessageEvent(msg.Id, con.Id, schMsg.Id)
|
event := ScheduledMessageEventTest(*msg.Id, *con.Id, schMsg.Id)
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
@@ -167,7 +171,7 @@ func TestDeleteScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response DeleteScheduledMessageEventResponse
|
var response DeleteScheduledMessageEventResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error creating event %v", err)
|
assert.NoError(t, err, "Error creating event %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No event created")
|
assert.NotEmpty(t, response.Data, "No event created")
|
||||||
@@ -176,31 +180,3 @@ func TestDeleteScheduledMessageEventWithMock(t *testing.T) {
|
|||||||
|
|
||||||
assert.NotEmpty(t, msgEvent.Created, "Created date should not be empty")
|
assert.NotEmpty(t, msgEvent.Created, "Created date should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testContact(id uuid.UUID, userId uuid.UUID) contact.Contact {
|
|
||||||
if id == uuid.Nil {
|
|
||||||
return contact.Contact{Id: uuid.New(), PhoneNumber: "+10123456789", UserId: userId}
|
|
||||||
} else {
|
|
||||||
return contact.Contact{Id: id, PhoneNumber: "+10123456789", UserId: userId}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testMessage(id uuid.UUID, userId uuid.UUID) message.Message {
|
|
||||||
if id == uuid.Nil {
|
|
||||||
return message.Message{Id: uuid.New(), Content: "Oh how the mighty have fallen", UserId: userId}
|
|
||||||
} else {
|
|
||||||
return message.Message{Id: id, Content: "Oh how the mighty have fallen", UserId: userId}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testScheduledMessage(id uuid.UUID, userId uuid.UUID, now time.Time) scheduling.ScheduledMessage {
|
|
||||||
if id == uuid.Nil {
|
|
||||||
return scheduling.ScheduledMessage{Id: uuid.New(), UserId: userId, Scheduled: now.Add(20 * time.Minute), Status: scheduling.Pending}
|
|
||||||
} else {
|
|
||||||
return scheduling.ScheduledMessage{Id: id, UserId: userId, Scheduled: now.Add(20 * time.Minute), Status: scheduling.Pending}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testScheduledMessageEvent(messageId, recipientId, scheduledMessageId uuid.UUID) scheduling.ScheduledMessageEvent {
|
|
||||||
return scheduling.ScheduledMessageEvent{MessageId: messageId, RecipientId: recipientId, ScheduledMessageId: scheduledMessageId}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@@ -26,10 +26,12 @@ type CreateScheduledMessageRequest struct {
|
|||||||
func TestCreateScheduledMessageWithMock(t *testing.T) {
|
func TestCreateScheduledMessageWithMock(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
mockStore := mock.NewMockScheduledMessageStore()
|
mockStore := mock.NewMockScheduledMessageStore()
|
||||||
handler := NewScheduledMessageHandler(mockStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageHandler(apiApp, mockStore)
|
||||||
|
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
testBody := testCreateScheduledMessageRequest(testUserId, now)
|
testBody := createScheduledMessageRequest(testUserId, now)
|
||||||
jsonValue, _ := json.Marshal(testBody)
|
jsonValue, _ := json.Marshal(testBody)
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", endpoint.ScheduleMessageEndpoint, strings.NewReader(string(jsonValue)))
|
req, _ := http.NewRequest("POST", endpoint.ScheduleMessageEndpoint, strings.NewReader(string(jsonValue)))
|
||||||
@@ -40,7 +42,7 @@ func TestCreateScheduledMessageWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusCreated, rr.Code)
|
assert.Equal(t, http.StatusCreated, rr.Code)
|
||||||
|
|
||||||
var response AddScheduledMessageResponse
|
var response AddScheduledMessageResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error Creating message %v", err)
|
assert.NoError(t, err, "Error Creating message %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No Message created")
|
assert.NotEmpty(t, response.Data, "No Message created")
|
||||||
@@ -53,7 +55,7 @@ func TestGetScheduledMessageWithMock(t *testing.T) {
|
|||||||
mockStore := mock.NewMockScheduledMessageStore()
|
mockStore := mock.NewMockScheduledMessageStore()
|
||||||
|
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
testBody := testCreateScheduledMessageRequest(testUserId, now)
|
testBody := createScheduledMessageRequest(testUserId, now)
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
schMsg := scheduling.ScheduledMessage{}
|
schMsg := scheduling.ScheduledMessage{}
|
||||||
@@ -68,13 +70,15 @@ func TestGetScheduledMessageWithMock(t *testing.T) {
|
|||||||
req, _ := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewScheduledMessageHandler(mockStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageHandler(apiApp, mockStore)
|
||||||
handler.GetScheduledMessage(rr, req)
|
handler.GetScheduledMessage(rr, req)
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response GetScheduledMessageResponse
|
var response GetScheduledMessageResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error parsing response %v", err)
|
assert.NoError(t, err, "Error parsing response %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,15 +89,15 @@ func TestFetchScheduledMessageWithMock(t *testing.T) {
|
|||||||
messageStore := mock.NewMockMessageStore()
|
messageStore := mock.NewMockMessageStore()
|
||||||
schMsgEventStore := mock.NewMockScheduledMessageEventStore()
|
schMsgEventStore := mock.NewMockScheduledMessageEventStore()
|
||||||
|
|
||||||
recipientId := uuid.New()
|
contactId := uuid.New()
|
||||||
messageId := uuid.New()
|
messageId := uuid.New()
|
||||||
scheduledMessageId := uuid.New()
|
scheduledMessageId := uuid.New()
|
||||||
testUserId := uuid.New()
|
testUserId := uuid.New()
|
||||||
|
|
||||||
con := testContact(recipientId, testUserId)
|
con := ContactTest(contactId, testUserId)
|
||||||
msg := testMessage(messageId, testUserId)
|
msg := MessageTest(messageId, testUserId)
|
||||||
schMsg := testScheduledMessage(scheduledMessageId, testUserId, now)
|
schMsg := ScheduledMessageTest(scheduledMessageId, testUserId, now)
|
||||||
event := testScheduledMessageEvent(msg.Id, con.Id, schMsg.Id)
|
event := ScheduledMessageEventTest(*msg.Id, *con.Id, schMsg.Id)
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
@@ -114,13 +118,15 @@ func TestFetchScheduledMessageWithMock(t *testing.T) {
|
|||||||
req, _ := http.NewRequest("GET", endpoint.FetchNextScheduledMessageEndpoint, nil)
|
req, _ := http.NewRequest("GET", endpoint.FetchNextScheduledMessageEndpoint, nil)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
handler := NewScheduledMessageHandler(mockStore)
|
apiApp, err := GetApp()
|
||||||
|
assert.NoError(t, err, "Error getting app")
|
||||||
|
handler := NewScheduledMessageHandler(apiApp, mockStore)
|
||||||
handler.FetchNextMessage(rr, req)
|
handler.FetchNextMessage(rr, req)
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response FetchNextMessageResponse
|
var response FetchNextMessageResponse
|
||||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
assert.NoError(t, err, "Error fetching scheduled message: %v", err)
|
assert.NoError(t, err, "Error fetching scheduled message: %v", err)
|
||||||
|
|
||||||
assert.NotEmpty(t, response.Data, "No data")
|
assert.NotEmpty(t, response.Data, "No data")
|
||||||
@@ -129,7 +135,7 @@ func TestFetchScheduledMessageWithMock(t *testing.T) {
|
|||||||
assert.Equal(t, scheduling.Processing, fetchedSchMsg.Status, "The statuses do not match")
|
assert.Equal(t, scheduling.Processing, fetchedSchMsg.Status, "The statuses do not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCreateScheduledMessageRequest(userId uuid.UUID, now time.Time) CreateScheduledMessageRequest {
|
func createScheduledMessageRequest(userId uuid.UUID, now time.Time) CreateScheduledMessageRequest {
|
||||||
scheduled := now.Add(5 * time.Minute)
|
scheduled := now.Add(5 * time.Minute)
|
||||||
return CreateScheduledMessageRequest{Status: scheduling.Pending, UserId: userId, Scheduled: scheduled}
|
return CreateScheduledMessageRequest{Status: scheduling.Pending, UserId: userId, Scheduled: scheduled}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ package services
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
txtmodels_token "git.kundeng.us/phoenix/textsender-models/tx0/token"
|
||||||
|
txtmodels_user "git.kundeng.us/phoenix/textsender-models/tx0/user"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
|
||||||
txtmodels_token "git.kundeng.us/phoenix/textsender-models/pkg/token"
|
|
||||||
txtmodels_user "git.kundeng.us/phoenix/textsender-models/pkg/user"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type JWTService struct {
|
type JWTService struct {
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContactStore interface {
|
type ContactStore interface {
|
||||||
@@ -17,6 +16,7 @@ type ContactStore interface {
|
|||||||
GetContactByPhone(ctx context.Context, phone string, userId uuid.UUID) (*contact.Contact, error)
|
GetContactByPhone(ctx context.Context, phone string, userId uuid.UUID) (*contact.Contact, error)
|
||||||
GetAllContacts(ctx context.Context) ([]*contact.Contact, error)
|
GetAllContacts(ctx context.Context) ([]*contact.Contact, error)
|
||||||
ContactExists(ctx context.Context, phone string, userId uuid.UUID) (bool, error)
|
ContactExists(ctx context.Context, phone string, userId uuid.UUID) (bool, error)
|
||||||
|
UpdateNames(ctx context.Context, con *contact.Contact, firstname *string, lastname *string, nickname *string) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGContactStore struct {
|
type PGContactStore struct {
|
||||||
@@ -29,54 +29,52 @@ func NewContactStore(db *pgxpool.Pool) *PGContactStore {
|
|||||||
|
|
||||||
func (s *PGContactStore) CreateContact(ctx context.Context, con *contact.Contact) error {
|
func (s *PGContactStore) CreateContact(ctx context.Context, con *contact.Contact) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO contacts (phone_number, user_id)
|
INSERT INTO contacts (phone_number, user_id, first_name, last_name, nickname)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
RETURNING id, phone_number, user_id
|
RETURNING id, phone_number, user_id
|
||||||
`
|
`
|
||||||
|
|
||||||
return s.db.QueryRow(ctx, query, con.PhoneNumber, con.UserId).Scan(
|
return s.db.QueryRow(ctx, query, con.PhoneNumber, con.UserId, con.Firstname, con.Lastname, con.Nickname).Scan(
|
||||||
&con.Id, &con.PhoneNumber, &con.UserId,
|
&con.Id, &con.PhoneNumber, &con.UserId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PGContactStore) GetContactByID(ctx context.Context, id uuid.UUID) (*contact.Contact, error) {
|
func (s *PGContactStore) GetContactByID(ctx context.Context, id uuid.UUID) (*contact.Contact, error) {
|
||||||
query := `SELECT id, phone_number, user_id FROM contacts WHERE id = $1`
|
query := `SELECT id, phone_number, user_id, first_name, last_name, nickname FROM contacts WHERE id = $1`
|
||||||
|
|
||||||
var con contact.Contact
|
var con contact.Contact
|
||||||
err := s.db.QueryRow(ctx, query, id).Scan(
|
err := s.db.QueryRow(ctx, query, id).Scan(
|
||||||
&con.Id, &con.PhoneNumber, &con.UserId,
|
&con.Id, &con.PhoneNumber, &con.UserId, &con.Firstname, &con.Lastname, &con.Nickname,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err == pgx.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
} else if err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("getting contact by ID: %w", err)
|
return nil, fmt.Errorf("getting contact by ID: %w", err)
|
||||||
|
} else {
|
||||||
|
return &con, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &con, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PGContactStore) GetContactByPhone(ctx context.Context, phone string, userId uuid.UUID) (*contact.Contact, error) {
|
func (s *PGContactStore) GetContactByPhone(ctx context.Context, phone string, userId uuid.UUID) (*contact.Contact, error) {
|
||||||
query := `SELECT id, phone_number, user_id FROM contacts WHERE phone_number = $1 AND user_id = $2`
|
query := `SELECT id, phone_number, user_id, first_name, last_name, nickname FROM contacts WHERE phone_number = $1 AND user_id = $2`
|
||||||
|
|
||||||
var con contact.Contact
|
var con contact.Contact
|
||||||
err := s.db.QueryRow(ctx, query, phone, userId).Scan(
|
err := s.db.QueryRow(ctx, query, phone, userId).Scan(
|
||||||
&con.Id, &con.PhoneNumber, &con.UserId,
|
&con.Id, &con.PhoneNumber, &con.UserId, &con.Firstname, &con.Lastname, &con.Nickname,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err == pgx.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
} else if err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("getting contact by phone and User ID: %w", err)
|
return nil, fmt.Errorf("getting contact by phone and User ID: %w", err)
|
||||||
|
} else {
|
||||||
|
return &con, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &con, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PGContactStore) GetAllContacts(ctx context.Context) ([]*contact.Contact, error) {
|
func (s *PGContactStore) GetAllContacts(ctx context.Context) ([]*contact.Contact, error) {
|
||||||
query := `SELECT id, phone_number, user_id FROM contacts`
|
query := `SELECT id, phone_number, user_id, first_name, last_name, nickname FROM contacts`
|
||||||
|
|
||||||
rows, err := s.db.Query(ctx, query)
|
rows, err := s.db.Query(ctx, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -88,7 +86,7 @@ func (s *PGContactStore) GetAllContacts(ctx context.Context) ([]*contact.Contact
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var con contact.Contact
|
var con contact.Contact
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&con.Id, &con.PhoneNumber, &con.UserId,
|
&con.Id, &con.PhoneNumber, &con.UserId, &con.Firstname, &con.Lastname, &con.Nickname,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, fmt.Errorf("scanning contact row: %w", err)
|
return nil, fmt.Errorf("scanning contact row: %w", err)
|
||||||
}
|
}
|
||||||
@@ -113,3 +111,72 @@ func (s *PGContactStore) ContactExists(ctx context.Context, phone string, userId
|
|||||||
|
|
||||||
return exists, nil
|
return exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PGContactStore) UpdateNames(ctx context.Context, con *contact.Contact, firstname *string, lastname *string, nickname *string) (int64, error) {
|
||||||
|
if firstname == nil && lastname == nil && nickname == nil {
|
||||||
|
return 0, fmt.Errorf("Names are nil")
|
||||||
|
} else {
|
||||||
|
if firstname != nil && lastname != nil && nickname != nil {
|
||||||
|
query := "UPDATE contacts SET first_name = $1, last_name = $2, nickname = $3 WHERE id = $4"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, firstname, lastname, nickname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Firstname = firstname
|
||||||
|
con.Lastname = lastname
|
||||||
|
con.Nickname = nickname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
} else if firstname != nil && lastname != nil {
|
||||||
|
query := "UPDATE contacts SET first_name = $1, last_name = $2 WHERE id = $3"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, firstname, lastname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Firstname = firstname
|
||||||
|
con.Lastname = lastname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
} else if lastname != nil && nickname != nil {
|
||||||
|
query := "UPDATE contacts SET last_name = $1, nickname = $2 WHERE id = $3"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, lastname, nickname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Lastname = lastname
|
||||||
|
con.Nickname = nickname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
} else if nickname != nil && firstname != nil {
|
||||||
|
query := "UPDATE contacts SET nickname = $1, firstname = $2 WHERE id = $3"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, nickname, firstname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Firstname = firstname
|
||||||
|
con.Nickname = nickname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
} else if firstname != nil {
|
||||||
|
query := "UPDATE contacts SET firstname = $1 WHERE id = $2"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, firstname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Firstname = firstname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
} else if lastname != nil {
|
||||||
|
query := "UPDATE contacts SET lastname = $1 WHERE id = $2"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, lastname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Lastname = lastname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
query := "UPDATE contacts SET nickname = $1 WHERE id = $2"
|
||||||
|
if affected, err := s.db.Exec(ctx, query, nickname, con.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
con.Nickname = nickname
|
||||||
|
return affected.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MessageEventResponseStore interface {
|
||||||
|
Create(ctx context.Context, mer *event.MessageEventResponse) error
|
||||||
|
GetWithUserId(ctx context.Context, userId uuid.UUID) ([]*event.MessageEventResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PGMessageEventResponseStore struct {
|
||||||
|
db *pgxpool.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMessageEventResponseStore(db *pgxpool.Pool) *PGMessageEventResponseStore {
|
||||||
|
return &PGMessageEventResponseStore{db: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PGMessageEventResponseStore) Create(ctx context.Context, mer *event.MessageEventResponse) error {
|
||||||
|
var query string
|
||||||
|
queryBase := "INSERT INTO message_event_responses"
|
||||||
|
queryReturn := "RETURNING id"
|
||||||
|
|
||||||
|
if mer.ScheduledMessageEventId == uuid.Nil {
|
||||||
|
query = fmt.Sprintf("%s (response, user_id, sent, contact_id, message_id, status) VALUES ($1, $2, $3, $4, $5, $6) %s", queryBase, queryReturn)
|
||||||
|
return m.db.QueryRow(ctx, query, mer.Response, mer.UserId, mer.Sent, mer.ContactId, mer.MessageId, mer.Status).Scan(&mer.Id)
|
||||||
|
} else {
|
||||||
|
query = fmt.Sprintf("%s (scheduled_message_event_id, response, user_id, sent, contact_id, message_id, status) VALUES ($1, $2, $3, $4, $5, $6, $7) %s", queryBase, queryReturn)
|
||||||
|
return m.db.QueryRow(ctx, query, mer.ScheduledMessageEventId, mer.Response, mer.UserId, mer.Sent, mer.ContactId, mer.MessageId, mer.Status).Scan(&mer.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PGMessageEventResponseStore) GetWithUserId(ctx context.Context, userId uuid.UUID) ([]*event.MessageEventResponse, error) {
|
||||||
|
query := "SELECT id, scheduled_message_event_id, response, user_id, sent, contact_id, message_id, status FROM message_event_responses WHERE user_id = $1"
|
||||||
|
rows, err := m.db.Query(ctx, query, userId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Error querying: %w", err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var sentMessages []*event.MessageEventResponse
|
||||||
|
for rows.Next() {
|
||||||
|
var msg event.MessageEventResponse
|
||||||
|
if err := rows.Scan(&msg.Id, &msg.ScheduledMessageEventId, &msg.Response, &msg.UserId, &msg.Sent, &msg.ContactId, &msg.MessageId, &msg.Status); err != nil {
|
||||||
|
return nil, fmt.Errorf("Scanning row: %w", err)
|
||||||
|
}
|
||||||
|
sentMessages = append(sentMessages, &msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, fmt.Errorf("Iterating message_event_responses: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return sentMessages, nil
|
||||||
|
}
|
||||||
@@ -4,11 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageStore interface {
|
type MessageStore interface {
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package mock
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Key struct {
|
type Key struct {
|
||||||
@@ -38,16 +37,18 @@ func (m *MockContactStore) CreateContact(ctx context.Context, con *contact.Conta
|
|||||||
return m.Error
|
return m.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
if con.Id == uuid.Nil {
|
var id uuid.UUID
|
||||||
con.Id = uuid.New()
|
if con.Id == nil {
|
||||||
|
id = uuid.New()
|
||||||
|
con.Id = &id
|
||||||
}
|
}
|
||||||
|
|
||||||
key := Key{PhoneNumber: con.PhoneNumber, UserId: con.UserId}
|
key := Key{PhoneNumber: con.PhoneNumber, UserId: *con.UserId}
|
||||||
if _, exists := m.ContactsByKey[key]; exists {
|
if _, exists := m.ContactsByKey[key]; exists {
|
||||||
return errors.New("Contact with phone number already exists")
|
return errors.New("Contact with phone number already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Contacts[con.Id] = con
|
m.Contacts[*con.Id] = con
|
||||||
m.ContactsByKey[key] = con
|
m.ContactsByKey[key] = con
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -117,86 +118,29 @@ func (m *MockContactStore) ContactExists(ctx context.Context, phoneNumber string
|
|||||||
return exists, nil
|
return exists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageKey struct {
|
func (m *MockContactStore) UpdateNames(ctx context.Context, con *contact.Contact, firstname *string, lastname *string, nickname *string) (int64, error) {
|
||||||
Content string
|
|
||||||
UserId uuid.UUID
|
|
||||||
}
|
|
||||||
|
|
||||||
type MockMessageStore struct {
|
|
||||||
Messages map[uuid.UUID]*message.Message
|
|
||||||
MessagesByKey map[MessageKey]*message.Message
|
|
||||||
mu sync.RWMutex
|
|
||||||
Error error // Optional: simulate errors
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMockMessageStore() *MockMessageStore {
|
|
||||||
return &MockMessageStore{
|
|
||||||
Messages: make(map[uuid.UUID]*message.Message),
|
|
||||||
MessagesByKey: make(map[MessageKey]*message.Message),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockMessageStore) CreateMessage(ctx context.Context, msg *message.Message) error {
|
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
if m.Error != nil {
|
if m.Error != nil {
|
||||||
return m.Error
|
return 0, m.Error
|
||||||
|
} else if firstname == nil && lastname == nil && nickname == nil {
|
||||||
|
return 0, fmt.Errorf("Names are not provided")
|
||||||
|
} else {
|
||||||
|
if c, exists := m.Contacts[*con.Id]; !exists {
|
||||||
|
return 0, fmt.Errorf("Contact does not exist")
|
||||||
|
} else {
|
||||||
|
if firstname != nil {
|
||||||
|
c.Firstname = firstname
|
||||||
|
}
|
||||||
|
if lastname != nil {
|
||||||
|
c.Lastname = lastname
|
||||||
|
}
|
||||||
|
if nickname != nil {
|
||||||
|
c.Nickname = nickname
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Id == uuid.Nil {
|
return 0, nil
|
||||||
msg.Id = uuid.New()
|
|
||||||
}
|
|
||||||
|
|
||||||
key := MessageKey{Content: msg.Content, UserId: msg.UserId}
|
|
||||||
if _, exists := m.MessagesByKey[key]; exists {
|
|
||||||
return errors.New("Message already exists")
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Messages[msg.Id] = msg
|
|
||||||
m.MessagesByKey[key] = msg
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockMessageStore) GetAllMessages(ctx context.Context) ([]*message.Message, error) {
|
|
||||||
m.mu.Lock()
|
|
||||||
defer m.mu.Unlock()
|
|
||||||
|
|
||||||
if m.Error != nil {
|
|
||||||
return nil, m.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
var msgs []*message.Message
|
|
||||||
|
|
||||||
for _, msg := range m.Messages {
|
|
||||||
msgs = append(msgs, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
return msgs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockMessageStore) GetMessageByID(ctx context.Context, id uuid.UUID) (*message.Message, error) {
|
|
||||||
m.mu.Lock()
|
|
||||||
defer m.mu.Unlock()
|
|
||||||
|
|
||||||
if m.Error != nil {
|
|
||||||
return nil, m.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := m.Messages[id]
|
|
||||||
|
|
||||||
return msg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockMessageStore) MessageExists(ctx context.Context, msg *message.Message) (bool, error) {
|
|
||||||
m.mu.Lock()
|
|
||||||
defer m.mu.Unlock()
|
|
||||||
|
|
||||||
if m.Error != nil {
|
|
||||||
return false, m.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
_, exists := m.MessagesByKey[MessageKey{Content: msg.Content, UserId: msg.UserId}]
|
|
||||||
|
|
||||||
return exists, nil
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package mock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MessageEventResponseKey struct {
|
||||||
|
ScheduledMessageEventId uuid.UUID
|
||||||
|
UserId uuid.UUID
|
||||||
|
}
|
||||||
|
type MockMessageEventResponseStore struct {
|
||||||
|
MessageEventResponses map[uuid.UUID]*event.MessageEventResponse
|
||||||
|
MessageEventResponsesByKey map[MessageEventResponseKey]*event.MessageEventResponse
|
||||||
|
mu sync.RWMutex
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMockMessageEventResponseStore() *MockMessageEventResponseStore {
|
||||||
|
return &MockMessageEventResponseStore{
|
||||||
|
MessageEventResponses: make(map[uuid.UUID]*event.MessageEventResponse),
|
||||||
|
MessageEventResponsesByKey: make(map[MessageEventResponseKey]*event.MessageEventResponse),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockMessageEventResponseStore) Create(ctx context.Context, mer *event.MessageEventResponse) error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.Error != nil {
|
||||||
|
return m.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
if mer.Id == uuid.Nil {
|
||||||
|
mer.Id = uuid.New()
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(mer.Response) == 0 {
|
||||||
|
return fmt.Errorf("Response is empty")
|
||||||
|
} else if mer.UserId == uuid.Nil {
|
||||||
|
return fmt.Errorf("User Id is nil")
|
||||||
|
} else {
|
||||||
|
key := MessageEventResponseKey{ScheduledMessageEventId: mer.ScheduledMessageEventId, UserId: mer.UserId}
|
||||||
|
if mer.ScheduledMessageEventId == uuid.Nil {
|
||||||
|
key.ScheduledMessageEventId = uuid.Nil
|
||||||
|
} else {
|
||||||
|
key.ScheduledMessageEventId = mer.ScheduledMessageEventId
|
||||||
|
}
|
||||||
|
sent := time.Now()
|
||||||
|
mer.Sent = sent
|
||||||
|
|
||||||
|
m.MessageEventResponses[mer.Id] = mer
|
||||||
|
m.MessageEventResponsesByKey[key] = mer
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add code to get mock MessageEventResponse
|
||||||
|
func (m *MockMessageEventResponseStore) GetWithUserId(ctx context.Context, userId uuid.UUID) ([]*event.MessageEventResponse, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.Error != nil {
|
||||||
|
return nil, m.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
var messages []*event.MessageEventResponse
|
||||||
|
for _, msg := range m.MessageEventResponses {
|
||||||
|
if msg.UserId == userId {
|
||||||
|
messages = append(messages, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages, nil
|
||||||
|
}
|
||||||
@@ -6,13 +6,12 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScheduledMessageEventKey struct {
|
type ScheduledMessageEventKey struct {
|
||||||
RecipientId uuid.UUID
|
ContactId uuid.UUID
|
||||||
MessageId uuid.UUID
|
MessageId uuid.UUID
|
||||||
ScheduledMessageId uuid.UUID
|
ScheduledMessageId uuid.UUID
|
||||||
}
|
}
|
||||||
@@ -95,7 +94,7 @@ func (m *MockScheduledMessageEventStore) Delete(ctx context.Context, id uuid.UUI
|
|||||||
copiedEventsKey := make(map[ScheduledMessageEventKey]*scheduling.ScheduledMessageEvent)
|
copiedEventsKey := make(map[ScheduledMessageEventKey]*scheduling.ScheduledMessageEvent)
|
||||||
|
|
||||||
for i, schMsgEvent := range m.ScheduledMessageEvents {
|
for i, schMsgEvent := range m.ScheduledMessageEvents {
|
||||||
key := ScheduledMessageEventKey{RecipientId: schMsgEvent.RecipientId, MessageId: schMsgEvent.MessageId, ScheduledMessageId: schMsgEvent.ScheduledMessageId}
|
key := ScheduledMessageEventKey{ContactId: schMsgEvent.ContactId, MessageId: schMsgEvent.MessageId, ScheduledMessageId: schMsgEvent.ScheduledMessageId}
|
||||||
if schMsgEvent.Id != id {
|
if schMsgEvent.Id != id {
|
||||||
copiedEvents[i] = schMsgEvent
|
copiedEvents[i] = schMsgEvent
|
||||||
copiedEventsKey[key] = schMsgEvent
|
copiedEventsKey[key] = schMsgEvent
|
||||||
@@ -133,7 +132,7 @@ func (m *MockScheduledMessageEventStore) CreateScheduledMessageEvent(ctx context
|
|||||||
event.Id = uuid.New()
|
event.Id = uuid.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
key := ScheduledMessageEventKey{RecipientId: event.RecipientId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
|
key := ScheduledMessageEventKey{ContactId: event.ContactId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
|
||||||
|
|
||||||
if _, exists := m.ScheduledMessageEventsByKey[key]; exists {
|
if _, exists := m.ScheduledMessageEventsByKey[key]; exists {
|
||||||
return fmt.Errorf("Already exists")
|
return fmt.Errorf("Already exists")
|
||||||
@@ -153,7 +152,7 @@ func (m *MockScheduledMessageEventStore) Exists(ctx context.Context, event *sche
|
|||||||
return false, m.Error
|
return false, m.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
key := ScheduledMessageEventKey{RecipientId: event.RecipientId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
|
key := ScheduledMessageEventKey{ContactId: event.ContactId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
|
||||||
_, exists := m.ScheduledMessageEventsByKey[key]
|
_, exists := m.ScheduledMessageEventsByKey[key]
|
||||||
|
|
||||||
return exists, nil
|
return exists, nil
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScheduledMessageKey struct {
|
type ScheduledMessageKey struct {
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package mock
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MessageKey struct {
|
||||||
|
Content string
|
||||||
|
UserId uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
type MockMessageStore struct {
|
||||||
|
Messages map[uuid.UUID]*message.Message
|
||||||
|
MessagesByKey map[MessageKey]*message.Message
|
||||||
|
mu sync.RWMutex
|
||||||
|
Error error // Optional: simulate errors
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMockMessageStore() *MockMessageStore {
|
||||||
|
return &MockMessageStore{
|
||||||
|
Messages: make(map[uuid.UUID]*message.Message),
|
||||||
|
MessagesByKey: make(map[MessageKey]*message.Message),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockMessageStore) CreateMessage(ctx context.Context, msg *message.Message) error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.Error != nil {
|
||||||
|
return m.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
var id uuid.UUID
|
||||||
|
if msg != nil {
|
||||||
|
if msg.Id == nil || *msg.Id == uuid.Nil {
|
||||||
|
id = uuid.New()
|
||||||
|
msg.Id = &id
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("Message not populated")
|
||||||
|
}
|
||||||
|
|
||||||
|
key := MessageKey{Content: msg.Content, UserId: *msg.UserId}
|
||||||
|
if _, exists := m.MessagesByKey[key]; exists {
|
||||||
|
return errors.New("Message already exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Messages[*msg.Id] = msg
|
||||||
|
m.MessagesByKey[key] = msg
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockMessageStore) GetAllMessages(ctx context.Context) ([]*message.Message, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.Error != nil {
|
||||||
|
return nil, m.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
var msgs []*message.Message
|
||||||
|
|
||||||
|
for _, msg := range m.Messages {
|
||||||
|
msgs = append(msgs, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockMessageStore) GetMessageByID(ctx context.Context, id uuid.UUID) (*message.Message, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.Error != nil {
|
||||||
|
return nil, m.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := m.Messages[id]
|
||||||
|
|
||||||
|
return msg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockMessageStore) MessageExists(ctx context.Context, msg *message.Message) (bool, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.Error != nil {
|
||||||
|
return false, m.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
_, exists := m.MessagesByKey[MessageKey{Content: msg.Content, UserId: *msg.UserId}]
|
||||||
|
|
||||||
|
return exists, nil
|
||||||
|
}
|
||||||
@@ -4,11 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScheduledMessageEventStore interface {
|
type ScheduledMessageEventStore interface {
|
||||||
@@ -28,11 +27,11 @@ func NewScheduledMessageEventStore(db *pgxpool.Pool) *PGScheduledMessageEventSto
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *PGScheduledMessageEventStore) Get(ctx context.Context, id uuid.UUID) (*scheduling.ScheduledMessageEvent, error) {
|
func (s *PGScheduledMessageEventStore) Get(ctx context.Context, id uuid.UUID) (*scheduling.ScheduledMessageEvent, error) {
|
||||||
query := `SELECT id, recipient_id, message_id, scheduled_message_id, created FROM scheduled_message_events WHERE id = $1`
|
query := `SELECT id, contact_id, message_id, scheduled_message_id, created FROM scheduled_message_events WHERE id = $1`
|
||||||
|
|
||||||
var event scheduling.ScheduledMessageEvent
|
var event scheduling.ScheduledMessageEvent
|
||||||
err := s.db.QueryRow(ctx, query, id).Scan(
|
err := s.db.QueryRow(ctx, query, id).Scan(
|
||||||
&event.Id, &event.RecipientId, &event.MessageId, &event.ScheduledMessageId, &event.Created,
|
&event.Id, &event.ContactId, &event.MessageId, &event.ScheduledMessageId, &event.Created,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err == pgx.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
@@ -46,7 +45,7 @@ func (s *PGScheduledMessageEventStore) Get(ctx context.Context, id uuid.UUID) (*
|
|||||||
|
|
||||||
func (s *PGScheduledMessageEventStore) GetWithScheduleMessageId(ctx context.Context, schMsgId uuid.UUID) ([]*scheduling.ScheduledMessageEvent, error) {
|
func (s *PGScheduledMessageEventStore) GetWithScheduleMessageId(ctx context.Context, schMsgId uuid.UUID) ([]*scheduling.ScheduledMessageEvent, error) {
|
||||||
var events []*scheduling.ScheduledMessageEvent
|
var events []*scheduling.ScheduledMessageEvent
|
||||||
query := `SELECT id, recipient_id, message_id, scheduled_message_id, created FROM scheduled_message_events WHERE scheduled_message_id = $1
|
query := `SELECT id, contact_id, message_id, scheduled_message_id, created FROM scheduled_message_events WHERE scheduled_message_id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
rows, err := s.db.Query(ctx, query, schMsgId)
|
rows, err := s.db.Query(ctx, query, schMsgId)
|
||||||
@@ -58,7 +57,7 @@ func (s *PGScheduledMessageEventStore) GetWithScheduleMessageId(ctx context.Cont
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var event scheduling.ScheduledMessageEvent
|
var event scheduling.ScheduledMessageEvent
|
||||||
|
|
||||||
if err := rows.Scan(&event.Id, &event.RecipientId, &event.MessageId, &event.ScheduledMessageId, &event.Created); err != nil {
|
if err := rows.Scan(&event.Id, &event.ContactId, &event.MessageId, &event.ScheduledMessageId, &event.Created); err != nil {
|
||||||
return nil, fmt.Errorf("Error fetching data from row: %w", err)
|
return nil, fmt.Errorf("Error fetching data from row: %w", err)
|
||||||
} else {
|
} else {
|
||||||
events = append(events, &event)
|
events = append(events, &event)
|
||||||
@@ -91,21 +90,21 @@ func (s *PGScheduledMessageEventStore) Delete(ctx context.Context, id uuid.UUID)
|
|||||||
|
|
||||||
func (s *PGScheduledMessageEventStore) CreateScheduledMessageEvent(ctx context.Context, event *scheduling.ScheduledMessageEvent) error {
|
func (s *PGScheduledMessageEventStore) CreateScheduledMessageEvent(ctx context.Context, event *scheduling.ScheduledMessageEvent) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO scheduled_message_events (recipient_id, message_id, scheduled_message_id)
|
INSERT INTO scheduled_message_events (contact_id, message_id, scheduled_message_id)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
RETURNING id, created
|
RETURNING id, created
|
||||||
`
|
`
|
||||||
|
|
||||||
return s.db.QueryRow(ctx, query, event.RecipientId, event.MessageId, event.ScheduledMessageId).Scan(
|
return s.db.QueryRow(ctx, query, event.ContactId, event.MessageId, event.ScheduledMessageId).Scan(
|
||||||
&event.Id, &event.Created,
|
&event.Id, &event.Created,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PGScheduledMessageEventStore) Exists(ctx context.Context, event *scheduling.ScheduledMessageEvent) (bool, error) {
|
func (s *PGScheduledMessageEventStore) Exists(ctx context.Context, event *scheduling.ScheduledMessageEvent) (bool, error) {
|
||||||
query := `SELECT EXISTS(SELECT 1 FROM scheduled_message_events WHERE scheduled_message_id = $1 AND recipient_id = $2)`
|
query := `SELECT EXISTS(SELECT 1 FROM scheduled_message_events WHERE scheduled_message_id = $1 AND contact_id = $2)`
|
||||||
|
|
||||||
var exists bool
|
var exists bool
|
||||||
err := s.db.QueryRow(ctx, query, event.ScheduledMessageId, event.RecipientId).Scan(&exists)
|
err := s.db.QueryRow(ctx, query, event.ScheduledMessageId, event.ContactId).Scan(&exists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Scheduled message event does not exist: %w", err)
|
return false, fmt.Errorf("Scheduled message event does not exist: %w", err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message/scheduling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScheduledMessageStore interface {
|
type ScheduledMessageStore interface {
|
||||||
|
|||||||
+21
-3
@@ -1,11 +1,18 @@
|
|||||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
DROP TABLE IF EXISTS contacts CASCADE;
|
DROP TABLE IF EXISTS contacts CASCADE;
|
||||||
|
DROP TABLE IF EXISTS messages CASCADE;
|
||||||
|
DROP TABLE IF EXISTS scheduled_messages CASCADE;
|
||||||
|
DROP TABLE IF EXISTS scheduled_message_events CASCADE;
|
||||||
|
DROP TABLE IF EXISTS message_event_responses CASCADE;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS contacts (
|
CREATE TABLE IF NOT EXISTS contacts (
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
phone_number TEXT NOT NULL,
|
phone_number TEXT NOT NULL,
|
||||||
user_id UUID NOT NULL
|
user_id UUID NOT NULL,
|
||||||
|
first_name TEXT NULL,
|
||||||
|
last_name TEXT NULL,
|
||||||
|
nickname TEXT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS messages (
|
CREATE TABLE IF NOT EXISTS messages (
|
||||||
@@ -24,8 +31,19 @@ CREATE TABLE IF NOT EXISTS scheduled_messages (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS scheduled_message_events (
|
CREATE TABLE IF NOT EXISTS scheduled_message_events (
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
recipient_id UUID NOT NULL,
|
contact_id UUID NOT NULL,
|
||||||
message_id UUID NOT NULL,
|
message_id UUID NOT NULL,
|
||||||
scheduled_message_id UUID NOT NULL,
|
scheduled_message_id UUID NOT NULL,
|
||||||
created timestamptz DEFAULT now()
|
created timestamptz DEFAULT now()
|
||||||
)
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS message_event_responses (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
scheduled_message_event_id UUID NULL,
|
||||||
|
response JSONB NOT NULL,
|
||||||
|
user_id UUID NOT NULL,
|
||||||
|
sent timestamptz NOT NULL,
|
||||||
|
contact_id UUID NULL,
|
||||||
|
message_id UUID NULL,
|
||||||
|
status TEXT CHECK (status IN ('INSTANT', 'SCHEDULED'))
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user