Skip to content

Commit

Permalink
display owner username instead of email in listings
Browse files Browse the repository at this point in the history
  • Loading branch information
chennisden committed Jun 12, 2024
1 parent f7c2c58 commit 75c6eac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/hooks/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class api {
}
public async getUserById(userId: string | undefined): Promise<string> {
const response = await this.api.get(`/users/${userId}`);
return response.data.email;
return response.data.username;
}
public async getRobots(): Promise<Robot[]> {
try {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Login = () => {
<label htmlFor="email">Email:</label>
<Form.Control
id="email"
autoComplete="username"
className="mb-3"
type="text"
placeholder="Email"
Expand All @@ -43,6 +44,7 @@ const Login = () => {
Description:
<Form.Control
id="password"
autoComplete="password"
className="mb-3"
type="password"
placeholder="Password"
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Register = () => {
<label htmlFor="email">Email:</label>
<Form.Control
id="email"
autoComplete="email"
className="mb-3"
type="text"
placeholder="Email"
Expand All @@ -50,6 +51,7 @@ const Register = () => {
<label htmlFor="username">Username:</label>
<Form.Control
id="username"
autoComplete="username"
className="mb-3"
type="text"
placeholder="Username"
Expand All @@ -62,6 +64,7 @@ const Register = () => {
Description:
<Form.Control
id="password"
autoComplete="new-password"
className="mb-3"
type="password"
placeholder="Password"
Expand Down
5 changes: 3 additions & 2 deletions store/app/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def login_user_endpoint(

class UserInfoResponse(BaseModel):
email: str
username: str


@users_router.get("/me", response_model=UserInfoResponse)
Expand All @@ -156,7 +157,7 @@ async def get_user_info_endpoint(
user_obj = await crud.get_user(user_id)
if user_obj is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
return UserInfoResponse(email=user_obj.email)
return UserInfoResponse(email=user_obj.email, username=user_obj.username)


@users_router.delete("/me")
Expand Down Expand Up @@ -191,4 +192,4 @@ async def get_user_info_by_id_endpoint(user_id: str, crud: Annotated[Crud, Depen
user_obj = await crud.get_user(user_id)
if user_obj is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
return UserInfoResponse(email=user_obj.email)
return UserInfoResponse(email=user_obj.email, username=user_obj.username)

0 comments on commit 75c6eac

Please sign in to comment.