Skip to content

Commit

Permalink
Merge pull request #14 from a-company-jp/invoke-endpoint
Browse files Browse the repository at this point in the history
Invoke Endpointの追加
  • Loading branch information
Shion1305 authored Oct 11, 2024
2 parents 276ca9c + 3c166b2 commit 308369f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 260 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",
})
}
2 changes: 1 addition & 1 deletion pkg/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package model
import "time"

type User struct {
Target
LINEID string `firestore:"line_id"`
Target Target `firestore:"target"`
AddDate time.Time `firestore:"add_date"`
}

Expand Down
43 changes: 0 additions & 43 deletions sample/get-data.go

This file was deleted.

216 changes: 0 additions & 216 deletions sample/main.go

This file was deleted.

0 comments on commit 308369f

Please sign in to comment.