feat : journey
continuous-integration/drone/push Build is passing Details

master
liuhaotian 2022-01-27 18:30:14 +08:00
parent da57f02191
commit 75c08d02f8
6 changed files with 105 additions and 12 deletions

View File

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

View File

@ -1,4 +1,28 @@
package model 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
} }

View File

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

View File

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

View File

@ -4,9 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/model" "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" "git.icechen.cn/monorepo/backend/pkg/wx"
ctxLogger "github.com/luizsuper/ctxLoggers"
"math/rand" "math/rand"
"strconv" "strconv"
"time" "time"
@ -15,15 +13,15 @@ import (
var appMap = make(map[string]Applet) var appMap = make(map[string]Applet)
func init() { func init() {
a := new(AppletConfig) //a := new(AppletConfig)
err := config.GetConfig(a) //err := config.GetConfig(a)
if err != nil { //if err != nil {
ctxLogger.Error(nil, err.Error()) // ctxLogger.Error(nil, err.Error())
panic(err) // panic(err)
} //}
for _, v := range a.Apps { //for _, v := range a.Apps {
appMap[v.Type] = v // appMap[v.Type] = v
} //}
} }
type AppletConfig struct { type AppletConfig struct {

View File

@ -21,6 +21,7 @@ const (
scripts = "/scripts" scripts = "/scripts"
script = "/script" script = "/script"
userInfo = "/userInfo" userInfo = "/userInfo"
journey = "/js"
) )
var ( var (
@ -120,6 +121,11 @@ func routerInit() {
return handler.Login(ctx) return handler.Login(ctx)
}) })
journeyGroup := app.Group(journey)
journeyGroup.Get("", func(ctx *fiber.Ctx) error {
return handler.GetJourneyH(ctx)
})
} }
func serverStart() { func serverStart() {