S SmartDocs
系列: Go go 40 行 · 更新於 2026-04-18

dto.go

Go/Baasid/internal/dto/dto.go

// Package dto defines JSON request/response shapes decoupled from GORM models.
//
// Keeping transport types separate from persistence models lets you rename
// database columns without breaking the public API contract from the spec.
package dto

// LoginRequest is the JSON body for POST /auth/login.
type LoginRequest struct {
	Account  string `json:"account" example:"admin"`
	Password string `json:"password" example:"password123"`
}

// LoginResponse is returned in the JSON body on successful login (HTTP 200).
// The JWT itself is returned in the Authorization response header per spec.
type LoginResponse struct {
	Account string `json:"account" example:"admin"`
	Name    string `json:"name" example:"系統管理員"`
}

// GoodsCreateRequest is the JSON body for POST /goods/add.
type GoodsCreateRequest struct {
	GoodsName string `json:"goods_name" example:"Sample Product"`
}

// GoodsUpdateRequest is the JSON body for PUT /goods/{id}.
type GoodsUpdateRequest struct {
	GoodsName string `json:"goods_name" example:"Updated name"`
}

// GoodsResponse is the canonical JSON representation of a product in API responses.
type GoodsResponse struct {
	ID        string `json:"_id" example:"550e8400-e29b-41d4-a716-446655440000"`
	GoodsName string `json:"goods_name" example:"Sample Product"`
}

// ErrorMessage is a simple JSON envelope for non-2xx errors where we still
// want a machine-readable body (Echo's default string body is fine too).
type ErrorMessage struct {
	Message string `json:"message"`
}

相關文章