Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/alert/AlertAddAnalysis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const addFile = (event: Event) => {
const uploadFile = async () => {
if (!file.value) return;
loading.value = true;
await $api.curService.uploadFile(file.value);
await $api.curApiClient.uploadFile(file.value);
loading.value = false;
emit("update:analyses");
closeModal();
Expand Down
2 changes: 1 addition & 1 deletion components/comparative/ComparativeByRegion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface Props {
const props = defineProps<Props>();

const resultsByRegion: Ref<RegionCarbonFootprint[]> = ref(
await $api.carbon.compareCarbonFootPrintbByRegion(
await $api.carbonService.compareCarbonFootPrintbByRegion(
props.infrastructureId,
props.totalCO2Gr,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { $api } = useNuxtApp();
const instanceTypes: Ref<string[]> = ref([]);
const isInstanceEmpty = ref(false);

$api.instanceType.getAllInstanceByType("EC2").then((responses) => {
$api.awsInstanceApiClient.getAllInstanceByType("EC2").then((responses) => {
instanceTypes.value = responses.map((response) => response.name);
});

Expand Down
2 changes: 1 addition & 1 deletion components/infrastructure/InfrastructureCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const handleSubmit = form.handleSubmit(async (values) => {
defaultRegion: values.region.id,
name: values.infraName,
};
await $api.infrastructureService.createNewInfra(infra);
await $api.infrastructureApiClient.createNewInfra(infra);
await infrastructuresStore.fetchInfrastructures();
isDialogOpen.value = false;
emit("infraCreated");
Expand Down
2 changes: 1 addition & 1 deletion components/infrastructure/InfrastructureDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function deleteInfrastructure(infrastructure: Infrastructure) {
}

async function confirmInfrastructureDeletion(infrastructure: Infrastructure) {
await $api.infrastructureService.deleteInfra(infrastructure.id!);
await $api.infrastructureApiClient.deleteInfra(infrastructure.id!);
await infrastructuresStore.fetchInfrastructures();
}

Expand Down
2 changes: 1 addition & 1 deletion pages/admin/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const notificationHandler = useToast();
const { $api } = useNuxtApp();

const clearCache = async () => {
await $api.adminService.evictRegionCache().then(() =>
await $api.adminApiClient.evictRegionCache().then(() =>
notificationHandler.add({
title: $t("admin.regionCache.notifyCleared"),
color: NuxtColors.success,
Expand Down
4 changes: 2 additions & 2 deletions pages/calculatrice/estimation/[infrastructureID]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const infrastructureId: string = Array.isArray(route.params.infrastructureID)
: route.params.infrastructureID;

const results = ref(
await $api.carbon.estimateCarbonFootPrint(infrastructureId),
await $api.carbonService.estimateCarbonFootPrint(infrastructureId),
);

infrastructure.value =
await $api.infrastructureService.getInfrastructure(infrastructureId);
await $api.infrastructureApiClient.getInfrastructure(infrastructureId);
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const route = useRoute();

const services = ref<CloudServiceProviderService[]>([]);
services.value =
await $api.cloudServiceProviderService.getCloudServiceProviderServices();
await $api.cloudServiceProviderApiClient.getCloudServiceProviderServices();

const goToComponentConfiguration = (
cloudServiceProviderService: CloudServiceProviderService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ const { cloudServiceProviderServiceID, componentId, serviceName } =
route.query as QueryParams;

const components = ref(
await $api.componentService.getComponentsByInfrastructureId(infrastructureId),
await $api.componentApiClient.getComponentsByInfrastructureId(
infrastructureId,
),
);

const originalComponent = components.value.find(
Expand All @@ -133,7 +135,7 @@ const isOtherRegion = ref(
);

const serviceConfigurationSettings = ref<ServiceConfigurationSetting[]>(
await $api.serviceConfigurationSettingSvc.findAllConfigurationSettingsByServiceId(
await $api.serviceConfigurationSettingApiClient.findAllConfigurationSettingsByServiceId(
originalComponent
? originalComponent.serviceID
: cloudServiceProviderServiceID,
Expand Down Expand Up @@ -171,12 +173,12 @@ const handleSubmit = async () => {
serviceID: cloudServiceProviderServiceID,
};
if (originalComponent) {
await $api.componentService.updateComponent({
await $api.componentApiClient.updateComponent({
...component,
id: originalComponent.id,
});
} else {
await $api.componentService.saveComponent(component);
await $api.componentApiClient.saveComponent(component);
}
await navigateTo(`/calculatrice/infrastructure/${infrastructureId}`);
};
Expand Down
10 changes: 6 additions & 4 deletions pages/calculatrice/infrastructure/[infrastructureID]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ const infrastructureId: string = Array.isArray(route.params.infrastructureID)

const { $api } = useNuxtApp();
const components = ref(
await $api.componentService.getComponentsByInfrastructureId(infrastructureId),
await $api.componentApiClient.getComponentsByInfrastructureId(
infrastructureId,
),
);

const componentToDelete = ref<string>("");
Expand All @@ -134,18 +136,18 @@ const addComponent = () => {
};

async function deleteComponent() {
await useNuxtApp().$api.componentService.deleteComponent(
await useNuxtApp().$api.componentApiClient.deleteComponent(
componentToDelete.value,
);
components.value =
await $api.componentService.getComponentsByInfrastructureId(
await $api.componentApiClient.getComponentsByInfrastructureId(
infrastructureId,
);
}
const navigateToEdit = async (component: Component) => {
const { id: componentId, serviceID } = component;
const serviceName =
(await $api.catalogService.getById(serviceID)).shortname ?? "";
(await $api.catalogApiClient.getById(serviceID)).shortname ?? "";
navigateTo({
path: `/calculatrice/infrastructure/${infrastructureId}/create-component`,
query: {
Expand Down
2 changes: 1 addition & 1 deletion pages/catalog/[serviceId]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const {
const id: string = Array.isArray(serviceId) ? serviceId[0] : serviceId;

const service: Ref<ServiceDescription> = ref(
await $api.catalogService.getById(id),
await $api.catalogApiClient.getById(id),
);
</script>

Expand Down
4 changes: 1 addition & 3 deletions pages/catalog/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ definePageMeta({
layout: "public",
});

// const services: Ref<ServiceCatalog[]> = ref([]);

const { $api, $router } = useNuxtApp();

const services = ref(await $api.catalogService.getAllServices());
const services = ref(await $api.catalogApiClient.getAllServices());

const toDescription = (id: string) => {
$router.push(`catalog/${id}`);
Expand Down
68 changes: 39 additions & 29 deletions plugins/02-irocalcApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,36 @@ import { createFetch } from "ofetch";
import { defineNuxtPlugin } from "#app";
import AWSDataCenterService from "../service/awsDataCenterService";
import CarbonService from "~/service/carbonService";
import CatalogService from "~/service/catalogService";
import AWSInstanceService from "~/service/awsInstanceService";
import AdminService from "~/service/adminService";
import CatalogApiClient from "~/service/api/catalogApiClient";
import AWSInstanceApiClient from "~/service/api/AWSInstanceApiClient";
import AdminApiClient from "~/service/api/adminApiClient";
import { useAuth } from "vue-clerk";
import InfrastructureService from "~/service/infrastructureService";
import CloudServiceProviderSvc from "~/service/CloudServiceProviderService";
import ServiceConfigurationSettingSvc from "~/service/ServiceConfigurationSettingService";
import ComponentService from "~/service/componentService";
import InfrastructureApiClient from "~/service/api/infrastructureApiClient";
import CloudServiceProviderApiClient from "~/service/api/CloudServiceProviderApiClient";
import ServiceConfigurationSettingApiClient from "~/service/api/ServiceConfigurationSettingApiClient";
import ComponentApiClient from "~/service/api/componentApiClient";
import AnalysisService from "~/service/analysisService";
import CurService from "~/service/curService";
import CurApiClient from "~/service/api/curApiClient";
import TokenService from "~/service/tokenService";
import ScanService from "~/service/scanService";
import { AnalysisApiClient } from "~/service/api/analysisApiClient";
import { AWSDataCenterApiClient } from "~/service/api/AWSDataCenterApiClient";
import { IrocalcCarbonApiClient } from "~/service/api/irocalcCarbonApiClient";
import ScanApiClient from "~/service/api/scanApiClient";

/** ApiInstance interface provides us with good typing */
interface IApiInstance {
awsDataCenter: AWSDataCenterService;
carbon: CarbonService;
catalogService: CatalogService;
instanceType: AWSInstanceService;
adminService: AdminService;
infrastructureService: InfrastructureService;
componentService: ComponentService;
cloudServiceProviderService: CloudServiceProviderSvc;
serviceConfigurationSettingSvc: ServiceConfigurationSettingSvc;
carbonService: CarbonService;
catalogApiClient: CatalogApiClient;
awsInstanceApiClient: AWSInstanceApiClient;
adminApiClient: AdminApiClient;
infrastructureApiClient: InfrastructureApiClient;
componentApiClient: ComponentApiClient;
cloudServiceProviderApiClient: CloudServiceProviderApiClient;
serviceConfigurationSettingApiClient: ServiceConfigurationSettingApiClient;
analysisService: AnalysisService;
curService: CurService;
curApiClient: CurApiClient;
tokenService: TokenService;
scanService: ScanService;
}
Expand Down Expand Up @@ -95,23 +99,29 @@ export default defineNuxtPlugin({
},
});

const infrastructureApiClient = new InfrastructureApiClient(apiFetcher);

/** an object containing all repositories we need to expose */
const modules: IApiInstance = {
carbon: new CarbonService(apiFetcher),
awsDataCenter: new AWSDataCenterService(apiFetcher),
catalogService: new CatalogService(apiFetcher),
instanceType: new AWSInstanceService(apiFetcher),
adminService: new AdminService(apiFetcher),
infrastructureService: new InfrastructureService(apiFetcher),
componentService: new ComponentService(apiFetcher),
cloudServiceProviderService: new CloudServiceProviderSvc(apiFetcher),
serviceConfigurationSettingSvc: new ServiceConfigurationSettingSvc(
carbonService: new CarbonService(new IrocalcCarbonApiClient(apiFetcher)),
awsDataCenter: new AWSDataCenterService(
infrastructureApiClient,
new AWSDataCenterApiClient(apiFetcher),
),
catalogApiClient: new CatalogApiClient(apiFetcher),
awsInstanceApiClient: new AWSInstanceApiClient(apiFetcher),
adminApiClient: new AdminApiClient(apiFetcher),
infrastructureApiClient: infrastructureApiClient,
componentApiClient: new ComponentApiClient(apiFetcher),
cloudServiceProviderApiClient: new CloudServiceProviderApiClient(
apiFetcher,
),
analysisService: new AnalysisService(apiFetcher),
curService: new CurService(apiFetcher),
serviceConfigurationSettingApiClient:
new ServiceConfigurationSettingApiClient(apiFetcher),
analysisService: new AnalysisService(new AnalysisApiClient(apiFetcher)),
curApiClient: new CurApiClient(apiFetcher),
tokenService: new TokenService(apiFetcher),
scanService: new ScanService(apiFetcher),
scanService: new ScanService(new ScanApiClient(apiFetcher)),
};

return {
Expand Down
24 changes: 13 additions & 11 deletions service/analysisService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,39 @@
* SPDX-License-Identifier: Apache-2.0
*/

import HttpFactory from "./factory/httpFactory";
import type { ReportStatus } from "~/type/ReportStatus";
import type { Payload } from "~/type/Payload";
import type { AnalysisApiClient } from "~/service/api/analysisApiClient";

type Analysis = {
export type Analysis = {
status: ReportStatus;
id: string;
dateCreation: string;
co2Gr: number;
};

type AnalysisDetails = Analysis & {
export type AnalysisDetails = Analysis & {
payloads: Payload[];
};

class AnalysisService extends HttpFactory {
private readonly RESOURCE = "/api/analysis";
class AnalysisService {
private readonly analysisApiClient: AnalysisApiClient;

constructor(analysisApiClient: AnalysisApiClient) {
this.analysisApiClient = analysisApiClient;
}

async getAllAnalyses() {
const analyses = await this.getCall<Analysis[]>(this.RESOURCE);
const analysesWithCO2Converted = analyses.map((analysis) => ({
const analyses = await this.analysisApiClient.getAllAnalyses();
return analyses.map((analysis) => ({
...analysis,
co2Converted: convertEstimateToBestMassUnit(analysis.co2Gr),
}));

return analysesWithCO2Converted;
}

async getAnalysisById(analysisId: string) {
const estimated = (
await this.getCall<AnalysisDetails>(`${this.RESOURCE}/${analysisId}`)
await this.analysisApiClient.getAnalysisById(analysisId)
).payloads.map((p) => ({
label: p.name,
co2Gr: p.carbonGramFootprint,
Expand All @@ -61,7 +63,7 @@ class AnalysisService extends HttpFactory {
}

async deleteAnalysis(analysisId: string): Promise<void> {
return await this.deleteCall(`${this.RESOURCE}/${analysisId}`);
return await this.analysisApiClient.deleteAnalysis(analysisId);
}
}

Expand Down
10 changes: 10 additions & 0 deletions service/api/AWSDataCenterApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ApiClient from "~/service/api/apiClient";
import type { Region } from "~/type/Region";

export class AWSDataCenterApiClient extends ApiClient {
private readonly RESOURCE = "/api/cloud-service-providers";

async getAllAWSDataCenter(cspId: string): Promise<Region[]> {
return await this.getCall<Region[]>(`${this.RESOURCE}/${cspId}/regions`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import HttpFactory from "./factory/httpFactory";
import ApiClient from "./apiClient";
import type { EC2InstanceType } from "~/type/ec2InstanceType";

class AWSInstanceService extends HttpFactory {
class AWSInstanceApiClient extends ApiClient {
private readonly RESOURCE = "/api/awsInstanceType";

async getAllInstanceByType(
Expand All @@ -28,4 +28,4 @@ class AWSInstanceService extends HttpFactory {
}
}

export default AWSInstanceService;
export default AWSInstanceApiClient;
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import HttpFactory from "./factory/httpFactory";
import ApiClient from "./apiClient";
import type { CloudServiceProvider } from "~/type/infrastructure/CloudServiceProvider";
import type { CloudServiceProviderService } from "~/type/infrastructure/CloudServiceProviderService";

class CloudServiceProviderSvc extends HttpFactory {
class CloudServiceProviderApiClient extends ApiClient {
private readonly RESOURCE = "/api/cloud-service-providers";

async getCloudServiceProviders(): Promise<CloudServiceProvider[]> {
Expand All @@ -35,4 +35,4 @@ class CloudServiceProviderSvc extends HttpFactory {
}
}

export default CloudServiceProviderSvc;
export default CloudServiceProviderApiClient;
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import HttpFactory from "./factory/httpFactory";
import ApiClient from "./apiClient";
import type { ServiceConfigurationSetting } from "~/type/infrastructure/ServiceConfigurationSetting";

class ServiceConfigurationSettingSvc extends HttpFactory {
class ServiceConfigurationSettingApiClient extends ApiClient {
private readonly RESOURCE = "/api/service-configuration-settings";

async findAllConfigurationSettingsByServiceId(
Expand All @@ -30,4 +30,4 @@ class ServiceConfigurationSettingSvc extends HttpFactory {
}
}

export default ServiceConfigurationSettingSvc;
export default ServiceConfigurationSettingApiClient;
Loading