more fixes and features

This commit is contained in:
Drake Marino 2024-06-23 17:02:19 -05:00
parent 03abc1191d
commit b860ae52f6
7 changed files with 205 additions and 152 deletions

View File

@ -176,23 +176,20 @@ void main() async {
request.url.queryParameters['offerFilters']?.split(',') ?? request.url.queryParameters['offerFilters']?.split(',') ??
OfferType.values.asNameMap().keys; OfferType.values.asNameMap().keys;
Map<String, dynamic> output = {};
for (int i = 0; i < typeFilters.length; i++) {
var postgresResult = (await postgres.query(''' var postgresResult = (await postgres.query('''
SELECT json_agg( WITH business_listings AS (
json_build_object( SELECT b.id AS business_id,
'id', b.id, b.name AS business_name,
'name', b.name, b."contactName" AS business_contactName,
'contactName', b."contactName", b."contactEmail" AS business_contactEmail,
'contactEmail', b."contactEmail", b."contactPhone" AS business_contactPhone,
'contactPhone', b."contactPhone", b."locationName" AS business_locationName,
'locationName', b."locationName", b."locationAddress" AS business_locationAddress,
'locationAddress', b."locationAddress", l.type AS listing_type,
'listings', ( json_agg(
SELECT json_agg(
json_build_object( json_build_object(
'id', l.id, 'id', l.id,
'businessId', l."businessId",
'name', l.name, 'name', l.name,
'description', l.description, 'description', l.description,
'type', l.type, 'type', l.type,
@ -200,24 +197,37 @@ void main() async {
'wage', l.wage, 'wage', l.wage,
'link', l.link 'link', l.link
) )
) ) AS listings
FROM listings l
WHERE l."businessId" = b.id AND l.type = '${typeFilters.elementAt(i)}' AND l."offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})
)
)
)
FROM businesses b FROM businesses b
WHERE b.id IN (SELECT "businessId" FROM public.listings WHERE type='${typeFilters.elementAt(i)}' AND "offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})) JOIN listings l ON b.id = l."businessId"
GROUP BY b.id; WHERE l.type IN (${typeFilters.map((element) => "'$element'").join(',')})
AND l."offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})
GROUP BY b.id, b.name, b."contactName", b."contactEmail", b."contactPhone",
b."locationName", b."locationAddress", l.type
),
aggregated_businesses AS (
SELECT listing_type,
json_agg(
json_build_object(
'id', business_id,
'name', business_name,
'contactName', business_contactName,
'contactEmail', business_contactEmail,
'contactPhone', business_contactPhone,
'locationName', business_locationName,
'locationAddress', business_locationAddress,
'listings', listings
)
) AS businesses
FROM business_listings
GROUP BY listing_type
)
SELECT jsonb_object_agg(listing_type, businesses) AS result
FROM aggregated_businesses;
''')); '''));
if (postgresResult.isNotEmpty) {
output.addAll({typeFilters.elementAt(i): postgresResult[0][0]});
}
}
return Response.ok( return Response.ok(
json.encode(output), json.encode(postgresResult[0][0]),
headers: { headers: {
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/plain' 'Content-Type': 'text/plain'
@ -311,9 +321,9 @@ void main() async {
'name', l.name, 'name', l.name,
'description', l.description, 'description', l.description,
'type', l.type, 'type', l.type,
'offerType', l."offerType",
'wage', l.wage, 'wage', l.wage,
'link', l.link, 'link', l.link
'offerType', l."offerType"
) )
) )
END END

View File

@ -225,11 +225,9 @@ class _BusinessesOverviewState extends State<BusinessesOverview> {
}); });
} }
List<Padding> chips = []; List<Widget> chips = [];
for (var type in BusinessType.values) { for (var type in BusinessType.values) {
chips.add(Padding( chips.add(FilterChip(
padding: const EdgeInsets.all(4),
child: FilterChip(
showCheckmark: false, showCheckmark: false,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)), borderRadius: BorderRadius.circular(20)),
@ -242,8 +240,7 @@ class _BusinessesOverviewState extends State<BusinessesOverview> {
selectedChips.remove(type); selectedChips.remove(type);
} }
setDialogState(filters); setDialogState(filters);
}), }));
));
} }
return AlertDialog( return AlertDialog(
@ -251,6 +248,8 @@ class _BusinessesOverviewState extends State<BusinessesOverview> {
content: SizedBox( content: SizedBox(
width: 400, width: 400,
child: Wrap( child: Wrap(
spacing: 6,
runSpacing: 6,
children: chips, children: chips,
), ),
), ),

View File

@ -141,9 +141,19 @@ class _CreateEditJobListingState extends State<CreateEditJobListing> {
style: const TextStyle( style: const TextStyle(
fontSize: 24, fontSize: 24,
fontWeight: FontWeight.bold)), fontWeight: FontWeight.bold)),
subtitle: Text( subtitle: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
getNameFromJobType(listing.type!),
style: const TextStyle(fontSize: 18),
),
Text(
listing.description, listing.description,
), ),
],
),
contentPadding: const EdgeInsets.only( contentPadding: const EdgeInsets.only(
bottom: 8, left: 16), bottom: 8, left: 16),
leading: ClipRRect( leading: ClipRRect(

View File

@ -45,22 +45,47 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
child: Column( child: Column(
children: [ children: [
ListTile( ListTile(
minVerticalPadding: 0,
titleAlignment: ListTileTitleAlignment.titleHeight, titleAlignment: ListTileTitleAlignment.titleHeight,
title: Text(listing.name, title: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
'${listing.name} (${getNameFromOfferType(listing.offerType!)})',
style: const TextStyle( style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold)), fontSize: 24, fontWeight: FontWeight.bold)),
subtitle: Text( ),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
getNameFromJobType(listing.type!),
style: const TextStyle(fontSize: 18),
),
Text(
listing.description, listing.description,
), ),
],
),
contentPadding: contentPadding:
const EdgeInsets.only(bottom: 8, left: 16), const EdgeInsets.only(bottom: 8, left: 16),
leading: ClipRRect( leading: Badge(
label: Text(
getLetterFromOfferType(listing.offerType!),
style: const TextStyle(fontSize: 16),
),
largeSize: 26,
offset: const Offset(15, -5),
textColor: Colors.white,
backgroundColor:
getColorFromOfferType(listing.offerType!),
child: ClipRRect(
borderRadius: BorderRadius.circular(6.0), borderRadius: BorderRadius.circular(6.0),
child: Image.network( child: Image.network(
'$apiAddress/logos/${listing.businessId}', '$apiAddress/logos/${listing.businessId}',
width: 48, width: 48,
height: 48, errorBuilder: (BuildContext context, height: 48, errorBuilder:
Object exception, StackTrace? stackTrace) { (BuildContext context, Object exception,
StackTrace? stackTrace) {
return Icon( return Icon(
getIconFromJobType( getIconFromJobType(
listing.type ?? JobType.other), listing.type ?? JobType.other),
@ -68,6 +93,7 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
}), }),
), ),
), ),
),
if (listing.link != null && listing.link != '') if (listing.link != null && listing.link != '')
ListTile( ListTile(
leading: const Icon(Icons.link), leading: const Icon(Icons.link),
@ -87,16 +113,14 @@ class _CreateBusinessDetailState extends State<JobListingDetail> {
), ),
), ),
// Wage // Wage
Visibility( if (listing.wage != null && listing.wage != '')
visible: listing.wage != null && listing.wage != '', Card(
child: Card(
child: ListTile( child: ListTile(
leading: const Icon(Icons.attach_money), leading: const Icon(Icons.attach_money),
subtitle: Text(listing.wage!), subtitle: Text(listing.wage!),
title: const Text('Wage Information'), title: const Text('Wage Information'),
), ),
), ),
),
Card( Card(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: Column( child: Column(

View File

@ -242,11 +242,9 @@ class _JobsOverviewState extends State<JobsOverview> {
} }
} }
List<Padding> jobTypeChips = []; List<Widget> jobTypeChips = [];
for (JobType type in JobType.values) { for (JobType type in JobType.values) {
jobTypeChips.add(Padding( jobTypeChips.add(FilterChip(
padding: const EdgeInsets.all(4),
child: FilterChip(
showCheckmark: false, showCheckmark: false,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)), borderRadius: BorderRadius.circular(20)),
@ -259,15 +257,12 @@ class _JobsOverviewState extends State<JobsOverview> {
selectedJobTypeChips.remove(type); selectedJobTypeChips.remove(type);
} }
setDialogState(selectedJobTypeChips, null); setDialogState(selectedJobTypeChips, null);
}), }));
));
} }
List<Padding> offerTypeChips = []; List<Widget> offerTypeChips = [];
for (OfferType type in OfferType.values) { for (OfferType type in OfferType.values) {
offerTypeChips.add(Padding( offerTypeChips.add(FilterChip(
padding: const EdgeInsets.all(4),
child: FilterChip(
showCheckmark: false, showCheckmark: false,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)), borderRadius: BorderRadius.circular(20)),
@ -280,8 +275,7 @@ class _JobsOverviewState extends State<JobsOverview> {
selectedOfferTypeChips.remove(type); selectedOfferTypeChips.remove(type);
} }
setDialogState(null, selectedOfferTypeChips); setDialogState(null, selectedOfferTypeChips);
}), }));
));
} }
return AlertDialog( return AlertDialog(
@ -295,6 +289,8 @@ class _JobsOverviewState extends State<JobsOverview> {
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Wrap( child: Wrap(
spacing: 6,
runSpacing: 6,
children: jobTypeChips, children: jobTypeChips,
), ),
), ),
@ -302,6 +298,8 @@ class _JobsOverviewState extends State<JobsOverview> {
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Wrap( child: Wrap(
spacing: 6,
runSpacing: 6,
children: offerTypeChips, children: offerTypeChips,
), ),
), ),
@ -515,8 +513,9 @@ class _JobHeaderState extends State<_JobHeader> {
), ),
largeSize: 26, largeSize: 26,
offset: const Offset(15, -5), offset: const Offset(15, -5),
textColor: Theme.of(context).colorScheme.onPrimary, textColor: Colors.white,
backgroundColor: Theme.of(context).colorScheme.primary, backgroundColor: getColorFromOfferType(
business.listings![0].offerType!),
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(6.0), borderRadius: BorderRadius.circular(6.0),
child: Image.network( child: Image.network(

View File

@ -87,16 +87,12 @@ class _FilterBusinessDataTypeChipsState
extends State<_FilterBusinessDataTypeChips> { extends State<_FilterBusinessDataTypeChips> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
List<Padding> chips = []; List<Widget> chips = [];
for (var type in DataTypeBusiness.values) { for (var type in DataTypeBusiness.values) {
chips.add(Padding( chips.add(FilterChip(
padding:
const EdgeInsets.only(left: 3.0, right: 3.0, bottom: 3.0, top: 3.0),
child: FilterChip(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
side: side: BorderSide(color: Theme.of(context).colorScheme.secondary)),
BorderSide(color: Theme.of(context).colorScheme.secondary)),
label: Text(dataTypeFriendlyBusiness[type]!), label: Text(dataTypeFriendlyBusiness[type]!),
showCheckmark: false, showCheckmark: false,
selected: widget.selectedDataTypesBusiness.contains(type), selected: widget.selectedDataTypesBusiness.contains(type),
@ -108,10 +104,11 @@ class _FilterBusinessDataTypeChipsState
widget.selectedDataTypesBusiness.remove(type); widget.selectedDataTypesBusiness.remove(type);
} }
}); });
}), }));
));
} }
return Wrap( return Wrap(
spacing: 6,
runSpacing: 6,
children: chips, children: chips,
); );
} }
@ -155,6 +152,8 @@ class _FilterJobDataTypeChipsState extends State<_FilterJobDataTypeChips> {
)); ));
} }
return Wrap( return Wrap(
spacing: 6,
runSpacing: 6,
children: chips, children: chips,
); );
} }

