Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-client): Create controller for Project module #370

Merged
merged 20 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
78 changes: 50 additions & 28 deletions packages/api-client/src/controllers/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import client from '@package/client'
import {
CreateProjectRequest,
CreateProjectResponse,
DeleteProjectRequest,
DeleteProjectResponse,
ForkProjectRequest,
ForkProjectResponse,
GetAllProjectsRequest,
GetAllProjectsResponse,
GetForkRequest,
GetForkResponse,
GetProjectRequest,
GetProjectResponse,
UnlinkProjectRequest,
UpdateProjectRequest
UnlinkProjectResponse,
UpdateProjectRequest,
UpdateProjectResponse
} from '@package/types/project.types'

export default class ProjectController {
private static apiClient = client

static async createProject(
request: CreateProjectRequest,
headers: any
): Promise<any> {
return this.apiClient.post(
headers: Record<string, string>
): Promise<CreateProjectResponse> {
return this.apiClient.post<CreateProjectResponse>(
`/api/project/${request.workspaceId}`,
request,
headers
Expand All @@ -26,9 +34,9 @@ export default class ProjectController {

static async updateProject(
request: UpdateProjectRequest,
headers: any
): Promise<any> {
return this.apiClient.put(
headers: Record<string, string>
): Promise<UpdateProjectResponse> {
return this.apiClient.put<UpdateProjectResponse>(
`/api/project/${request.projectId}`,
request,
headers
Expand All @@ -37,23 +45,26 @@ export default class ProjectController {

static async deleteProject(
request: DeleteProjectRequest,
headers: any
): Promise<any> {
headers: Record<string, string>
): Promise<DeleteProjectResponse> {
return this.apiClient.delete(`/api/project/${request.projectId}`, headers)
}

static async getProject(
request: GetProjectRequest,
headers: any
): Promise<any> {
return this.apiClient.get(`/api/project/${request.projectId}`, headers)
headers: Record<string, string>
): Promise<GetProjectResponse> {
return this.apiClient.get<GetProjectResponse>(
`/api/project/${request.projectId}`,
headers
)
}

static async forkProject(
request: ForkProjectRequest,
headers: any
): Promise<any> {
return this.apiClient.post(
headers: Record<string, string>
): Promise<ForkProjectResponse> {
return this.apiClient.post<ForkProjectResponse>(
`/api/project/${request.projectId}/fork`,
request,
headers
Expand All @@ -64,26 +75,37 @@ export default class ProjectController {

static async unlinkFork(
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
request: UnlinkProjectRequest,
headers: any
): Promise<any> {
return this.apiClient.put(
`/api/project/${request.projectId}/unlink-fork`,
request,
headers: Record<string, string>
): Promise<UnlinkProjectResponse> {
return this.apiClient.delete(
`/api/project/${request.projectId}/fork`,
headers
)
}

static async getForks(request: GetForkRequest, headers: any): Promise<any> {
return this.apiClient.get(
`/api/project/${request.projectId}/forks`,
headers
)
static async getForks(
request: GetForkRequest,
headers: Record<string, string>
): Promise<[GetForkResponse]> {
let url = `/api/project/${request.projectId}/forks`
request.page && (url += `page=${request.page}&`)
request.limit && (url += `limit=${request.limit}&`)
request.sort && (url += `sort=${request.sort}&`)
request.order && (url += `order=${request.order}&`)
request.search && (url += `search=${request.search}&`)
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
return this.apiClient.get(url, headers)
}

static async getAllProjects(
request: GetAllProjectsRequest,
headers: any
): Promise<any> {
return this.apiClient.get(`/api/project/all/${request.projectId}`, headers)
headers: Record<string, string>
): Promise<[GetAllProjectsResponse]> {
let url = `/api/project/all/${request.projectId}`
request.page && (url += `page=${request.page}&`)
request.limit && (url += `limit=${request.limit}&`)
request.sort && (url += `sort=${request.sort}&`)
request.order && (url += `order=${request.order}&`)
request.search && (url += `search=${request.search}&`)
return this.apiClient.get(url, headers)
}
}
102 changes: 97 additions & 5 deletions packages/api-client/src/types/project.types.d.ts
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,46 @@ export interface CreateProjectRequest {
environments?: CreateEnvironment[]
}

export interface CreateProjectResponse {}
export interface CreateProjectResponse {
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}

export interface UpdateProjectRequest {
projectId: string
name?: string
}

export interface UpdateProjectResponse {}
export interface UpdateProjectResponse {
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}

export interface DeleteProjectRequest {
projectId: string
Expand All @@ -25,14 +57,46 @@ export interface GetProjectRequest {
projectId: string
}

export interface GetProjectResponse {}
export interface GetProjectResponse {
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}

export interface ForkProjectRequest {
projectId: string
name: string
}

export interface ForkProjectResponse {}
export interface ForkProjectResponse {
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}

export interface SyncProjectRequest {}

Expand All @@ -46,9 +110,37 @@ export interface UnlinkProjectResponse {}

export interface GetForkRequest {
projectId: string
page?: number
limit?: number
sort?: string
order?: string
search?: string
}

export interface GetForkResponse {}
export interface GetForkResponse {
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}
export interface GetAllProjectsRequest {
projectId: string
page?: number
limit?: number
sort?: string
order?: string
search?: string
}

export interface GetAllProjectsResponse {}
Empty file.
Loading