Skip to content

Commit

Permalink
337/jurisdiction array (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinBuyck authored Oct 12, 2023
1 parent e2c256d commit 8e96eb2
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 70 deletions.
10 changes: 9 additions & 1 deletion backend/core/src/jurisdictions/dto/jurisdiction.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OmitType } from "@nestjs/swagger"
import { Expose, Type } from "class-transformer"
import { ArrayMaxSize, IsArray, IsString, ValidateNested } from "class-validator"
import { ArrayMaxSize, IsArray, IsBoolean, IsString, ValidateNested } from "class-validator"
import { ValidationsGroupsEnum } from "../../shared/types/validations-groups-enum"
import { Jurisdiction } from "../entities/jurisdiction.entity"
import { IdDto } from "../../shared/dto/id.dto"
Expand All @@ -19,4 +19,12 @@ export class JurisdictionSlimDto extends IdNameDto {
@Expose()
@IsString({ groups: [ValidationsGroupsEnum.default] })
publicUrl: string

@Expose()
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
enableAccessibilityFeatures: boolean | null

@Expose()
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
enableUtilitiesIncluded: boolean | null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Expose } from "class-transformer"
import { ApiProperty } from "@nestjs/swagger"
import { IsArray, IsOptional } from "class-validator"
import { ValidationsGroupsEnum } from "../../shared/types/validations-groups-enum"

export class JurisdictionsListParams {
@Expose()
@ApiProperty({
type: Array,
example: ["Bay Area", "Contra Costa"],
required: false,
})
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsArray({ groups: [ValidationsGroupsEnum.default] })
names?: string[]
}
9 changes: 7 additions & 2 deletions backend/core/src/jurisdictions/jurisdictions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Param,
Post,
Put,
Query,
UseGuards,
UsePipes,
ValidationPipe,
Expand All @@ -21,6 +22,7 @@ import { JurisdictionDto } from "./dto/jurisdiction.dto"
import { JurisdictionCreateDto } from "./dto/jurisdiction-create.dto"
import { JurisdictionUpdateDto } from "./dto/jurisdiction-update.dto"
import { IdDto } from "../shared/dto/id.dto"
import { JurisdictionsListParams } from "./dto/jurisdictions-list-query-params"

