mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-22 02:27:57 +00:00
44 lines
638 B
Go
44 lines
638 B
Go
package dto
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type ObjectById struct {
|
|
Id int `uri:"id"`
|
|
Ids []int `json:"ids"`
|
|
}
|
|
|
|
func (s *ObjectById) Bind(ctx *gin.Context) error {
|
|
var err error
|
|
err = ctx.ShouldBindUri(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if ctx.Request.Method == http.MethodDelete {
|
|
err = ctx.ShouldBind(&s.Ids)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(s.Ids) > 0 {
|
|
return nil
|
|
}
|
|
if s.Ids == nil {
|
|
s.Ids = make([]int, 0)
|
|
}
|
|
if s.Id != 0 {
|
|
s.Ids = append(s.Ids, s.Id)
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s *ObjectById) GetId() interface{} {
|
|
if len(s.Ids) > 0 {
|
|
return s.Ids
|
|
}
|
|
return s.Id
|
|
}
|