feat: enhance phlebotomy service with database support and new endpoints
This commit is contained in:
parent
c2ba07852b
commit
0786442539
@ -1,6 +1,11 @@
|
||||
package phlebotomy
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NewHandler(srv *Service) *Handler {
|
||||
return &Handler{srv: srv}
|
||||
@ -14,6 +19,34 @@ func (h *Handler) Speech(c *gin.Context) {
|
||||
|
||||
//manual sent response to edge device
|
||||
|
||||
h.srv.Speech(c)
|
||||
device, hasDevice := c.GetPostForm("device")
|
||||
if !hasDevice {
|
||||
err := errors.New("device field is missing") // 將其轉換為 error 型態
|
||||
fmt.Println("Device not filled. Or unauthorized access.", err)
|
||||
c.JSON(404, gin.H{"error": "Resources not found."})
|
||||
return
|
||||
}
|
||||
|
||||
transcribe, hasText := c.GetPostForm("text")
|
||||
if !hasText {
|
||||
err := errors.New("text field is missing") // 將其轉換為 error 型態
|
||||
fmt.Println("Transcribe not filled. Or unauthorized access.", err)
|
||||
c.JSON(406, gin.H{"error": "Form not satisfied with document."})
|
||||
return
|
||||
}
|
||||
|
||||
status, err := h.srv.Speech(device, transcribe)
|
||||
|
||||
}
|
||||
|
||||
func (h *Handler) GetSpeech(c *gin.Context) {
|
||||
//c.GetPostForm("")
|
||||
}
|
||||
|
||||
func (h *Handler) Analysis(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (h *Handler) GetAnalysis(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
@ -4,9 +4,9 @@ import "NTU-H/utils/system"
|
||||
|
||||
type Repository struct {
|
||||
Repository *Repository
|
||||
DB *system.Database
|
||||
}
|
||||
|
||||
func NewRepository(db *system.Database) *Repository {
|
||||
|
||||
return &Repository{}
|
||||
return &Repository{DB: db}
|
||||
}
|
||||
|
||||
@ -4,4 +4,7 @@ import "github.com/gin-gonic/gin"
|
||||
|
||||
func NewPhlebotomyRoute(router *gin.RouterGroup, h *Handler) {
|
||||
router.POST("/speech", h.Speech)
|
||||
router.GET("/getSpeech", h.GetSpeech)
|
||||
router.POST("/aiAnalysis", h.Analysis)
|
||||
router.GET("/getAiAnalysis", h.GetAnalysis)
|
||||
}
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
package phlebotomy
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func NewService(phlebotomyRepository *Repository) *Service {
|
||||
return &Service{
|
||||
phlebotomyRepository: phlebotomyRepository,
|
||||
}
|
||||
}
|
||||
|
||||
func (srv *Service) Speech(c *gin.Context) {
|
||||
func (srv *Service) Speech(deviceID string, transcribe string) (string, error) {
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user