Skip to content

Commit

Permalink
✨ Invoke endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Shion1305 committed Oct 11, 2024
1 parent c82bc8a commit 3c166b2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ func main() {
return
}
}

invokeHandler := handler.NewInvokeHandler(fs)
e.POST("/invoke", invokeHandler.Handle)

e.Run(fmt.Sprintf(":%d", port))
}
44 changes: 44 additions & 0 deletions pkg/handler/invoke.go
Original file line number Diff line number Diff line change
@@ -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",
})
}

0 comments on commit 3c166b2

Please sign in to comment.