v0.2.0 beta - Major screen changes
This commit is contained in:
+106
-30
@@ -28,6 +28,7 @@ class Business {
|
||||
int id;
|
||||
String name;
|
||||
String description;
|
||||
BusinessType? type;
|
||||
String? website;
|
||||
String? contactName;
|
||||
String? contactEmail;
|
||||
@@ -40,6 +41,7 @@ class Business {
|
||||
{required this.id,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.type,
|
||||
this.website,
|
||||
this.contactName,
|
||||
this.contactEmail,
|
||||
@@ -49,11 +51,21 @@ class Business {
|
||||
this.locationAddress});
|
||||
|
||||
factory Business.fromJson(Map<String, dynamic> json) {
|
||||
bool typeValid = true;
|
||||
try {
|
||||
BusinessType.values.byName(json['type']);
|
||||
} catch (e) {
|
||||
typeValid = false;
|
||||
}
|
||||
|
||||
return Business(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
description: json['description'],
|
||||
website: json['website'],
|
||||
type: typeValid
|
||||
? BusinessType.values.byName(json['type'])
|
||||
: BusinessType.other,
|
||||
contactName: json['contactName'],
|
||||
contactEmail: json['contactEmail'],
|
||||
contactPhone: json['contactPhone'],
|
||||
@@ -151,12 +163,64 @@ void main() async {
|
||||
headers: {'Access-Control-Allow-Origin': '*'},
|
||||
);
|
||||
});
|
||||
app.get('/fbla-api/businessdata/overview', (Request request) async {
|
||||
app.get('/fbla-api/businessdata/overview/jobs', (Request request) async {
|
||||
print('business overview request received');
|
||||
|
||||
var filters = request.url.queryParameters['filters']?.split(',') ??
|
||||
JobType.values.asNameMap().keys;
|
||||
|
||||
Map<String, dynamic> output = {};
|
||||
|
||||
for (int i = 0; i < filters.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",
|
||||
'listings', (
|
||||
SELECT json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
)
|
||||
FROM listings l
|
||||
WHERE l."businessId" = b.id AND l.type = '${filters.elementAt(i)}'
|
||||
)
|
||||
)
|
||||
)
|
||||
FROM businesses b
|
||||
WHERE b.id IN (SELECT "businessId" FROM public.listings WHERE type='${filters.elementAt(i)}')
|
||||
GROUP BY b.id;
|
||||
'''));
|
||||
|
||||
if (postgresResult.isNotEmpty) {
|
||||
output.addAll({filters.elementAt(i): postgresResult[0][0]});
|
||||
}
|
||||
}
|
||||
|
||||
return Response.ok(
|
||||
json.encode(output),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
);
|
||||
});
|
||||
app.get('/fbla-api/businessdata/overview/types', (Request request) async {
|
||||
print('business overview request received');
|
||||
|
||||
var filters = request.url.queryParameters['filters']?.split(',') ??
|
||||
BusinessType.values.asNameMap().keys;
|
||||
|
||||
// List<Map<String, List<Map<String, dynamic>>>> this is the real type lol
|
||||
Map<String, dynamic> output = {};
|
||||
|
||||
@@ -172,7 +236,7 @@ void main() async {
|
||||
'contactPhone', "contactPhone",
|
||||
'locationName', "locationName"
|
||||
)
|
||||
) FROM public.businesses WHERE id IN (SELECT "businessId" FROM public.listings WHERE type='${filters.elementAt(i)}')
|
||||
) FROM public.businesses WHERE type='${filters.elementAt(i)}'
|
||||
'''))[0][0];
|
||||
|
||||
if (postgresResult != null) {
|
||||
@@ -180,6 +244,7 @@ void main() async {
|
||||
}
|
||||
}
|
||||
|
||||
// await Future.delayed(Duration(seconds: 5));
|
||||
return Response.ok(
|
||||
json.encode(output),
|
||||
headers: {
|
||||
@@ -218,6 +283,7 @@ void main() async {
|
||||
'id', b.id,
|
||||
'name', b.name,
|
||||
'description', b.description,
|
||||
'type', b.type,
|
||||
'website', b.website,
|
||||
'contactName', b."contactName",
|
||||
'contactEmail', b."contactEmail",
|
||||
@@ -226,17 +292,20 @@ void main() async {
|
||||
'locationName', b."locationName",
|
||||
'locationAddress', b."locationAddress",
|
||||
'listings',
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'businessId', l."businessId",
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
CASE
|
||||
WHEN COUNT(l.id) = 0 THEN 'null'
|
||||
ELSE json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'businessId', l."businessId",
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
)
|
||||
END
|
||||
)
|
||||
FROM businesses b
|
||||
LEFT JOIN listings l ON b.id = l."businessId"
|
||||
@@ -273,24 +342,27 @@ void main() async {
|
||||
'name', b.name,
|
||||
'description', b.description,
|
||||
'website', b.website,
|
||||
'type', b.type,
|
||||
'contactName', b."contactName",
|
||||
'contactEmail', b."contactEmail",
|
||||
'contactPhone', b."contactPhone",
|
||||
'notes', b.notes,
|
||||
'locationName', b."locationName",
|
||||
'locationAddress', b."locationAddress",
|
||||
'listings',
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'businessId', l."businessId",
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
'listings', CASE
|
||||
WHEN COUNT(l.id) = 0 THEN 'null'
|
||||
ELSE json_agg(
|
||||
json_build_object(
|
||||
'id', l.id,
|
||||
'businessId', l."businessId",
|
||||
'name', l.name,
|
||||
'description', l.description,
|
||||
'type', l.type,
|
||||
'wage', l.wage,
|
||||
'link', l.link
|
||||
)
|
||||
)
|
||||
END
|
||||
)
|
||||
FROM businesses b
|
||||
LEFT JOIN listings l ON b.id = l."businessId"
|
||||
@@ -362,9 +434,10 @@ void main() async {
|
||||
Business business = Business.fromJson(json);
|
||||
|
||||
await postgres.query('''
|
||||
INSERT INTO businesses (name, description, website, "contactName", "contactPhone", "contactEmail", notes, "locationName", "locationAddress")
|
||||
VALUES ('${business.name.replaceAll("'", "''")}', '${business.description.replaceAll("'", "''")}', '${business.website ?? 'NULL'}', '${business.contactName?.replaceAll("'", "''") ?? 'NULL'}', '${business.contactPhone ?? 'NULL'}', '${business.contactEmail ?? 'NULL'}', '${business.notes?.replaceAll("'", "''") ?? 'NULL'}', '${business.locationName?.replaceAll("'", "''") ?? 'NULL'}', '${business.locationAddress?.replaceAll("'", "''") ?? 'NULL'}')
|
||||
''');
|
||||
INSERT INTO businesses (name, description, website, type, "contactName", "contactPhone", "contactEmail", notes, "locationName", "locationAddress")
|
||||
VALUES ('${business.name.replaceAll("'", "''")}', '${business.description.replaceAll("'", "''")}', '${business.website ?? 'NULL'}', '${business.type?.name}', '${business.contactName?.replaceAll("'", "''") ?? 'NULL'}', '${business.contactPhone ?? 'NULL'}', '${business.contactEmail ?? 'NULL'}', '${business.notes?.replaceAll("'", "''") ?? 'NULL'}', '${business.locationName?.replaceAll("'", "''") ?? 'NULL'}', '${business.locationAddress?.replaceAll("'", "''") ?? 'NULL'}')
|
||||
'''
|
||||
.replaceAll("'null'", 'NULL'));
|
||||
|
||||
final dbBusiness = await postgres.query('''SELECT * FROM public.businesses
|
||||
ORDER BY id DESC LIMIT 1''');
|
||||
@@ -403,8 +476,9 @@ void main() async {
|
||||
|
||||
await postgres.query('''
|
||||
INSERT INTO listings ("businessId", name, description, type, wage, link)
|
||||
VALUES ('${listing.businessId}' '${listing.name.replaceAll("'", "''")}', '${listing.description.replaceAll("'", "''")}', '${listing.type.name}', '${listing.wage ?? 'NULL'}', '${listing.link?.replaceAll("'", "''") ?? 'NULL'}')
|
||||
''');
|
||||
VALUES ('${listing.businessId}', '${listing.name.replaceAll("'", "''")}', '${listing.description.replaceAll("'", "''")}', '${listing.type.name}', '${listing.wage ?? 'NULL'}', '${listing.link?.replaceAll("'", "''") ?? 'NULL'}')
|
||||
'''
|
||||
.replaceAll("'null'", 'NULL'));
|
||||
|
||||
final dbListing = await postgres.query('''SELECT id FROM public.listings
|
||||
ORDER BY id DESC LIMIT 1''');
|
||||
@@ -500,7 +574,8 @@ void main() async {
|
||||
UPDATE businesses SET
|
||||
name = '${business.name.replaceAll("'", "''").replaceAll("\"", "\"\"")}'::text, description = '${business.description.replaceAll("'", "''").replaceAll("\"", "\"\"")}'::text, website = '${business.website!}'::text, "contactName" = '${business.contactName!.replaceAll("'", "''").replaceAll("\"", "\"\"")}'::text, "contactPhone" = '${business.contactPhone!}'::text, "contactEmail" = '${business.contactEmail!}'::text, notes = '${business.notes!.replaceAll("'", "''").replaceAll("\"", "\"\"")}'::text, "locationName" = '${business.locationName!.replaceAll("'", "''").replaceAll("\"", "\"\"")}'::text, "locationAddress" = '${business.locationAddress!.replaceAll("'", "''").replaceAll("\"", "\"\"")}'::text WHERE
|
||||
id = ${business.id};
|
||||
''');
|
||||
'''
|
||||
.replaceAll("'null'", 'NULL'));
|
||||
|
||||
var logoResponse = await http.get(
|
||||
Uri.http('logo.clearbit.com', '/${business.website}'),
|
||||
@@ -546,7 +621,8 @@ void main() async {
|
||||
UPDATE listings SET
|
||||
"businessId" = ${listing.businessId}, name = '${listing.name.replaceAll("'", "''")}'::text, description = '${listing.description.replaceAll("'", "''")}'::text, type = '${listing.type.name}'::text, wage = '${listing.wage ?? 'NULL'}'::text, link = '${listing.link?.replaceAll("'", "''") ?? 'NULL'}'::text WHERE
|
||||
id = ${listing.id};
|
||||
''');
|
||||
'''
|
||||
.replaceAll("'null'", 'NULL'));
|
||||
|
||||
return Response.ok(
|
||||
listing.id.toString(),
|
||||
|
||||
Reference in New Issue
Block a user