wip: user stuff

This commit is contained in:
loveuer
2025-07-11 22:12:37 +08:00
parent 99cbe8c523
commit b926a8fb80
16 changed files with 447 additions and 3 deletions

29
internal/api/api.go Normal file
View File

@ -0,0 +1,29 @@
package api
import (
"context"
"loveuer/utodo/internal/handler"
"loveuer/utodo/internal/opt"
g_handler "loveuer/utodo/pkg/handler"
"loveuer/utodo/pkg/middleware/trace"
"github.com/gofiber/fiber/v3"
l3 "github.com/gofiber/fiber/v3/middleware/logger"
r3 "github.com/gofiber/fiber/v3/middleware/recover"
)
func New(ctx context.Context) *fiber.App {
app := fiber.New()
app.Use(trace.New())
app.Use(l3.New())
app.Use(r3.New())
app.Get("/healthz", g_handler.Healthz(opt.Cfg.Name, opt.Cfg.Version))
{
api := app.Group("/api/v1/auth")
api.Post("/login", handler.Login())
}
return app
}

View File

@ -2,6 +2,7 @@ package cmd
import (
"context"
"loveuer/utodo/internal/api"
"loveuer/utodo/internal/model"
"loveuer/utodo/internal/opt"
g_api "loveuer/utodo/pkg/api"
@ -34,7 +35,7 @@ func svcRun(cmd *cobra.Command, args []string) error {
return err
}
if err = model.Init(cmd.Context(), db.Default.Session(tool.Timeout(60))); err != nil {
if err = model.Init(cmd.Context(), db.Default.Session(tool.Timeout(60), db.Config{Debug: opt.Cfg.Debug})); err != nil {
return err
}
@ -43,6 +44,7 @@ func svcRun(cmd *cobra.Command, args []string) error {
g_api.WithAddress(opt.Cfg.Svc.Address),
g_api.WithVersion(opt.Cfg.Version),
g_api.WithName(opt.Cfg.Name),
g_api.WithApp(api.New(cmd.Context())),
); err != nil {
return err
}

14
internal/handler/login.go Normal file
View File

@ -0,0 +1,14 @@
package handler
import (
"loveuer/utodo/pkg/logger"
"github.com/gofiber/fiber/v3"
)
func Login() fiber.Handler {
return func(c fiber.Ctx) error {
logger.InfoCtx(c.Context(), "login")
return c.SendString("Hello, World!")
}
}

View File

@ -9,5 +9,7 @@ import (
func Init(ctx context.Context, tx *gorm.DB) error {
return tx.AutoMigrate(
&Todo{},
&User{},
&Object{},
)
}

10
internal/model/object.go Normal file
View File

@ -0,0 +1,10 @@
package model
type Object struct {
Id int64 `json:"id" gorm:"column:id,primaryKey"`
CreatedAt int64 `json:"created_at" gorm:"column:created_at,autoCreateTime:milli"`
Key string `json:"key" gorm:"column:key;type:varchar(32);not null;unique"`
ContentType string `json:"content_type" gorm:"column:content_type;type:varchar(255);not null"`
Size int64 `json:"size" gorm:"column:size"`
Blob []byte `json:"-" gorm:"column:blob;type:blob"`
}

View File

@ -27,7 +27,7 @@ func (t TodoStatus) MarshalJSON() ([]byte, error) {
}
type Todo struct {
Id int64 `json:"id" gorm:"column:id,primaryKey;autoIncrement"`
Id int64 `json:"id" gorm:"column:id,primaryKey"`
CreatedAt int64 `json:"created_at" gorm:"column:created_at,autoCreateTime:milli"`
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at,autoUpdateTime:milli"`
DeletedAt int64 `json:"deleted_at" gorm:"column:deleted_at"`

14
internal/model/user.go Normal file
View File

@ -0,0 +1,14 @@
package model
type User struct {
Id int64 `json:"id" gorm:"column:id,primaryKey"`
CreatedAt int64 `json:"created_at" gorm:"column:created_at,autoCreateTime:milli"`
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at,autoUpdateTime:milli"`
DeletedAt int64 `json:"deleted_at" gorm:"column:deleted_at"`
Username string `json:"username" gorm:"column:username;type:varchar(255);not null"`
Nickname string `json:"nickname" gorm:"column:nickname;type:varchar(255);not null"`
Password string `json:"-" gorm:"column:password;type:varchar(255);not null"`
Avatar string `json:"avatar" gorm:"column:avatar;type:varchar(32);not null"`
Phone string `json:"phone" gorm:"column:phone;type:varchar(16);not null"`
Email string `json:"email" gorm:"column:email;type:varchar(255);not null"`
}