Skip to content

Commit

Permalink
Move status filtering from front end to back end (#2112)
Browse files Browse the repository at this point in the history
  • Loading branch information
djnunez-aot authored Sep 1, 2023
1 parent 70f77d5 commit 74e02af
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
8 changes: 7 additions & 1 deletion met-api/src/met_api/models/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ class Feedback(BaseModel):
db.Integer, db.ForeignKey('tenant.id'), nullable=True)

@classmethod
def get_all_paginated(cls, pagination_options: PaginationOptions, search_text=''):
def get_all_paginated(cls,
pagination_options: PaginationOptions,
status: FeedbackStatusType,
search_text='',
):
"""Get feedback paginated."""
query = db.session.query(Feedback)

query = query.filter_by(status=status)

if search_text:
# Remove all non-digit characters from search text
query = query.filter(
Expand Down
6 changes: 5 additions & 1 deletion met-api/src/met_api/resources/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from met_api.schemas import utils as schema_utils
from met_api.models.pagination_options import PaginationOptions
from met_api.services.feedback_service import FeedbackService
from met_api.constants.feedback import FeedbackStatusType
from met_api.utils.token_info import TokenInfo
from met_api.utils.util import allowedorigins, cors_preflight

Expand Down Expand Up @@ -53,8 +54,11 @@ def get():
sort_key=args.get('sort_key', 'name', str),
sort_order=args.get('sort_order', 'asc', str),
)
status_int = args.get(
'status', FeedbackStatusType.Unreviewed.value, int)
status = FeedbackStatusType(status_int)
feedback_records = FeedbackService().get_feedback_paginated(
pagination_options, search_text)
pagination_options, search_text, status,)

return feedback_records, HTTPStatus.OK
except ValueError as err:
Expand Down
8 changes: 6 additions & 2 deletions met-api/src/met_api/services/feedback_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

"""Service for feedback management."""
from met_api.constants.feedback import FeedbackSourceType
from met_api.constants.feedback import FeedbackSourceType, FeedbackStatusType
from met_api.models.feedback import Feedback
from met_api.models.pagination_options import PaginationOptions
from met_api.schemas.feedback import FeedbackSchema
Expand All @@ -17,12 +17,16 @@ def get_feedback(feedback_id):
return feedback_schema.dump(feedback)

@classmethod
def get_feedback_paginated(cls, pagination_options: PaginationOptions, search_text=''):
def get_feedback_paginated(cls, pagination_options: PaginationOptions,
status: FeedbackStatusType,
search_text='',
):
"""Get feedbacks paginated."""
feedback_schema = FeedbackSchema(many=True)
items, total = Feedback.get_all_paginated(
pagination_options,
search_text,
status,
)
return {
'items': feedback_schema.dump(items),
Expand Down
3 changes: 2 additions & 1 deletion met-api/tests/unit/models/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def test_get_feedbacks_paginated(session):
sort_key='comment',
sort_order=''
)
status = FeedbackStatusType.Unreviewed

# verify name search
result, count = FeedbackModel.get_all_paginated(pagination_options)
_, count = FeedbackModel.get_all_paginated(pagination_options, status)
assert count == 11
6 changes: 3 additions & 3 deletions met-web/src/components/feedback/listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ const FeedbackListing = () => {
size,
sort_key: nested_sort_key || sort_key,
sort_order,
status: statusFilter,
});
const filteredFeedbacks = response.items.filter((feedback) => feedback.status == statusFilter);
setFeedbacks(filteredFeedbacks);
setFeedbacks(response.items);
setPageInfo({
total: filteredFeedbacks.length,
total: response.total,
});
setTableLoading(false);
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions met-web/src/services/feedbackService/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const getFeedbacksPage = async ({
sort_key,
sort_order,
search_text,
status,
}: GetFeedbackRequest): Promise<Page<Feedback>> => {
const url = Endpoints.Feedback.GET_LIST;
const response = await http.GetRequest<Page<Feedback>>(url, {
Expand All @@ -18,6 +19,7 @@ export const getFeedbacksPage = async ({
sort_key,
sort_order,
search_text,
status,
});
if (response.data) {
return response.data;
Expand Down
1 change: 1 addition & 0 deletions met-web/src/services/feedbackService/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface GetFeedbackRequest {
sort_key?: string;
sort_order?: 'asc' | 'desc';
search_text?: string;
status?: FeedbackStatusEnum;
}

export interface PostFeedbackRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupEnv } from '../setEnvVars';
import * as reactRedux from 'react-redux';
import * as feedbackService from 'services/feedbackService/index';
import * as notificationSlice from 'services/notificationService/notificationSlice';
import { createDefaultFeedback, CommentTypeEnum, SourceTypeEnum } from 'models/feedback';
import { createDefaultFeedback, CommentTypeEnum, SourceTypeEnum, FeedbackStatusEnum } from 'models/feedback';
import FeedbackListing from 'components/feedback/listing';
import { USER_ROLES } from 'services/userService/constants';

Expand All @@ -27,7 +27,7 @@ const mockFeedbackTwo = {
source: SourceTypeEnum.Public,
};

jest.mock('axios')
jest.mock('axios');

jest.mock('@mui/material', () => ({
...jest.requireActual('@mui/material'),
Expand Down Expand Up @@ -123,6 +123,7 @@ describe('Feedback Listing tests', () => {
size: 10,
sort_key: 'rating',
sort_order: 'asc',
status: FeedbackStatusEnum.NotReviewed,
});
});
});
Expand Down Expand Up @@ -150,6 +151,7 @@ describe('Feedback Listing tests', () => {
size: 10,
sort_key: 'rating',
sort_order: 'asc',
status: FeedbackStatusEnum.NotReviewed,
});
});
});
Expand Down

0 comments on commit 74e02af

Please sign in to comment.