|
|
@@ -0,0 +1,58 @@
|
|
|
+package model
|
|
|
+
|
|
|
+import "time"
|
|
|
+
|
|
|
+type OrderStatus string
|
|
|
+
|
|
|
+const (
|
|
|
+ StatusPending OrderStatus = "pending"
|
|
|
+ StatusAccepted OrderStatus = "accepted"
|
|
|
+ StatusCanceled OrderStatus = "canceled"
|
|
|
+)
|
|
|
+
|
|
|
+type Order struct {
|
|
|
+ ID string `json:"id"`
|
|
|
+ Status OrderStatus `json:"status"`
|
|
|
+ ServiceTime time.Time `json:"service_time"`
|
|
|
+ Duration int `json:"duration"`
|
|
|
+ Address string `json:"address"`
|
|
|
+ ProviderID *string `json:"provider_id"`
|
|
|
+ CreatedAt time.Time `json:"created_at"`
|
|
|
+ UpdatedAt time.Time `json:"updated_at"`
|
|
|
+}
|
|
|
+
|
|
|
+type CreateOrderRequest struct {
|
|
|
+ ServiceTime time.Time `json:"service_time" binding:"required"`
|
|
|
+ Duration int `json:"duration" binding:"required,gt=0"`
|
|
|
+ Address string `json:"address" binding:"required"`
|
|
|
+}
|
|
|
+
|
|
|
+type AcceptOrderRequest struct {
|
|
|
+ ProviderID string `json:"provider_id" binding:"required"`
|
|
|
+}
|
|
|
+
|
|
|
+type CancelOrderRequest struct{}
|
|
|
+
|
|
|
+type AppError struct {
|
|
|
+ Code string `json:"error"`
|
|
|
+ Message string `json:"message"`
|
|
|
+ HTTPStatus int `json:"-"`
|
|
|
+}
|
|
|
+
|
|
|
+func NewAppError(code, message string, httpStatus int) *AppError {
|
|
|
+ return &AppError{Code: code, Message: message, HTTPStatus: httpStatus}
|
|
|
+}
|
|
|
+
|
|
|
+func (e *AppError) Error() string {
|
|
|
+ return e.Message
|
|
|
+}
|
|
|
+
|
|
|
+// 预定义错误
|
|
|
+var (
|
|
|
+ ErrNotFound = NewAppError("not_found", "订单不存在", 404)
|
|
|
+ ErrConflict = NewAppError("conflict", "订单已被其他服务者接单", 409)
|
|
|
+ ErrInvalidState = func(op string) *AppError {
|
|
|
+ return NewAppError("invalid_state", "订单已取消,无法" + op, 400)
|
|
|
+ }
|
|
|
+ ErrStatusConflict = NewAppError("conflict", "订单状态已变更,请重试", 409)
|
|
|
+)
|