修复配送端合同与用户管理问题
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// 功能描述:实现配送点范围内的用户、服务关系和收货地址管理。
|
||||
// 版本:v1.1.0。
|
||||
// 版本:v1.2.0。
|
||||
package delivery
|
||||
|
||||
import (
|
||||
@@ -12,9 +12,25 @@ import (
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/upload"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const deliveryUserUsernameConstraint = "idx_user_account_username"
|
||||
|
||||
var errDeliveryUserUsernameExists = errors.New("用户名已存在,请更换用户名")
|
||||
|
||||
// deliveryUserCreateError 仅转换配送点新建用户时的用户名唯一约束冲突。
|
||||
// 参数:err 为用户和服务关系事务返回的错误。
|
||||
// 返回值:用户名冲突返回中文提示,其他错误保持原样。
|
||||
func deliveryUserCreateError(err error) error {
|
||||
var postgresError *pgconn.PgError
|
||||
if errors.As(err, &postgresError) && postgresError.Code == "23505" && postgresError.ConstraintName == deliveryUserUsernameConstraint {
|
||||
return errDeliveryUserUsernameExists
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func userQuery(pointID uint64) *gorm.DB {
|
||||
return common.ActiveRecords(db().Model(&models.UserAccount{})).
|
||||
Joins("JOIN user_service_relation ON user_service_relation.user_account_id = user_account.id AND user_service_relation.status <> ?",
|
||||
@@ -116,7 +132,7 @@ func CreateUser(ctx *gin.Context) {
|
||||
relation.UserAccountID = user.ID
|
||||
return tx.Create(&relation).Error
|
||||
}); err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
infra.Response.Error(ctx, deliveryUserCreateError(err))
|
||||
return
|
||||
}
|
||||
common.RespondCreatedResource(ctx, user)
|
||||
|
||||
Reference in New Issue
Block a user