Skip to content

Commit

Permalink
Minor changes to Organization and add endpoint for address. Add Aviny…
Browse files Browse the repository at this point in the history
…a type table
  • Loading branch information
rukmal committed Sep 27, 2022
1 parent 9ed14fc commit f77c465
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
21 changes: 21 additions & 0 deletions api/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ service graphql:Service /graphql on new graphql:Listener(4000) {
return new (name, id);
}

remote function add_address(Address address) returns AddressData|error? {
sql:ExecutionResult res = check db_client->execute(
`INSERT INTO avinya_db.address (
street_address,
phone,
city_id
) VALUES (
${address.street_address},
${address.phone},
${address.city_id}
);`
);

int|string? insert_id = res.lastInsertId;
if !(insert_id is int) {
return error("Unable to insert addresss");
}

return new(insert_id);
}

remote function add_organization(Organization org) returns OrganizationData|error? {
sql:ExecutionResult res = check db_client->execute(
`INSERT INTO avinya_db.organization (
Expand Down
6 changes: 3 additions & 3 deletions db/schema/1-base_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ USE avinya_db;


-- Insert Sri Lanka Province data
INSERT INTO province (id, name_en, name_si, name_ta) VALUES
INSERT IGNORE INTO province (id, name_en, name_si, name_ta) VALUES
(1, 'Western', 'බස්නාහිර', 'மேல்'),
(2, 'Central', 'මධ්‍යම', 'மத்திய'),
(3, 'Southern', 'දකුණු', 'தென்'),
Expand All @@ -15,7 +15,7 @@ INSERT INTO province (id, name_en, name_si, name_ta) VALUES


-- Insert Sri Lanka District data
INSERT INTO district (id, province_id, name_en, name_si, name_ta) VALUES
INSERT IGNORE INTO district (id, province_id, name_en, name_si, name_ta) VALUES
(1, 6, 'Ampara', 'අම්පාර', 'அம்பாறை'),
(2, 8, 'Anuradhapura', 'අනුරාධපුරය', 'அனுராதபுரம்'),
(3, 7, 'Badulla', 'බදුල්ල', 'பதுளை'),
Expand Down Expand Up @@ -44,7 +44,7 @@ INSERT INTO district (id, province_id, name_en, name_si, name_ta) VALUES


-- Insert Sri Lanka City data
INSERT INTO city (id, district_id, name_en, name_si, name_ta, suburb_name_en, suburb_name_si, suburb_name_ta, postcode, latitude, longitude) VALUES
INSERT IGNORE INTO city (id, district_id, name_en, name_si, name_ta, suburb_name_en, suburb_name_si, suburb_name_ta, postcode, latitude, longitude) VALUES
(1, 1, 'Akkaraipattu', 'අක්කරපත්තුව', 'அக்கரைப்பற்று', NULL, NULL, NULL, '32400', '7.21842790', '81.85411610'),
(2, 1, 'Ambagahawatta', 'අඹගහවත්ත', 'அம்பகஹவத்த', NULL, NULL, NULL, '90326', '7.30175630', '81.67472950'),
(3, 1, 'Ampara', 'අම්පාර', 'அம்பாறை', NULL, NULL, NULL, '32000', '7.30175630', '81.67472950'),
Expand Down
5 changes: 1 addition & 4 deletions db/schema/2-organization_and_address_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ USE avinya_db;
-- Address
CREATE TABLE IF NOT EXISTS address (
id INT NOT NULL PRIMARY KEY,
name_en VARCHAR(255) NOT NULL,
name_ta VARCHAR(255),
name_si VARCHAR(255),
street_address VARCHAR(255) NOT NULL,
phone INT,
city_id INT NOT NULL,
Expand All @@ -18,7 +15,7 @@ CREATE TABLE IF NOT EXISTS organization (
name_en VARCHAR(255) NOT NULL,
name_ta VARCHAR(255),
name_si VARCHAR(255),
phone int,
phone INT,
address_id INT NOT NULL,
FOREIGN KEY (address_id) REFERENCES address(id)
);
Expand Down
27 changes: 27 additions & 0 deletions db/schema/3-avinya_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
USE avinya_db;

CREATE TABLE IF NOT EXISTS avinya_type (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
active BOOLEAN NOT NULL,
global_type ENUM("Employee", "Customer", "Volunteer", "Applicant", "Team") NOT NULL,
name VARCHAR(255),
foundation_type ENUM(
"Advisors",
"Educator",
"Technology",
"Operations",
"Parent",
"Student"
),
focus ENUM(
"Bootcamp",
"Healthcare",
"Information Technology"
),
level INT
);

ALTER TABLE organization
ADD COLUMN avinya_type INT NOT NULL;
ALTER TABLE organization
ADD FOREIGN KEY (avinya_type) REFERENCES avinya_db.avinya_type(id);

0 comments on commit f77c465

Please sign in to comment.