mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-09 14:00:15 -04:00
Save current change currents
This commit is contained in:
parent
bdf892c6c2
commit
edbb1565e8
|
@ -15,7 +15,7 @@ openapi_tags = {
|
||||||
# TODO: Add security using HTTP Bearer Tokens
|
# TODO: Add security using HTTP Bearer Tokens
|
||||||
# TODO: Enable authorization by passing user uuid to API
|
# TODO: Enable authorization by passing user uuid to API
|
||||||
# TODO: Create custom exceptions
|
# 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()):
|
def get_all(user_id: str, user_svc: UserService = Depends()):
|
||||||
subject = user_svc.get_user_by_uuid(user_id)
|
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}")
|
raise Exception(f"Insufficient permissions for user {subject.uuid}")
|
||||||
|
|
||||||
return user_svc.all()
|
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)
|
||||||
|
|
|
@ -21,4 +21,4 @@ entities.EntityBase.metadata.drop_all(engine)
|
||||||
entities.EntityBase.metadata.create_all(engine)
|
entities.EntityBase.metadata.create_all(engine)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
user_test_data.insert_fake_data(session)
|
user_test_data.insert_test_data(session)
|
||||||
|
|
|
@ -76,6 +76,52 @@ toDelete = User(
|
||||||
|
|
||||||
users = [volunteer, employee, admin, toDelete]
|
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 import text
|
||||||
from sqlalchemy.orm import Session, DeclarativeBase, InstrumentedAttribute
|
from sqlalchemy.orm import Session, DeclarativeBase, InstrumentedAttribute
|
||||||
|
@ -122,6 +168,23 @@ def insert_fake_data(session: Session):
|
||||||
session.commit()
|
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)
|
@pytest.fixture(autouse=True)
|
||||||
def fake_data_fixture(session: Session):
|
def fake_data_fixture(session: Session):
|
||||||
"""Insert fake data the session automatically when test is run.
|
"""Insert fake data the session automatically when test is run.
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const apiEndpoint = `${process.env.NEXT_PUBLIC_API_HOST}/api/health`;
|
const apiEndpoint = `${process.env.NEXT_PUBLIC_API_HOST}/api/health`;
|
||||||
console.log(apiEndpoint);
|
|
||||||
|
|
||||||
const result = await fetch(apiEndpoint);
|
const result = await fetch(apiEndpoint);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET(request: Request) {
|
||||||
return NextResponse.json({ message: "Hello World!" }, { status: 200 });
|
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 });
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,12 @@ export default function RootLayout({
|
||||||
}
|
}
|
||||||
|
|
||||||
setUser(data.user);
|
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();
|
getUser();
|
||||||
|
|
23
compass/utils/models/User.ts
Normal file
23
compass/utils/models/User.ts
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user