@Controller("jurisdictions")
@ApiTags("jurisdictions")
Expand All @@ -33,8 +35,11 @@ export class JurisdictionsController {

@Get()
@ApiOperation({ summary: "List jurisdictions", operationId: "list" })
async list(): Promise<JurisdictionDto[]> {
return mapTo(JurisdictionDto, await this.jurisdictionsService.list())
async list(
@Query()
queryParams: JurisdictionsListParams
): Promise<JurisdictionDto[]> {
return mapTo(JurisdictionDto, await this.jurisdictionsService.list(queryParams))
}

@Post()
Expand Down
21 changes: 16 additions & 5 deletions backend/core/src/jurisdictions/services/jurisdictions.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NotFoundException } from "@nestjs/common"
import { InjectRepository } from "@nestjs/typeorm"
import { FindOneOptions, Repository } from "typeorm"
import { FindOneOptions, In, Repository } from "typeorm"
import { Jurisdiction } from "../entities/jurisdiction.entity"
import { JurisdictionCreateDto } from "../dto/jurisdiction-create.dto"
import { JurisdictionUpdateDto } from "../dto/jurisdiction-update.dto"
import { assignDefined } from "../../shared/utils/assign-defined"
import { JurisdictionsListParams } from "../dto/jurisdictions-list-query-params"

export class JurisdictionsService {
constructor(
Expand All @@ -18,10 +19,20 @@ export class JurisdictionsService {
},
}

list(): Promise<Jurisdiction[]> {
return this.repository.find({
join: this.joinOptions,
})
async list(queryParams?: JurisdictionsListParams): Promise<Jurisdiction[]> {
const obj = queryParams?.names
? await this.repository.find({
where: { name: In([...queryParams.names]) },
join: this.joinOptions,
})
: await this.repository.find({
join: this.joinOptions,
})

if (!obj) {
throw new NotFoundException()
}
return obj
}

async create(dto: JurisdictionCreateDto): Promise<Jurisdiction> {
Expand Down
7 changes: 7 additions & 0 deletions build/docker/Dockerfile.sites-generic
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ARG GTM_KEY
# feature flags
ARG FEATURE_LISTINGS_APPROVAL
ARG SHOW_PROFESSIONAL_PARTNERS
ARG NOTIFICATIONS_SIGN_UP_URL


# The base image will contain all the source code needed for our site
FROM node:18.14-alpine AS base
Expand Down Expand Up @@ -118,6 +120,8 @@ ARG MAPBOX_TOKEN
ARG GTM_KEY
ARG FEATURE_LISTINGS_APPROVAL
ARG SHOW_PROFESSIONAL_PARTNERS
ARG NOTIFICATIONS_SIGN_UP_URL


# We need to have this nested 2 layers deep due to hardcoded paths in package.json
WORKDIR /app/sites/${SITE}
Expand All @@ -138,6 +142,9 @@ ENV GTM_KEY=$GTM_KEY
# feature flags
ENV FEATURE_LISTINGS_APPROVAL=$FEATURE_LISTINGS_APPROVAL
ENV SHOW_PROFESSIONAL_PARTNERS=$SHOW_PROFESSIONAL_PARTNERS
ENV NOTIFICATIONS_SIGN_UP_URL=$NOTIFICATIONS_SIGN_UP_URL



# Build/compile
RUN yarn build
Expand Down
5 changes: 3 additions & 2 deletions ci/buildspec/build_public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ phases:
--build-arg "MAPBOX_TOKEN=${MAPBOX_TOKEN}"
--build-arg "GTM_KEY=${GTM_KEY}"
--build-arg "SHOW_PROFESSIONAL_PARTNERS=$SHOW_PROFESSIONAL_PARTNERS"
--build-arg "NOTIFICATIONS_SIGN_UP_URL=$NOTIFICATIONS_SIGN_UP_URL"
--target test
-t sites/public:test
.
Expand All @@ -62,11 +63,11 @@ phases:
--build-arg "MAPBOX_TOKEN=${MAPBOX_TOKEN}"
--build-arg "GTM_KEY=${GTM_KEY}"
--build-arg "SHOW_PROFESSIONAL_PARTNERS=$SHOW_PROFESSIONAL_PARTNERS"
--build-arg "NOTIFICATIONS_SIGN_UP_URL=$NOTIFICATIONS_SIGN_UP_URL"
--target run
-t sites/public:run-candidate
.
# Tag the run image
- docker tag sites/public:run-candidate "${ECR_REPO}/public:run-${CODEBUILD_RESOLVED_SOURCE_VERSION:0:8}"

Expand Down
1 change: 1 addition & 0 deletions sites/public/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MAPBOX_TOKEN=
LANGUAGES=en,es,zh,vi,tl
IDLE_TIMEOUT=5
JURISDICTION_NAME=Bay Area
NOTIFICATIONS_SIGN_UP_URL=https://public.govdelivery.com/accounts/CAMTC/signup/36832
CLOUDINARY_CLOUD_NAME=exygy
# next js cache revalidate
CACHE_REVALIDATE=60
Expand Down
4 changes: 4 additions & 0 deletions sites/public/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ module.exports = withBundleAnalyzer(
withTM({
env: {
backendApiBase: BACKEND_API_BASE, // this has to be set for tests
backendProxyBase: process.env.BACKEND_PROXY_BASE,
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY,
listingsQuery: LISTINGS_QUERY,
listingPhotoSize: process.env.LISTING_PHOTO_SIZE || "1302",
mapBoxToken: MAPBOX_TOKEN,
housingCounselorServiceUrl: HOUSING_COUNSELOR_SERVICE_URL,
Expand All @@ -50,6 +53,7 @@ module.exports = withBundleAnalyzer(
cacheRevalidate: process.env.CACHE_REVALIDATE ? Number(process.env.CACHE_REVALIDATE) : 60,
cloudinaryCloudName: process.env.CLOUDINARY_CLOUD_NAME,
showProfessionalPartners: process.env.SHOW_PROFESSIONAL_PARTNERS === "TRUE",
notificationsSignUpUrl: process.env.NOTIFICATIONS_SIGN_UP_URL || null,

// start Doorway env variables
//googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY, // moved to runtime config
Expand Down
5 changes: 1 addition & 4 deletions sites/public/src/components/listings/ListingsCombined.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useState } from "react"
import { Jurisdiction, Listing } from "@bloom-housing/backend-core/types"
import { Listing } from "@bloom-housing/backend-core/types"
import { ListingsMap } from "./ListingsMap"
import { ListingsList } from "./ListingsList"
import { useSwipeable } from "react-swipeable"
import styles from "./ListingsCombined.module.scss"

type ListingsCombinedProps = {
jurisdiction: Jurisdiction
listings: Listing[]
currentPage: number
lastPage: number
Expand Down Expand Up @@ -68,7 +67,6 @@ const ListingsCombined = (props: ListingsCombinedProps) => {
</div>
<div id="listings-list-expanded" className={styles["listings-list-expanded"]}>
<ListingsList
jurisdiction={props.jurisdiction}
listings={props.listings}
currentPage={props.currentPage}
lastPage={props.lastPage}
Expand Down Expand Up @@ -114,7 +112,6 @@ const ListingsCombined = (props: ListingsCombinedProps) => {
</div>
<div id="listings-list" className={styles["listings-list"]}>
<ListingsList
jurisdiction={props.jurisdiction}
listings={props.listings}
currentPage={props.currentPage}
lastPage={props.lastPage}
Expand Down
5 changes: 2 additions & 3 deletions sites/public/src/components/listings/ListingsList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as React from "react"
import { getListings } from "../../lib/helpers"
import { Listing, Jurisdiction } from "@bloom-housing/backend-core"
import { Listing } from "@bloom-housing/backend-core"
import { InfoCard, LinkButton, ZeroListingsItem } from "@bloom-housing/doorway-ui-components"
import { Pagination } from "./Pagination"
import { LoadingOverlay, t } from "@bloom-housing/ui-components"

type ListingsListProps = {
jurisdiction: Jurisdiction
listings: Listing[]
currentPage: number
lastPage: number
Expand Down Expand Up @@ -36,7 +35,7 @@ const ListingsList = (props: ListingsListProps) => {
className="is-normal-primary-lighter"
>
<LinkButton
href={props.jurisdiction.notificationsSignUpURL}
href={process.env.notificationsSignUpUrl}
newTab={true}
className="is-primary"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { ListingList, pushGtmEvent, AuthContext } from "@bloom-housing/shared-he
import { ListingSearchParams, generateSearchQuery } from "../../../lib/listings/search"
import { ListingService } from "../../../lib/listings/listing-service"
import { ListingsCombined } from "../ListingsCombined"
import { Jurisdiction } from "@bloom-housing/backend-core"

import { AppearanceSizeType, Button } from "@bloom-housing/doorway-ui-components"
import { FormOption, ListingsSearchModal } from "./ListingsSearchModal"
import { AppearanceBorderType, t } from "@bloom-housing/ui-components"

type ListingsSearchCombinedProps = {
jurisdiction: Jurisdiction
searchString?: string
googleMapsApiKey: string
listingsEndpoint: string
Expand Down Expand Up @@ -127,7 +125,6 @@ function ListingsSearchCombined(props: ListingsSearchCombinedProps) {
/>

<ListingsCombined
jurisdiction={props.jurisdiction}
listings={searchResults.listings}
currentPage={searchResults.currentPage}
lastPage={searchResults.lastPage}
Expand Down
23 changes: 4 additions & 19 deletions sites/public/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { UserStatus } from "../lib/constants"
import Layout from "../layouts/application"
import { ConfirmationModal } from "../components/account/ConfirmationModal"
import { MetaTags } from "../components/shared/MetaTags"
import { fetchJurisdictionByName } from "../lib/hooks"
import { runtimeConfig } from "../lib/runtime-config"
import { LandingSearch } from "../components/listings/search/LandingSearch"
import { FormOption } from "../components/listings/search/ListingsSearchModal"
import { locations } from "../components/listings/search/ListingsSearchCombined"
Expand All @@ -43,6 +41,7 @@ export default function Home(props: IndexProps) {
})
}, [profile])

const notificationsSignUpURL = process.env.notificationsSignUpUrl
const metaDescription = t("pageDescription.welcome")
const metaImage = t("welcome.personWithChildAlt")
const alertClasses = "flex-grow mt-6 max-w-6xl w-full"
Expand Down Expand Up @@ -70,7 +69,7 @@ export default function Home(props: IndexProps) {
offsetImage={"images/person-with-child.jpg"}
offsetImageAlt={t("welcome.personWithChildAlt")}
>
<LandingSearch bedrooms={props.bedrooms} counties={props.counties} />
<LandingSearch bedrooms={props.bedrooms} counties={locations} />
</DoorwayHero>
<ActionBlock
className="p-12"
Expand Down Expand Up @@ -160,7 +159,7 @@ export default function Home(props: IndexProps) {
</InfoCard>
</div>
</div>
{props.jurisdiction && props.jurisdiction.notificationsSignUpURL && (
{notificationsSignUpURL && (
<ActionBlock
className="p-12"
header={
Expand All @@ -174,7 +173,7 @@ export default function Home(props: IndexProps) {
<LinkButton
key={"sign-up"}
className="is-primary"
href={props.jurisdiction.notificationsSignUpURL}
href={notificationsSignUpURL}
newTab={true}
size={AppearanceSizeType.small}
>
Expand All @@ -189,17 +188,3 @@ export default function Home(props: IndexProps) {
</Layout>
)
}

export async function getServerSideProps() {
const jurisdiction = await fetchJurisdictionByName(
runtimeConfig.getBackendApiBase(),
runtimeConfig.getJurisdictionName()
)

return {
props: {
jurisdiction,
counties: locations,
},
}
}
1 change: 0 additions & 1 deletion sites/public/src/pages/listing/[id]/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export async function getServerSideProps(context: {
locale: string
}) {
let response

const listingServiceUrl = runtimeConfig.getListingServiceUrl()

try {
Expand Down
Loading

0 comments on commit 8e96eb2

Please sign in to comment.