Skip to content

Commit

Permalink
feat(type): implemented resource type (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidhabib-buttons authored Feb 6, 2025
1 parent 785e12c commit ff23416
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 56 deletions.
1 change: 1 addition & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ model recreation_resource {
description String? @db.VarChar(5000)
site_location String? @db.VarChar(200)
display_on_public_site Boolean? @default(false)
rec_resource_type String? @db.VarChar(50)
recreation_activity recreation_activity[]
recreation_status recreation_status?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ export class RecreationResourceDto {
type: RecreationStatusDto,
})
recreation_status: RecreationStatusDto;

@ApiProperty({
description:
"Code representing a specific feature associated with the recreation resource",
example: "IF",
})
rec_resource_type: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const recreationResource1 = {
comment: "Site is open comment",
status_code: "01",
},
rec_resource_type: "SIT",
};

const recreationResource1Response = {
Expand All @@ -38,6 +39,7 @@ const recreationResource1Response = {
comment: "Site is open comment",
status_code: "01",
},
rec_resource_type: "SIT",
};

const recreationResource2 = {
Expand All @@ -54,6 +56,7 @@ const recreationResource2 = {
comment: "Site is closed comment",
status_code: "02",
},
rec_resource_type: "RTR",
};

const recreationResource2Response = {
Expand All @@ -64,6 +67,7 @@ const recreationResource2Response = {
comment: "Site is closed comment",
status_code: "02",
},
rec_resource_type: "RTR",
};

const recreationResource3 = {
Expand All @@ -87,6 +91,7 @@ const recreationResource3 = {
comment: "Site is active comment",
status_code: "01",
},
rec_resource_type: "RR",
};

const recreationResource3Response = {
Expand All @@ -102,6 +107,7 @@ const recreationResource3Response = {
comment: "Site is active comment",
status_code: "01",
},
rec_resource_type: "RR",
};

const recreationResource4 = {
Expand Down Expand Up @@ -131,6 +137,7 @@ const recreationResource4 = {
},
],
recreation_status: null,
rec_resource_type: "IF",
};

const recreationResource4Response = {
Expand All @@ -154,6 +161,7 @@ const recreationResource4Response = {
comment: undefined,
status_code: undefined,
},
rec_resource_type: "IF",
};

const recresourceArray = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface RecreationResource {
description: string;
site_location: string;
recreation_activity: RecreationActivityWithDescription[];
rec_resource_type: string;
recreation_status: {
recreation_status_code: {
description: string;
Expand All @@ -36,6 +37,7 @@ export class RecreationResourceService {
description: true,
name: true,
site_location: true,
rec_resource_type: true,

recreation_activity: {
select: {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/layout/PageMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
@media (min-width: $mdBreakpoint) {
position: sticky;
position: -webkit-sticky;
background-color: #fff;
z-index: 100;
}

@media (max-width: $lgBreakpoint) {
max-width: 100%;
}

.navbar {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/rec-resource/RecResourcePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import locationDot from '@/images/fontAwesomeIcons/location-dot.svg';
import '@/components/rec-resource/RecResource.scss';
import { RecreationResourceDto } from '@/service/recreation-resource';
import { useRecreationResourceApi } from '@/service/hooks/useRecreationResourceApi';
import { mapRecreationFeatureCode } from '@/utils/mapRecreationFeatureCode';

export const photosExample = [
{
Expand Down Expand Up @@ -75,6 +76,7 @@ const RecResourcePage = () => {
name,
rec_resource_id,
site_location,
rec_resource_type,
recreation_status: {
status_code: statusCode,
description: statusDescription,
Expand Down Expand Up @@ -133,7 +135,8 @@ const RecResourcePage = () => {
<div>
<h1 className="capitalize">{formattedName}</h1>
<p className="bc-color-blue-dk mb-4">
<span>Recreation site |</span> {rec_resource_id}
<span>{mapRecreationFeatureCode(rec_resource_type!)} |</span>{' '}
{rec_resource_id}
</p>
</div>
<div className="icon-container mb-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export interface RecreationResourceDto {
* @memberof RecreationResourceDto
*/
recreation_status: RecreationStatusDto;

rec_resource_type: string;
}

/**
Expand Down Expand Up @@ -116,6 +118,7 @@ export function RecreationResourceDtoFromJSONTyped(
name: json['name'],
description: json['description'],
site_location: json['site_location'],
rec_resource_type: json['rec_resource_type'],
recreation_activity: (json['recreation_activity'] as Array<any>).map(
RecreationActivityDtoFromJSON,
),
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/utils/mapRecreationFeatureCode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { mapRecreationFeatureCode } from './mapRecreationFeatureCode';

describe('mapRecreationFeatureCode', () => {
it('should return correct description for known codes', () => {
expect(mapRecreationFeatureCode('RTR')).toBe('Recreation Trail');
expect(mapRecreationFeatureCode('SIT')).toBe('Recreation Site');
expect(mapRecreationFeatureCode('RR')).toBe('Recreation Reserve');
expect(mapRecreationFeatureCode('IF')).toBe('Interpretive Forest');
});

it('should return "Unknown Feature" for unknown codes', () => {
expect(mapRecreationFeatureCode('XYZ')).toBe('Unknown Feature');
expect(mapRecreationFeatureCode('')).toBe('Unknown Feature');
expect(mapRecreationFeatureCode('123')).toBe('Unknown Feature');
});

it('should handle case sensitivity correctly', () => {
expect(mapRecreationFeatureCode('rtr')).toBe('Unknown Feature');
expect(mapRecreationFeatureCode('sit')).toBe('Unknown Feature');
});
});
14 changes: 14 additions & 0 deletions frontend/src/utils/mapRecreationFeatureCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum RecreationFeatureCode {
RTR = 'Recreation Trail',
SIT = 'Recreation Site',
RR = 'Recreation Reserve',
IF = 'Interpretive Forest',
}

const recreationFeatureMap = new Map<string, string>(
Object.entries(RecreationFeatureCode),
);

export const mapRecreationFeatureCode = (code: string): string => {
return recreationFeatureMap.get(code) ?? 'Unknown Feature';
};
Loading

0 comments on commit ff23416

Please sign in to comment.