Skip to content

Commit 0aca6ca

Browse files
Get all projects with GET /projects (#70)
* get all path * Update apps/backend/lambdas/projects/test/crud.test.ts Co-authored-by: Nour Shoreibah <[email protected]> * Update apps/backend/lambdas/projects/package.json Co-authored-by: Nour Shoreibah <[email protected]> --------- Co-authored-by: Nour Shoreibah <[email protected]>
1 parent f97bb60 commit 0aca6ca

File tree

8 files changed

+4609
-128
lines changed

8 files changed

+4609
-128
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* This file was generated by kysely-codegen.
3+
* Please do not edit it manually.
4+
*/
5+
6+
import type { ColumnType } from "kysely";
7+
8+
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
9+
? ColumnType<S, I | undefined, U>
10+
: ColumnType<T, T | undefined, T>;
11+
12+
export type Numeric = ColumnType<string, number | string, number | string>;
13+
14+
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
15+
16+
export interface BranchDonors {
17+
contact_email: string | null;
18+
contact_name: string | null;
19+
created_at: Generated<Timestamp | null>;
20+
donor_id: Generated<number>;
21+
organization: string;
22+
}
23+
24+
export interface BranchExpenditures {
25+
amount: Numeric;
26+
category: string | null;
27+
created_at: Generated<Timestamp | null>;
28+
description: string | null;
29+
entered_by: number | null;
30+
expenditure_id: Generated<number>;
31+
project_id: number;
32+
spent_on: Generated<Timestamp>;
33+
}
34+
35+
export interface BranchProjectDonations {
36+
amount: Numeric;
37+
donated_at: Generated<Timestamp | null>;
38+
donation_id: Generated<number>;
39+
donor_id: number;
40+
project_id: number;
41+
}
42+
43+
export interface BranchProjectMemberships {
44+
hours: Numeric | null;
45+
membership_id: Generated<number>;
46+
project_id: number;
47+
role: string;
48+
start_date: Timestamp | null;
49+
user_id: number;
50+
}
51+
52+
export interface BranchProjects {
53+
created_at: Generated<Timestamp | null>;
54+
currency: Generated<string | null>;
55+
end_date: Timestamp | null;
56+
name: string;
57+
project_id: Generated<number>;
58+
start_date: Timestamp | null;
59+
total_budget: Numeric | null;
60+
}
61+
62+
export interface BranchUsers {
63+
created_at: Generated<Timestamp | null>;
64+
email: string;
65+
is_admin: Generated<boolean | null>;
66+
name: string;
67+
user_id: Generated<number>;
68+
}
69+
70+
export interface DB {
71+
"branch.donors": BranchDonors;
72+
"branch.expenditures": BranchExpenditures;
73+
"branch.project_donations": BranchProjectDonations;
74+
"branch.project_memberships": BranchProjectMemberships;
75+
"branch.projects": BranchProjects;
76+
"branch.users": BranchUsers;
77+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Kysely, PostgresDialect } from 'kysely'
2+
import { Pool } from 'pg'
3+
import type { DB } from './db-types'
4+
5+
6+
const db = new Kysely<DB>({
7+
dialect: new PostgresDialect({
8+
pool: new Pool({
9+
host: process.env.DB_HOST ?? 'localhost',
10+
port: Number(process.env.DB_PORT ?? 5432),
11+
user: process.env.DB_USER ?? 'branch_dev',
12+
password: process.env.DB_PASSWORD ?? 'password',
13+
database: process.env.DB_NAME ?? 'branch_db',
14+
ssl: false,
15+
}),
16+
}),
17+
})
18+
19+
export default db

apps/backend/lambdas/projects/handler.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
22

3+
import db from './db';
4+
35
export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
46
try {
57
// Support both API Gateway and Lambda Function URL events
@@ -16,7 +18,14 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
1618

1719
// >>> ROUTES-START (do not remove this marker)
1820
// CLI-generated routes will be inserted here
19-
// <<< ROUTES-END
21+
22+
// GET /projects
23+
if (rawPath === '/' && method === 'GET') {
24+
const projects = await db.selectFrom("branch.projects").selectAll().execute();
25+
return json(200, projects);
26+
}
27+
28+
// <<< ROUTES-END
2029

2130
return json(404, { message: 'Not Found', path: normalizedPath, method });
2231
} catch (err) {

apps/backend/lambdas/projects/openapi.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,60 @@ paths:
1818
properties:
1919
ok:
2020
type: boolean
21+
22+
/projects:
23+
get:
24+
summary: GET /projects
25+
responses:
26+
'200':
27+
description: OK
28+
29+
/projects/{id}:
30+
get:
31+
summary: GET /projects/{id}
32+
parameters:
33+
- in: path
34+
name: id
35+
required: true
36+
schema:
37+
type: string
38+
responses:
39+
'200':
40+
description: OK
41+
42+
/projects/{id}:
43+
put:
44+
summary: PUT /projects/{id}
45+
parameters:
46+
- in: path
47+
name: id
48+
required: true
49+
schema:
50+
type: string
51+
responses:
52+
'200':
53+
description: OK
54+
55+
/projects/{id}:
56+
put:
57+
summary: PUT /projects/{id}
58+
parameters:
59+
- in: path
60+
name: id
61+
required: true
62+
schema:
63+
type: string
64+
requestBody:
65+
required: true
66+
content:
67+
application/json:
68+
schema:
69+
type: object
70+
properties:
71+
name:
72+
type: string
73+
total_budget:
74+
type: number
75+
responses:
76+
'200':
77+
description: OK

0 commit comments

Comments
 (0)