more fixes and features
This commit is contained in:
+49
-39
@@ -176,48 +176,58 @@ void main() async {
|
||||
request.url.queryParameters['offerFilters']?.split(',') ??
|
||||
OfferType.values.asNameMap().keys;
|
||||
|
||||
Map<String, dynamic> output = {};
|
||||
|
||||
for (int i = 0; i < typeFilters.length; i++) {
|
||||
var postgresResult = (await postgres.query('''
|
||||
SELECT json_agg(
|
||||
json_build_object(
|
||||
'id', b.id,
|
||||
'name', b.name,
|
||||
'contactName', b."contactName",
|
||||
'contactEmail', b."contactEmail",
|
||||
'contactPhone', b."contactPhone",
|
||||
'locationName', b."locationName",
|
||||
'locationAddress', b."locationAddress",
|
||||
'listings', (
|
||||
SELECT json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'offerType', l."offerType",
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
var postgresResult = (await postgres.query('''
|
||||
WITH business_listings AS (
|
||||
SELECT b.id AS business_id,
|
||||
b.name AS business_name,
|
||||
b."contactName" AS business_contactName,
|
||||
b."contactEmail" AS business_contactEmail,
|
||||
b."contactPhone" AS business_contactPhone,
|
||||
b."locationName" AS business_locationName,
|
||||
b."locationAddress" AS business_locationAddress,
|
||||
l.type AS listing_type,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'businessId', l."businessId",
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'offerType', l."offerType",
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
FROM listings l
|
||||
WHERE l."businessId" = b.id AND l.type = '${typeFilters.elementAt(i)}' AND l."offerType" IN (${offerFilters.map((element) => "'$element'").join(',')})
|
||||
)
|
||||
) AS listings
|
||||
FROM businesses b
|
||||
JOIN listings l ON b.id = l."businessId"
|
||||
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
|
||||
)
|
||||
)
|
||||
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(',')}))
|
||||
GROUP BY b.id;
|
||||
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(
|
||||
json.encode(output),
|
||||
json.encode(postgresResult[0][0]),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': 'text/plain'
|
||||
@@ -311,9 +321,9 @@ void main() async {
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'offerType', l."offerType",
|
||||
'wage', l.wage,
|
||||
'link', l.link,
|
||||
'offerType', l."offerType"
|
||||
'link', l.link
|
||||
)
|
||||
)
|
||||
END
|
||||
|
||||
Reference in New Issue
Block a user