Skip to content

Commit

Permalink
Add buttons to directory + lint (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
helenellyx authored Aug 1, 2023
1 parent c9f873d commit b5df053
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 38 deletions.
9 changes: 6 additions & 3 deletions backend/app/rest/residents_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ def get_residents():
except:
pass

try:
try:
resident_id = request.args.get("resident_id")
residents_results = residents_service.get_residents(return_all, page_number, results_per_page, resident_id)
residents_results = residents_service.get_residents(
return_all, page_number, results_per_page, resident_id
)
return jsonify(residents_results), 201
except Exception as e:
error_message = getattr(e, "message", None)
return jsonify({"error": (error_message if error_message else str(e))}), 500



@blueprint.route("/count", methods=["GET"], strict_slashes=False)
@require_authorization_by_role({"Relief Staff", "Regular Staff", "Admin"})
def count_residents():
Expand Down
1 change: 1 addition & 0 deletions backend/app/rest/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def count_users():
error_message = getattr(e, "message", None)
return jsonify({"error": (error_message if error_message else str(e))}), 500


@blueprint.route("/user-status", methods=["GET"], strict_slashes=False)
def get_user_status():
try:
Expand Down
12 changes: 8 additions & 4 deletions backend/app/services/implementations/residents_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,28 @@ def delete_resident(self, resident_id):
)
db.session.commit()

def get_residents(self, return_all, page_number, results_per_page, resident_id=None):
def get_residents(
self, return_all, page_number, results_per_page, resident_id=None
):
try:
if resident_id:
residents_results = Residents.query.filter_by(resident_id=resident_id)
elif return_all:
residents_results = Residents.query.all()
else:
else:
residents_results = (
Residents.query.limit(results_per_page)
.offset((page_number - 1) * results_per_page)
.all()
)

residents_results = list(map(lambda resident: resident.to_dict(), residents_results))
residents_results = list(
map(lambda resident: resident.to_dict(), residents_results)
)
return {"residents": residents_results}
except Exception as postgres_error:
raise postgres_error

def count_residents(self):
try:
count = Residents.query.count()
Expand Down
2 changes: 1 addition & 1 deletion backend/app/services/implementations/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_users(self, return_all, page_number, results_per_page):

except Exception as postgres_error:
raise postgres_error

def count_users(self):
try:
count = User.query.count()
Expand Down
6 changes: 4 additions & 2 deletions backend/app/services/interfaces/residents_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def delete_resident(self, resident_id):
pass

@abstractmethod
def get_residents(self, return_all, page_number, results_per_page, resident_id=None):
def get_residents(
self, return_all, page_number, results_per_page, resident_id=None
):
"""
Gets residents in json format.
:param resident_id: id of resident to be deleted in the format of initial+room_num
Expand All @@ -59,7 +61,7 @@ def get_residents(self, return_all, page_number, results_per_page, resident_id=N
"""
pass

