feat: enhance phlebotomy service with database support and new endpoints

This commit is contained in:
joyHuang 2026-05-27 19:37:25 +09:00
parent c2ba07852b
commit 0786442539
Signed by: joy
GPG Key ID: E9FF7B8ECF17FD6D
4 changed files with 42 additions and 7 deletions

View File

@ -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) {
}

View File

@ -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}
}

View File

@ -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)
}

View File

@ -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
}