-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from avinyafoundation/main
2024A batch removed from the avinya system
- Loading branch information
Showing
6 changed files
with
451 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
public isolated service class VehicleData { | ||
|
||
private Vehicle vehicle; | ||
|
||
isolated function init(int? id = 0, int? person_id = 0, Vehicle? vehicle = null) returns error? { | ||
|
||
if (vehicle != null) { | ||
self.vehicle = vehicle.cloneReadOnly(); | ||
return; | ||
} | ||
|
||
lock { | ||
|
||
Vehicle vehicle_raw; | ||
|
||
if (id > 0) { | ||
|
||
vehicle_raw = check db_client->queryRow( | ||
`SELECT * | ||
FROM vehicle | ||
WHERE id = ${id};`); | ||
|
||
} else { | ||
vehicle_raw = check db_client->queryRow( | ||
`SELECT * | ||
FROM vehicle | ||
WHERE | ||
person_id = ${person_id};`); | ||
} | ||
|
||
self.vehicle = vehicle_raw.cloneReadOnly(); | ||
|
||
} | ||
|
||
} | ||
|
||
isolated resource function get id() returns int?|error { | ||
lock { | ||
return self.vehicle.id; | ||
} | ||
} | ||
|
||
isolated resource function get vehicle_number() returns string? { | ||
lock { | ||
return self.vehicle.vehicle_number; | ||
} | ||
} | ||
|
||
isolated resource function get organization() returns OrganizationData|error? { | ||
int id = 0; | ||
lock { | ||
id = self.vehicle.organization_id ?: 0; | ||
if (id == 0) { | ||
return null; // no point in querying if address id is null | ||
} | ||
} | ||
|
||
return new OrganizationData((), id); | ||
} | ||
|
||
isolated resource function get person_id() returns int? { | ||
lock { | ||
return self.vehicle.person_id; | ||
} | ||
} | ||
|
||
isolated resource function get person() returns PersonData|error? { | ||
int id = 0; | ||
lock { | ||
id = self.vehicle.person_id ?: 0; | ||
if (id == 0) { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
return new PersonData((), id); | ||
} | ||
|
||
|
||
isolated resource function get created() returns string? { | ||
lock { | ||
return self.vehicle.created; | ||
} | ||
} | ||
|
||
isolated resource function get updated() returns string? { | ||
lock { | ||
return self.vehicle.updated; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.