View File

@ -5,12 +5,12 @@ enum DataTypeBusiness {
logo, logo,
name, name,
description, description,
type,
website, website,
contactName, contactName,
contactEmail, contactEmail,
contactPhone, contactPhone,
notes, notes,
type,
} }
enum DataTypeJob { enum DataTypeJob {
@ -42,19 +42,20 @@ class JobListing {
String name; String name;
String description; String description;
JobType? type; JobType? type;
OfferType? offerType;
String? wage; String? wage;
String? link; String? link;
OfferType? offerType;
JobListing( JobListing({
{this.id, this.id,
this.businessId, this.businessId,
required this.name, required this.name,
required this.description, required this.description,
this.type, this.type,
this.offerType,
this.wage, this.wage,
this.link, this.link,
this.offerType}); });
factory JobListing.copy(JobListing input) { factory JobListing.copy(JobListing input) {
return JobListing( return JobListing(
@ -63,9 +64,9 @@ class JobListing {
name: input.name, name: input.name,
description: input.description, description: input.description,
type: input.type, type: input.type,
offerType: input.offerType,
wage: input.wage, wage: input.wage,
link: input.link, link: input.link,
offerType: input.offerType,
); );
} }
} }
@ -261,6 +262,17 @@ String getLetterFromOfferType(OfferType type) {
} }
} }
Color getColorFromOfferType(OfferType type) {
switch (type) {
case OfferType.job:
return Colors.blue;
case OfferType.internship:
return Colors.green.shade800;
case OfferType.apprenticeship:
return Colors.red;
}
}
IconData getIconFromThemeMode(ThemeMode theme) { IconData getIconFromThemeMode(ThemeMode theme) {
switch (theme) { switch (theme) {
case ThemeMode.dark: case ThemeMode.dark: