Save current change currents

This commit is contained in:
pmoharana-cmd 2024-04-23 18:54:18 -04:00
parent bdf892c6c2
commit edbb1565e8
7 changed files with 110 additions and 6 deletions

View File

@ -15,7 +15,7 @@ openapi_tags = {
# TODO: Add security using HTTP Bearer Tokens
# TODO: Enable authorization by passing user uuid to API
# TODO: Create custom exceptions
@api.get("", response_model=List[User], tags=["Users"])
@api.get("all", response_model=List[User], tags=["Users"])
def get_all(user_id: str, user_svc: UserService = Depends()):
subject = user_svc.get_user_by_uuid(user_id)
@ -23,3 +23,8 @@ def get_all(user_id: str, user_svc: UserService = Depends()):
raise Exception(f"Insufficient permissions for user {subject.uuid}")
return user_svc.all()
@api.get("/{user_id}", response_model=User, tags=["Users"])
def get_by_uuid(user_id: str, user_svc: UserService = Depends()):
return user_svc.get_user_by_uuid(user_id)

View File

@ -21,4 +21,4 @@ entities.EntityBase.metadata.drop_all(engine)
entities.EntityBase.metadata.create_all(engine)
with Session(engine) as session:
user_test_data.insert_fake_data(session)
user_test_data.insert_test_data(session)

View File

@ -76,6 +76,52 @@ toDelete = User(
users = [volunteer, employee, admin, toDelete]
admin1 = User(
username="Prajwal Moharana",
uuid="acc6e112-d296-4739-a80c-b89b2933e50b",
email="root@compass.com",
experience=10,
group="admin",
program=[programs.ECONOMIC, programs.DOMESTIC, programs.COMMUNITY],
created_at=datetime.now(),
role=roles.ADMIN,
)
employee1 = User(
username="Mel Ho",
uuid="c5fcff86-3deb-4d09-9f60-9b529e40161a",
email="employee@compass.com",
experience=5,
group="employee",
program=[programs.ECONOMIC, programs.DOMESTIC, programs.COMMUNITY],
created_at=datetime.now(),
role=roles.EMPLOYEE,
)
volunteer1 = User(
username="Pranav Wagh",
uuid="1d2e114f-b286-4464-8528-d177dc226b09",
email="volunteer1@compass.com",
experience=2,
group="volunteer",
program=[programs.DOMESTIC],
created_at=datetime.now(),
role=roles.VOLUNTEER,
)
volunteer2 = User(
username="Yashu Singhai",
uuid="13888204-1bae-4be4-8192-1ca46be4fc7d",
email="volunteer2@compass.com",
experience=1,
group="volunteer",
program=[programs.COMMUNITY, programs.ECONOMIC],
created_at=datetime.now(),
role=roles.VOLUNTEER,
)
users1 = [admin1, employee1, volunteer1, volunteer2]
from sqlalchemy import text
from sqlalchemy.orm import Session, DeclarativeBase, InstrumentedAttribute
@ -122,6 +168,23 @@ def insert_fake_data(session: Session):
session.commit()
def insert_test_data(session: Session):
"""Inserts fake organization data into the test session."""
global users1
# Create entities for test organization data
for user in users1:
entity = UserEntity.from_model(user)
session.add(entity)
# Reset table IDs to prevent ID conflicts
reset_table_id_seq(session, UserEntity, UserEntity.id, len(users1) + 1)
# Commit all changes
session.commit()
@pytest.fixture(autouse=True)
def fake_data_fixture(session: Session):
"""Insert fake data the session automatically when test is run.

View File

@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
export async function GET() {
const apiEndpoint = `${process.env.NEXT_PUBLIC_API_HOST}/api/health`;
console.log(apiEndpoint);
const result = await fetch(apiEndpoint);

View File

@ -1,5 +1,14 @@
import { NextResponse } from "next/server";
export async function GET() {
return NextResponse.json({ message: "Hello World!" }, { status: 200 });
export async function GET(request: Request) {
const apiEndpoint = `${process.env.NEXT_PUBLIC_API_HOST}/api/user`;
console.log(apiEndpoint);
const { searchParams } = new URL(request.url);
const uuid = searchParams.get("uuid");
const data = await fetch(`${apiEndpoint}/${uuid}`);
return NextResponse.json(await data.json(), { status: data.status });
}

View File

@ -29,7 +29,12 @@ export default function RootLayout({
}
setUser(data.user);
console.log(data.user);
const userData = await fetch(
`${process.env.NEXT_PUBLIC_HOST}/api/user?uuid=${data.user.id}`
);
console.log(await userData.json());
}
getUser();

View File

@ -0,0 +1,23 @@
export enum Program {
"ECONOMIC",
"DOMESTIC",
"COMMUNITY",
}
export enum Role {
"ADMIN",
"EMPLOYEE",
"VOLUNTEER",
}
export default interface User {
id: number;
uuid: string;
username: string;
email: string;
group: string;
experience: number;
program: Program[];
role: Role;
created_at: Date;
}