feat: integrate database and service layer for phlebotomy module
This commit is contained in:
parent
4badef89bd
commit
c2ba07852b
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.25.0
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.12.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/mattn/go-sqlite3 v1.14.44
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
2
go.sum
2
go.sum
@ -40,6 +40,8 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.44 h1:3VSe+xafpbzsLbdr2AWlAZk9yRHiBhTBakioXaCKTF8=
|
||||
github.com/mattn/go-sqlite3 v1.14.44/go.mod h1:pjEuOr8IwzLJP2MfGeTb0A35jauH+C2kbHKBr7yXKVQ=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
|
||||
18
main.go
18
main.go
@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
env := godotenv.Load()
|
||||
if env != nil {
|
||||
panic(env)
|
||||
@ -24,6 +25,9 @@ func main() {
|
||||
log := system.NewLogModel()
|
||||
|
||||
log.Startup()
|
||||
|
||||
dbms := system.NewDatabase()
|
||||
|
||||
route := gin.Default()
|
||||
route.Use(
|
||||
gin.Recovery(),
|
||||
@ -33,16 +37,20 @@ func main() {
|
||||
apiRoute := route.Group("/api/v1")
|
||||
{
|
||||
|
||||
phlebotomyHandler := phlebotomy.NewHandler()
|
||||
phlebotomyRepository := phlebotomy.NewRepository(dbms)
|
||||
phlebotomyService := phlebotomy.NewService(phlebotomyRepository)
|
||||
phlebotomyHandler := phlebotomy.NewHandler(phlebotomyService)
|
||||
|
||||
phlebotomy.NewPhlebotomyRoute(apiRoute, phlebotomyHandler)
|
||||
|
||||
}
|
||||
|
||||
route.Group("/api/v1").POST("/speech", func(c *gin.Context) {
|
||||
log.Print(1, "speech")
|
||||
})
|
||||
//route.Group("/api/v1").POST("/speech", func(c *gin.Context) {
|
||||
// log.Print(1, "speech")
|
||||
//})
|
||||
|
||||
err := route.Run(":" + "1231")
|
||||
port := os.Getenv("PORT")
|
||||
err := route.Run(":" + port)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -2,10 +2,18 @@ package phlebotomy
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func NewHandler() *Handler {
|
||||
return &Handler{}
|
||||
func NewHandler(srv *Service) *Handler {
|
||||
return &Handler{srv: srv}
|
||||
}
|
||||
|
||||
func (h *Handler) Speech(c *gin.Context) {
|
||||
|
||||
// Expect will receive a audio file
|
||||
// Keep the file with hash name and mapping in db
|
||||
// Wait for worker fetch file and process
|
||||
|
||||
//manual sent response to edge device
|
||||
|
||||
h.srv.Speech(c)
|
||||
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package phlebotomy
|
||||
|
||||
type Handler struct {
|
||||
Handler *Handler
|
||||
srv *Service
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Service *Service
|
||||
Service *Service
|
||||
phlebotomyRepository *Repository
|
||||
}
|
||||
|
||||
@ -1 +1,12 @@
|
||||
package phlebotomy
|
||||
|
||||
import "NTU-H/utils/system"
|
||||
|
||||
type Repository struct {
|
||||
Repository *Repository
|
||||
}
|
||||
|
||||
func NewRepository(db *system.Database) *Repository {
|
||||
|
||||
return &Repository{}
|
||||
}
|
||||
|
||||
@ -2,6 +2,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) {
|
||||
|
||||
}
|
||||
|
||||
26
utils/system/database.go
Normal file
26
utils/system/database.go
Normal file
@ -0,0 +1,26 @@
|
||||
package system
|
||||
|
||||
import "database/sql"
|
||||
import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
Database *sql.DB
|
||||
}
|
||||
|
||||
func NewDatabase() *Database {
|
||||
db := &Database{}
|
||||
|
||||
//dbs, err := sql.Open("sqlite3", "./data.db")
|
||||
|
||||
dbs, err := sql.Open("postgres", "postgres://backend:password@192.168.50.94:5432/backend?sslmode=disable")
|
||||
|
||||
db.Database = dbs
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user