This commit is contained in:
2026-08-15 02:05:43 +08:00
parent 1a5969897a
commit bd5dbf2522
15 changed files with 174 additions and 108 deletions
+23 -2
View File
@@ -10,11 +10,11 @@ import (
)
type APIService struct {
uc *biz.AccessUsecase
uc *biz.APIUsecase
runtime *conf.Runtime
}
func NewAPIService(uc *biz.AccessUsecase, runtime *conf.Runtime) *APIService {
func NewAPIService(uc *biz.APIUsecase, runtime *conf.Runtime) *APIService {
return &APIService{uc: uc, runtime: runtime}
}
@@ -63,6 +63,27 @@ func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*dto.APIRespons
return apiResponses(items), nil
}
func (s *APIService) Groups(ctx context.Context) ([]string, map[string]string, error) {
items, err := s.AllAPI(ctx, false)
if err != nil {
return nil, nil, err
}
seen := make(map[string]bool)
groups := make([]string, 0)
groupAPIMap := make(map[string]string)
for _, item := range items {
if !seen[item.APIGroup] {
seen[item.APIGroup] = true
groups = append(groups, item.APIGroup)
}
parts := strings.Split(item.Path, "/")
if len(parts) > 1 {
groupAPIMap[parts[1]] = item.APIGroup
}
}
return groups, groupAPIMap, nil
}
func (s *APIService) CreateAPIRequest(ctx context.Context, req *dto.APIRequest) (*dto.APIResponse, error) {
value := apiDomain(req)
if err := s.uc.CreateAPI(ctx, value); err != nil {