@abstractmethod
@abstractmethod
def count_residents(self):
"""
Count the total number of residents
Expand Down
4 changes: 2 additions & 2 deletions backend/app/services/interfaces/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_auth_id_by_user_id(self, user_id):
def get_users(self, return_all, page_number, results_per_page):
"""
Get all users by a specific page and results per page
:param return_all: flag to return all users
:param page_number: number of page
:param results_per_page: number of results_per_page
Expand All @@ -89,7 +89,7 @@ def get_users(self, return_all, page_number, results_per_page):
def count_users(self):
"""
Count the total number of users
:return: count of users
:rtype: int
:raises Exception: if user count fails
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import HooksDemo from "./components/pages/HooksDemo";
import ResidentDirectory from "./components/pages/ResidentDirectory/ResidentDirectory";

import { AuthenticatedUser } from "./types/AuthTypes";
import CreateEmployee from "./components/forms/CreateEmployee";

import customTheme from "./theme";
import EmployeeDirectoryPage from "./components/pages/AdminControls/EmployeeDirectory";
Expand Down Expand Up @@ -102,11 +101,7 @@ const App = (): React.ReactElement => {
path={Routes.EMPLOYEE_DIRECTORY_PAGE}
component={EmployeeDirectoryPage}
/>
<PrivateRoute
exact
path={Routes.INVITE_EMPLOYEES}
component={CreateEmployee}
/>

<Route exact path="*" component={NotFound} />
</Switch>
</Router>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/CreateResident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

import { AddIcon } from "@chakra-ui/icons";
import { SingleDatepicker } from "chakra-dayzed-datepicker";
import { Card, Col, Row } from "react-bootstrap";
import { Col, Row } from "react-bootstrap";

import selectStyle from "../../theme/forms/selectStyles";
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from "react";
import { Box, Flex, Spacer } from "@chakra-ui/react";
import { Box, Flex } from "@chakra-ui/react";

import Pagination from "../../common/Pagination";
import NavigationBar from "../../common/NavigationBar";
Expand All @@ -9,6 +9,7 @@ import ExportCSVButton from "../../common/ExportCSVButton";
import { User } from "../../../types/UserTypes";
import EmployeesTable from "./EmployeesTable";
import UserAPIClient from "../../../APIClients/UserAPIClient";
import CreateEmployee from "../../forms/CreateEmployee";

const EmployeeDirectoryPage = (): React.ReactElement => {
const [users, setUsers] = useState<User[]>([]);
Expand All @@ -21,7 +22,7 @@ const EmployeeDirectoryPage = (): React.ReactElement => {
const tableRef = useRef<HTMLDivElement>(null);

const getUsers = async (pageNumber: number) => {
const data = await UserAPIClient.getUsers({pageNumber, resultsPerPage});
const data = await UserAPIClient.getUsers({ pageNumber, resultsPerPage });

// Reset table scroll
tableRef.current?.scrollTo(0, 0);
Expand Down Expand Up @@ -61,8 +62,9 @@ const EmployeeDirectoryPage = (): React.ReactElement => {
margin="0px auto"
color="blue.600"
>
<Flex marginBottom="16px">
<Flex marginBottom="16px" justify="space-between">
<Box textStyle="hero-table">Employee Directory</Box>
<>{CreateEmployee()}</>
</Flex>

<EmployeesTable users={users} tableRef={tableRef} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useState, useRef, useEffect } from "react";
import { Box, Flex, Spacer } from "@chakra-ui/react";
import ResidentDirectoryTable from './ResidentDirectoryTable'
import ResidentDirectoryTable from "./ResidentDirectoryTable";
import NavigationBar from "../../common/NavigationBar";
import { Resident } from "../../../types/ResidentTypes";
import ResidentAPIClient from "../../../APIClients/ResidentAPIClient";
import Pagination from "../../common/Pagination";
import CreateResident from "../../forms/CreateResident";

const ResidentDirectory = (): React.ReactElement => {
const [residents, setResidents] = useState<Resident[]>([]);
Expand All @@ -19,7 +20,7 @@ const ResidentDirectory = (): React.ReactElement => {
const data = await ResidentAPIClient.getResidents({
returnAll: false,
pageNumber,
resultsPerPage
resultsPerPage,
});

// Reset table scroll
Expand All @@ -33,21 +34,21 @@ const ResidentDirectory = (): React.ReactElement => {
} else {
setPageNum(pageNumber);
}
}
};

const countResidents = async () => {
const data = await ResidentAPIClient.countResidents()
const data = await ResidentAPIClient.countResidents();
setNumResidents(data ? data.numResults : 0);
}
};

useEffect(() => {
setUserPageNum(1);
getResidents(1);
}, [resultsPerPage])
}, [resultsPerPage]);

useEffect(() => {
countResidents()
}, [])
countResidents();
}, []);

return (
<Box>
Expand All @@ -64,13 +65,10 @@ const ResidentDirectory = (): React.ReactElement => {
<Box textStyle="hero-table">Resident Directory</Box>
<Spacer />
<Flex justify="end" gap="12px">
{/* TODO: INSERT RESIDENT-RELATED BUTTONS */}
{CreateResident()}
</Flex>
</Flex>
<ResidentDirectoryTable
residents={residents}
tableRef={tableRef }
/>
<ResidentDirectoryTable residents={residents} tableRef={tableRef} />
<Pagination
numRecords={numResidents}
pageNum={pageNum}
Expand All @@ -82,7 +80,7 @@ const ResidentDirectory = (): React.ReactElement => {
/>
</Box>
</Box>
)
);
};

export default ResidentDirectory;
2 changes: 0 additions & 2 deletions frontend/src/constants/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ export const HOOKS_PAGE = "/hooks";
export const RESIDENT_DIRECTORY_PAGE = "/resident-directory";

export const EMPLOYEE_DIRECTORY_PAGE = "/employee-directory";

export const INVITE_EMPLOYEES = "/invite-employees";

0 comments on commit b5df053

Please sign in to comment.