feat/ajout-de-fonctionnalites (#1)
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
Reviewed-on: #1 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #1.
This commit is contained in:
41
frontend/services/applications.ts
Normal file
41
frontend/services/applications.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { Application, ApplicationWrite } from './dto/application'
|
||||
import { type HydraCollection, extractHydraMembers } from '~/utils/api'
|
||||
|
||||
export function getApplications(): Promise<Application[]> {
|
||||
const api = useApi()
|
||||
return api.get<Application[]>('/applications', undefined, {
|
||||
toast: false,
|
||||
}).then((response) => {
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
return extractHydraMembers(response as HydraCollection<Application>)
|
||||
})
|
||||
}
|
||||
|
||||
export function getApplication(slug: string): Promise<Application> {
|
||||
return useApi().get<Application>(`/applications/${slug}`, undefined, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
|
||||
export function createApplication(data: ApplicationWrite): Promise<Application> {
|
||||
return useApi().post<Application>('/applications', data, {
|
||||
toastSuccessKey: 'success.applications.create',
|
||||
toastErrorKey: 'errors.applications.create',
|
||||
})
|
||||
}
|
||||
|
||||
export function updateApplication(slug: string, data: Partial<ApplicationWrite>): Promise<Application> {
|
||||
return useApi().patch<Application>(`/applications/${slug}`, data, {
|
||||
toastSuccessKey: 'success.applications.update',
|
||||
toastErrorKey: 'errors.applications.update',
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteApplication(slug: string): Promise<void> {
|
||||
return useApi().delete<void>(`/applications/${slug}`, undefined, {
|
||||
toastSuccessKey: 'success.applications.delete',
|
||||
toastErrorKey: 'errors.applications.delete',
|
||||
})
|
||||
}
|
||||
13
frontend/services/dashboard.ts
Normal file
13
frontend/services/dashboard.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { DashboardResponse, EnvironmentHealth } from './dto/dashboard'
|
||||
|
||||
export function getDashboard(): Promise<DashboardResponse> {
|
||||
return useApi().get<DashboardResponse>('/dashboard', undefined, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
|
||||
export function getEnvironmentHealth(envId: number): Promise<EnvironmentHealth> {
|
||||
return useApi().get<EnvironmentHealth>(`/environments/${envId}/health`, undefined, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
13
frontend/services/deploy.ts
Normal file
13
frontend/services/deploy.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { TagListResponse, DeployResult } from './dto/deploy'
|
||||
|
||||
export function getAvailableTags(slug: string): Promise<TagListResponse> {
|
||||
return useApi().get<TagListResponse>(`/applications/${slug}/tags`, undefined, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
|
||||
export function deploy(envId: number, tag: string): Promise<DeployResult> {
|
||||
return useApi().post<DeployResult>(`/environments/${envId}/deploy`, { tag }, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
46
frontend/services/dto/application.ts
Normal file
46
frontend/services/dto/application.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
type LogFile = {
|
||||
id?: number
|
||||
label: string
|
||||
path: string
|
||||
}
|
||||
|
||||
type Environment = {
|
||||
id?: number
|
||||
'@id'?: string
|
||||
name: string
|
||||
containerName: string
|
||||
deployScriptPath: string
|
||||
maintenanceFilePath: string
|
||||
appUrl?: string
|
||||
logFiles: LogFile[]
|
||||
maintenance: boolean
|
||||
}
|
||||
|
||||
type EnvironmentWrite = {
|
||||
name: string
|
||||
containerName: string
|
||||
deployScriptPath: string
|
||||
maintenanceFilePath: string
|
||||
appUrl?: string
|
||||
logFiles: LogFile[]
|
||||
}
|
||||
|
||||
type Application = {
|
||||
id?: number
|
||||
'@id'?: string
|
||||
slug: string
|
||||
name: string
|
||||
registryImage: string
|
||||
description?: string
|
||||
giteaUrl?: string
|
||||
createdAt?: string
|
||||
environments?: Environment[]
|
||||
}
|
||||
|
||||
type ApplicationWrite = {
|
||||
name: string
|
||||
slug: string
|
||||
registryImage: string
|
||||
description?: string
|
||||
giteaUrl?: string
|
||||
}
|
||||
27
frontend/services/dto/dashboard.ts
Normal file
27
frontend/services/dto/dashboard.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
type DashboardEnvironment = {
|
||||
id: number
|
||||
name: string
|
||||
status: string
|
||||
version: string
|
||||
}
|
||||
|
||||
type DashboardApplication = {
|
||||
name: string
|
||||
slug: string
|
||||
giteaUrl?: string
|
||||
environments: DashboardEnvironment[]
|
||||
}
|
||||
|
||||
type DashboardResponse = {
|
||||
applications: DashboardApplication[]
|
||||
}
|
||||
|
||||
type EnvironmentHealth = {
|
||||
status: string
|
||||
version: string
|
||||
startedAt: string
|
||||
cpuPercent: number
|
||||
memoryUsage: string
|
||||
memoryLimit: string
|
||||
memoryPercent: number
|
||||
}
|
||||
9
frontend/services/dto/deploy.ts
Normal file
9
frontend/services/dto/deploy.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
type TagListResponse = {
|
||||
tags: string[]
|
||||
}
|
||||
|
||||
type DeployResult = {
|
||||
success: boolean
|
||||
output: string
|
||||
tag: string
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
export type ManagedApplication = {
|
||||
slug: string
|
||||
name: string
|
||||
maintenance: boolean
|
||||
}
|
||||
|
||||
export type ManagedApplicationCollection = {
|
||||
'hydra:member'?: ManagedApplication[]
|
||||
member?: ManagedApplication[]
|
||||
}
|
||||
36
frontend/services/environments.ts
Normal file
36
frontend/services/environments.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { Environment, EnvironmentWrite } from './dto/application'
|
||||
|
||||
export function createEnvironment(appSlug: string, data: EnvironmentWrite): Promise<Environment> {
|
||||
return useApi().post<Environment>(`/applications/${appSlug}/environments`, data, {
|
||||
toastSuccessKey: 'success.environments.create',
|
||||
toastErrorKey: 'errors.environments.create',
|
||||
})
|
||||
}
|
||||
|
||||
export function updateEnvironment(id: number, data: Partial<EnvironmentWrite>): Promise<Environment> {
|
||||
return useApi().patch<Environment>(`/environments/${id}`, data, {
|
||||
toastSuccessKey: 'success.environments.update',
|
||||
toastErrorKey: 'errors.environments.update',
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteEnvironment(id: number): Promise<void> {
|
||||
return useApi().delete<void>(`/environments/${id}`, undefined, {
|
||||
toastSuccessKey: 'success.environments.delete',
|
||||
toastErrorKey: 'errors.environments.delete',
|
||||
})
|
||||
}
|
||||
|
||||
export function toggleMaintenance(id: number, maintenance: boolean): Promise<Environment> {
|
||||
const successKey = maintenance
|
||||
? 'success.environments.activateMaintenance'
|
||||
: 'success.environments.deactivateMaintenance'
|
||||
const errorKey = maintenance
|
||||
? 'errors.environments.activateMaintenance'
|
||||
: 'errors.environments.deactivateMaintenance'
|
||||
|
||||
return useApi().post<Environment>(`/environments/${id}/maintenance`, { maintenance }, {
|
||||
toastSuccessKey: successKey,
|
||||
toastErrorKey: errorKey,
|
||||
})
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import type { ManagedApplication, ManagedApplicationCollection } from './dto/managed-application'
|
||||
|
||||
function normalizeManagedApplications(response: ManagedApplication[] | ManagedApplicationCollection): ManagedApplication[] {
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
return response['hydra:member'] ?? response.member ?? []
|
||||
}
|
||||
|
||||
export async function getManagedApplications(): Promise<ManagedApplication[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<ManagedApplication[] | ManagedApplicationCollection>('/applications')
|
||||
|
||||
return normalizeManagedApplications(response)
|
||||
}
|
||||
|
||||
export function setApplicationMaintenance(slug: string, maintenance: boolean) {
|
||||
const api = useApi()
|
||||
|
||||
return api.post<ManagedApplication>(
|
||||
`/applications/${slug}/maintenance`,
|
||||
{ maintenance },
|
||||
{
|
||||
toastSuccessKey: maintenance
|
||||
? 'success.applications.activateMaintenance'
|
||||
: 'success.applications.deactivateMaintenance',
|
||||
toastErrorKey: maintenance
|
||||
? 'errors.applications.activateMaintenance'
|
||||
: 'errors.applications.deactivateMaintenance'
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user