From 3c166b25ee0fce162c1a945ef0dd7f7fffd516c5 Mon Sep 17 00:00:00 2001 From: Shion Ichikawa Date: Sat, 12 Oct 2024 06:52:24 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Invoke=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 4 ++++ pkg/handler/invoke.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 pkg/handler/invoke.go diff --git a/main.go b/main.go index ac9b6ef..54f969c 100644 --- a/main.go +++ b/main.go @@ -40,5 +40,9 @@ func main() { return } } + + invokeHandler := handler.NewInvokeHandler(fs) + e.POST("/invoke", invokeHandler.Handle) + e.Run(fmt.Sprintf(":%d", port)) } diff --git a/pkg/handler/invoke.go b/pkg/handler/invoke.go new file mode 100644 index 0000000..3fc6ecd --- /dev/null +++ b/pkg/handler/invoke.go @@ -0,0 +1,44 @@ +package handler + +import ( + "cloud.google.com/go/firestore" + "fmt" + "github.com/gin-gonic/gin" + "log/slog" + "time" +) + +type CallInvoke struct { + fs *firestore.Client +} + +func NewInvokeHandler( + fs *firestore.Client, +) *CallInvoke { + return &CallInvoke{ + fs: fs, + } +} + +func (h *CallInvoke) Handle(c *gin.Context) { + // get time + timeVal := fmt.Sprintf("%2d:%2d", time.Now().Hour(), 0) + res := h.fs.Collection("users").Where("call_time", "==", timeVal).Documents(c) + if res == nil { + c.JSON(400, gin.H{"error": "no data"}) + return + } + for { + doc, err := res.Next() + if err != nil { + break + } + userdata := doc.Data() + slog.Info("invoke call on user", slog.Any("data", userdata)) + + // vonage callを発火 + } + c.JSON(200, gin.H{ + "message": "success", + }) +}