diff --git a/app/brahma/api/murder/internal/handler/journey_h.go b/app/brahma/api/murder/internal/handler/journey_h.go new file mode 100644 index 0000000..19c4c0e --- /dev/null +++ b/app/brahma/api/murder/internal/handler/journey_h.go @@ -0,0 +1,27 @@ +package handler + +import ( + "fmt" + "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/error_process" + "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/service" + "github.com/gofiber/fiber/v2" + ctxLogger "github.com/luizsuper/ctxLoggers" + "go.uber.org/zap" +) + +func GetJourneyH(ctx *fiber.Ctx) error { + journey, err := service.GetJourney(ctx) + if err != nil { + return err + } + + if err != nil { + ctxLogger.FError(ctx, error_process.ServiceErr, zap.String("", fmt.Sprintf("%+v", err))) + return ctx.JSON(fail(nil)) + } + + return ctx.JSON(success(&Data{ + Elements: journey, + Total: 64, + })) +} diff --git a/app/brahma/api/murder/internal/model/journey.go b/app/brahma/api/murder/internal/model/journey.go index 1a9e338..735bd97 100644 --- a/app/brahma/api/murder/internal/model/journey.go +++ b/app/brahma/api/murder/internal/model/journey.go @@ -1,4 +1,28 @@ package model -type model struct { +import ( + "gorm.io/gorm" +) + +type Journey struct { + ID int `json:"id" gorm:"column:id"` + Shop Shop `gorm:"foreignKey:MID;references:ShopID"` + Scripts Scripts `gorm:"foreignKey:Uuid;references:ScriptID"` + Persons strs `json:"persons" gorm:"column:persons"` + ScriptID string `json:"script_id" gorm:"column:script_id"` + Owner string `json:"owner" gorm:"column:owner"` + ShopID string `json:"shop_id" gorm:"column:shop_id"` + Status int `json:"status" gorm:"column:status"` // 1:进行中 2:已开始 3:已结束 +} + +func (m *Journey) TableName() string { + return "journey" +} + +func GetJourneyM(db *gorm.DB) (*Journey, error) { + j := new(Journey) + + db.Joins("Shop").Joins("Scripts").First(j) + + return j, nil } diff --git a/app/brahma/api/murder/internal/model/shop.go b/app/brahma/api/murder/internal/model/shop.go new file mode 100644 index 0000000..e7821f2 --- /dev/null +++ b/app/brahma/api/murder/internal/model/shop.go @@ -0,0 +1,19 @@ +package model + +type Shop struct { + ShopName string `json:"shop_name" gorm:"column:shop_name"` + ShopAddr string `json:"shop_addr" gorm:"column:shop_addr"` + ShopScore float64 `json:"shop_score" gorm:"column:shop_score"` + Numone string `json:"numone" gorm:"column:numone"` + Numtwo string `json:"numtwo" gorm:"column:numtwo"` + ShopLogo string `json:"shop_logo" gorm:"column:shop_logo"` + ShopCover string `json:"shop_cover" gorm:"column:shop_cover"` + MID string `json:"m_id" gorm:"column:m_id"` + Longtitude float64 `json:"longtitude" gorm:"column:longtitude"` + Latitude float64 `json:"latitude" gorm:"column:latitude"` + ID int `json:"id" gorm:"column:id"` +} + +func (m *Shop) TableName() string { + return "shop" +} diff --git a/app/brahma/api/murder/internal/service/journey.go b/app/brahma/api/murder/internal/service/journey.go new file mode 100644 index 0000000..2b7ca8b --- /dev/null +++ b/app/brahma/api/murder/internal/service/journey.go @@ -0,0 +1,19 @@ +package service + +import ( + "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/gorm_helper" + "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/model" + "github.com/gofiber/fiber/v2" + "gorm.io/gorm" +) + +func GetJourney(ctx *fiber.Ctx) (*model.Journey, error) { + var ( + db *gorm.DB + err error + ) + if db, err = gorm_helper.GetContextDB(ctx); err != nil { + return nil, err + } + return model.GetJourneyM(db) +} diff --git a/app/brahma/api/murder/internal/service/user.go b/app/brahma/api/murder/internal/service/user.go index 4d14937..2d83ac3 100644 --- a/app/brahma/api/murder/internal/service/user.go +++ b/app/brahma/api/murder/internal/service/user.go @@ -4,9 +4,7 @@ import ( "context" "fmt" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/model" - "git.icechen.cn/monorepo/backend/pkg/config" "git.icechen.cn/monorepo/backend/pkg/wx" - ctxLogger "github.com/luizsuper/ctxLoggers" "math/rand" "strconv" "time" @@ -15,15 +13,15 @@ import ( var appMap = make(map[string]Applet) func init() { - a := new(AppletConfig) - err := config.GetConfig(a) - if err != nil { - ctxLogger.Error(nil, err.Error()) - panic(err) - } - for _, v := range a.Apps { - appMap[v.Type] = v - } + //a := new(AppletConfig) + //err := config.GetConfig(a) + //if err != nil { + // ctxLogger.Error(nil, err.Error()) + // panic(err) + //} + //for _, v := range a.Apps { + // appMap[v.Type] = v + //} } type AppletConfig struct { diff --git a/app/brahma/api/murder/main.go b/app/brahma/api/murder/main.go index 08342fd..05f93a1 100755 --- a/app/brahma/api/murder/main.go +++ b/app/brahma/api/murder/main.go @@ -21,6 +21,7 @@ const ( scripts = "/scripts" script = "/script" userInfo = "/userInfo" + journey = "/js" ) var ( @@ -120,6 +121,11 @@ func routerInit() { return handler.Login(ctx) }) + journeyGroup := app.Group(journey) + journeyGroup.Get("", func(ctx *fiber.Ctx) error { + return handler.GetJourneyH(ctx) + }) + } func serverStart() {