github.com/infraboard/keyauth@v0.8.1/apps/domain/request.ext.go (about)

     1  package domain
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/infraboard/mcube/http/request"
     8  
     9  	"github.com/infraboard/keyauth/common/types"
    10  )
    11  
    12  // NewQueryDomainRequest 查询domian列表
    13  func NewQueryDomainRequest(page *request.PageRequest) *QueryDomainRequest {
    14  	return &QueryDomainRequest{
    15  		Page: page,
    16  	}
    17  }
    18  
    19  // Validate 校验请求合法
    20  func (req *QueryDomainRequest) Validate() error {
    21  	return nil
    22  }
    23  
    24  // NewDescribeDomainRequest 查询详情请求
    25  func NewDescribeDomainRequest() *DescribeDomainRequest {
    26  	return &DescribeDomainRequest{}
    27  }
    28  
    29  // NewDescribeDomainRequestWithName 查询详情请求
    30  func NewDescribeDomainRequestWithName(name string) *DescribeDomainRequest {
    31  	return &DescribeDomainRequest{
    32  		Name: name,
    33  	}
    34  }
    35  
    36  // Validate todo
    37  func (req *DescribeDomainRequest) Validate() error {
    38  	if req.Name == "" {
    39  		return fmt.Errorf("name required")
    40  	}
    41  
    42  	return nil
    43  }
    44  
    45  // NewCreateDomainRequest todo
    46  func NewCreateDomainRequest() *CreateDomainRequest {
    47  	return &CreateDomainRequest{
    48  		Profile: &DomainProfile{},
    49  	}
    50  }
    51  
    52  // Validate 校验请求是否合法
    53  func (req *CreateDomainRequest) Validate() error {
    54  	return validate.Struct(req)
    55  }
    56  
    57  // Patch todo
    58  func (req *DomainProfile) Patch(data *DomainProfile) {
    59  	patchData, _ := json.Marshal(data)
    60  	json.Unmarshal(patchData, req)
    61  }
    62  
    63  // NewPutDomainRequest todo
    64  func NewPutDomainRequest() *UpdateDomainInfoRequest {
    65  	return &UpdateDomainInfoRequest{
    66  		UpdateMode: types.UpdateMode_PUT,
    67  	}
    68  }
    69  
    70  // NewPatchDomainRequest todo
    71  func NewPatchDomainRequest() *UpdateDomainInfoRequest {
    72  	return &UpdateDomainInfoRequest{
    73  		UpdateMode: types.UpdateMode_PATCH,
    74  	}
    75  }
    76  
    77  // NewPutDomainSecurityRequest todo
    78  func NewPutDomainSecurityRequest() *UpdateDomainSecurityRequest {
    79  	return &UpdateDomainSecurityRequest{
    80  		UpdateMode:      types.UpdateMode_PUT,
    81  		SecuritySetting: NewDefaultSecuritySetting(),
    82  	}
    83  }
    84  
    85  // NewDeleteDomainRequestByName todo
    86  func NewDeleteDomainRequestByName(name string) *DeleteDomainRequest {
    87  	return &DeleteDomainRequest{
    88  		Name: name,
    89  	}
    90  }
    91  
    92  // Validate todo
    93  func (req *UpdateDomainSecurityRequest) Validate() error {
    94  	return validate.Struct(req)
    95  }
    96  
    97  // Validate 更新校验
    98  func (req *UpdateDomainInfoRequest) Validate() error {
    99  	return validate.Struct(req)
   100  }