|
- /* ******************************************************************************
- * 2019 - present Contributed by Apulis Technology (Shenzhen) Co. LTD
- *
- * This program and the accompanying materials are made available under the
- * terms of the MIT License, which is available at
- * https://www.opensource.org/licenses/MIT
- *
- * See the NOTICE file distributed with this work for additional
- * information regarding copyright ownership.
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- * SPDX-License-Identifier: MIT
- ******************************************************************************/
- package services
-
- import (
- "bytes"
- "encoding/json"
- "net/http"
- "net/url"
- "time"
-
- "github.com/apulis/app/ai-arts-backend/internal/configs"
- "github.com/apulis/app/ai-arts-backend/internal/dto"
- "github.com/apulis/app/ai-arts-backend/internal/utils"
- "github.com/apulis/app/ai-arts-backend/pkg/exports"
- )
-
- var globalAomService = &AomService{}
-
- func GetGlobalAomService() *AomService {
- return globalAomService
- }
-
- type AomService struct{}
-
- func (p *AomService) GetUserGroupResources(req *dto.GetUserGroupResourcesReq, header http.Header) ([]dto.UserGroupResources, *exports.CommResponse, error) {
- defer utils.TimeCost(time.Now(), "AomService.GetUserGroupResources")
- urlpath := configs.GetAppConfig().Resources.Aom + "/user-group-resources"
- u, _ := url.Parse(urlpath)
-
- b, _ := json.Marshal(req)
- r := bytes.NewReader(b)
- u.RawQuery = ParseQueryFromStruct(*req)
-
- resp, err := DoRequest(u.String(), "GET", header, r)
-
- if err != nil {
- return nil, nil, err
- }
- resource := []dto.UserGroupResources{}
- data := dto.BaseListResp{
- Items: &resource,
- }
- commResponse, err := ParseResponse(resp, &data)
- return resource, commResponse, err
- }
-
- func (p *AomService) GetResourceQuotas(req *dto.GetResourceQuotaReq, header http.Header) ([]dto.QuotaItem, *exports.CommResponse, error) {
- defer utils.TimeCost(time.Now(), "AomService.GetResourceQuotas")
- urlpath := configs.GetAppConfig().Resources.Aom + "/resource-quotas"
- u, _ := url.Parse(urlpath)
- b, _ := json.Marshal(req)
- r := bytes.NewReader(b)
- u.RawQuery = ParseQueryFromStruct(*req)
- resp, err := DoRequest(u.String(), "GET", header, r)
- if err != nil {
- return nil, nil, err
- }
- resource := []dto.QuotaItem{}
- data := dto.BaseListResp{
- Items: &resource,
- }
- commResponse, err := ParseResponse(resp, &data)
- return resource, commResponse, err
- }
|