Selaa lähdekoodia

refactor(api/v1/cc.go): 修改 CCStateRequest 结构体- 将 CCStateRequest 中的 Ip 字段改为 Ips,类型从 string 改为 []string
- 更新相关的服务层逻辑,以适应新的请求结构

fusu 3 viikkoa sitten
vanhempi
sitoutus
34c00308cf
2 muutettua tiedostoa jossa 6 lisäystä ja 6 poistoa
  1. 1 1
      api/v1/cc.go
  2. 5 5
      internal/service/cc.go

+ 1 - 1
api/v1/cc.go

@@ -29,7 +29,7 @@ type CCListResponse struct {
 
 type CCStateRequest struct {
 	Uid int64 `json:"uid" form:"uid" validate:"required"`
-	Ip string `json:"ip" form:"ip" validate:"required"`
+	Ips[] string `json:"ip" form:"ip" validate:"required"`
 	HostId int64 `json:"hostId" form:"hostId" validate:"required"`
 	WebId int64 `json:"webId" form:"webId" validate:"required"`
 }

+ 5 - 5
internal/service/cc.go

@@ -10,7 +10,7 @@ import (
 
 type CcService interface {
 	GetCcList(ctx context.Context, req v1.CCListRequest) ([]v1.CCListResponse, error)
-	EditCcState(ctx context.Context, req []v1.CCStateRequest) error
+	EditCcState(ctx context.Context, req v1.CCStateRequest) error
 }
 func NewCcService(
     service *Service,
@@ -57,16 +57,16 @@ func (s *ccService) GetCcList(ctx context.Context, req v1.CCListRequest) ([]v1.C
 	return res, nil
 }
 
-func (s *ccService) EditCcState(ctx context.Context, req []v1.CCStateRequest) error {
-	for _, v := range req {
-		webData, err := s.webForwardingRep.GetWebForwarding(ctx, v.WebId)
+func (s *ccService) EditCcState(ctx context.Context, req v1.CCStateRequest) error {
+	for _, v := range req.Ips {
+		webData, err := s.webForwardingRep.GetWebForwarding(ctx, req.WebId)
 		if err != nil {
 			return err
 		}
 		if webData.CdnWebId == 0 {
 			return fmt.Errorf("网站不存在")
 		}
-		err = s.ccRepository.EditCcState(ctx, int64(webData.CdnWebId), v.Ip)
+		err = s.ccRepository.EditCcState(ctx, int64(webData.CdnWebId), v)
 		if err != nil {
 			return err
 		}