Skip to content

Commit

Permalink
rename all necessary columns
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Sep 21, 2024
1 parent a8a9fcf commit 5d8dee9
Show file tree
Hide file tree
Showing 29 changed files with 609 additions and 241 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<id>cospend</id>
<name>Cospend</name>
<summary> </summary><description> </description>
<version>3.0.1</version>
<version>3.0.2</version>
<licence>agpl</licence>
<author mail="julien-nc@posteo.net">Julien Veyssier</author>
<namespace>Cospend</namespace>
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public function getLocalProjects(): DataResponse {
/**
* Get federated project list
*
* @return DataResponse<Http::STATUS_OK, CospendFullProjectInfo[], array{}>
* @return DataResponse<Http::STATUS_OK, list<array{id: int, remoteProjectId: string, remoteProjectName: string, remoteServerUrl: string, state: int, userId: string, inviterCloudId: string, inviterDisplayName: string}>, array{}>
* @throws Exception
*
* 200: Project list
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/PublicApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ public function publicDeleteBills(string $token, array $billIds, bool $moveToTra
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT, tags: ['Public-API_Projects'])]
public function publicGetProjectInfo(string $token): DataResponse {
$share = $this->shareMapper->getLinkOrFederatedShareByToken($token);
$projectInfo = $this->localProjectService->getProjectInfo($share->getProjectid());
$projectInfo = $this->localProjectService->getProjectInfo($share->getProjectId());
if ($projectInfo !== null) {
unset($projectInfo['userid']);
// set the visible access level for frontend
$projectInfo['myaccesslevel'] = $share->getAccesslevel() ;
$projectInfo['myaccesslevel'] = $share->getAccessLevel() ;
return new DataResponse($projectInfo);
}
return new DataResponse(
Expand Down
49 changes: 16 additions & 33 deletions lib/Db/BillMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ public function find(int $id): Bill {
return $this->mapRowToEntity($row);
}

/**
* Delete bill owers of given bill
*
* @param int $billId
* @return int
* @throws \OCP\DB\Exception
*/
public function deleteBillOwersOfBill(int $billId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete('cospend_bill_owers')
->where(
$qb->expr()->eq('billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
);
$nbDeleted = $qb->executeStatement();
return $nbDeleted;
}

public function deleteDeletedBills(string $projectId): void {
// first delete the bill owers
$qb = $this->db->getQueryBuilder();
Expand All @@ -84,7 +67,7 @@ public function deleteDeletedBills(string $projectId): void {

$qb->delete('cospend_bill_owers')
->where(
$qb2->expr()->in('billid', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY)
$qb2->expr()->in('bill_id', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY)
);
$qb->executeStatement();

Expand Down Expand Up @@ -130,7 +113,7 @@ public function deleteBills(string $projectId, ?string $what = null, ?int $minTi

$qb->delete('cospend_bill_owers')
->where(
$qb2->expr()->in('billid', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY)
$qb2->expr()->in('bill_id', $qb->createFunction($qb2->getSQL()), IQueryBuilder::PARAM_STR_ARRAY)
);
$nbBillOwersDeleted = $qb->executeStatement();
$qb = $this->db->getQueryBuilder();
Expand Down Expand Up @@ -258,19 +241,19 @@ public function getBill(string $projectId, int $billId): ?array {

$qb = $this->db->getQueryBuilder();

$qb->select('memberid', 'm.name', 'm.weight', 'm.activated')
$qb->select('bo.member_id', 'm.name', 'm.weight', 'm.activated')
->from('cospend_bill_owers', 'bo')
->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.memberid', 'm.id'))
->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.member_id', 'm.id'))
->where(
$qb->expr()->eq('bo.billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
$qb->expr()->eq('bo.bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
);
$req = $qb->executeQuery();

while ($row = $req->fetch()) {
$dbWeight = (float)$row['weight'];
$dbName = $row['name'];
$dbActivated = (((int)$row['activated']) === 1);
$dbOwerId = (int)$row['memberid'];
$dbOwerId = (int)$row['member_id'];
$billOwers[] = [
'id' => $dbOwerId,
'weight' => $dbWeight,
Expand Down Expand Up @@ -342,10 +325,10 @@ public function getBillsClassic(
$qb = $this->db->getQueryBuilder();
$qb->select('bi.id', 'what', 'comment', 'timestamp', 'amount', 'payer_id', 'repeat',
'payment_mode', 'payment_mode_id', 'category_id', 'bi.last_changed', 'repeat_all_active', 'repeat_until', 'repeat_frequency',
'deleted', 'memberid', 'm.name', 'm.weight', 'm.activated')
'deleted', 'bo.member_id', 'm.name', 'm.weight', 'm.activated')
->from('cospend_bill_owers', 'bo')
->innerJoin('bo', 'cospend_bills', 'bi', $qb->expr()->eq('bo.billid', 'bi.id'))
->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.memberid', 'm.id'))
->innerJoin('bo', 'cospend_bills', 'bi', $qb->expr()->eq('bo.bill_id', 'bi.id'))
->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.member_id', 'm.id'))
->where(
$qb->expr()->eq('bi.project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR))
);
Expand Down Expand Up @@ -432,7 +415,7 @@ public function getBillsClassic(
$dbWeight = (float)$row['weight'];
$dbName = $row['name'];
$dbActivated = ((int)$row['activated']) === 1;
$dbOwerId = (int)$row['memberid'];
$dbOwerId = (int)$row['member_id'];
$billDict[$dbBillId]['owers'][] = [
'id' => $dbOwerId,
'weight' => $dbWeight,
Expand Down Expand Up @@ -602,19 +585,19 @@ public function getBillsWithLimit(
$billOwers = [];
$billOwerIds = [];

$qb->select('memberid', 'm.name', 'm.weight', 'm.activated')
$qb->select('bo.member_id', 'm.name', 'm.weight', 'm.activated')
->from('cospend_bill_owers', 'bo')
->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.memberid', 'm.id'))
->innerJoin('bo', 'cospend_members', 'm', $qb->expr()->eq('bo.member_id', 'm.id'))
->where(
$qb->expr()->eq('bo.billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
$qb->expr()->eq('bo.bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
);
$qb->setFirstResult(0);
$req = $qb->executeQuery();
while ($row = $req->fetch()) {
$dbWeight = (float)$row['weight'];
$dbName = $row['name'];
$dbActivated = ((int)$row['activated']) === 1;
$dbOwerId = (int)$row['memberid'];
$dbOwerId = (int)$row['member_id'];
$billOwers[] = [
'id' => $dbOwerId,
'weight' => $dbWeight,
Expand Down Expand Up @@ -711,7 +694,7 @@ public function searchBills(string $projectId, string $term, ?int $deleted = 0):
$qb->select(
'b.id', 'what', 'comment', 'amount', 'timestamp',
'payment_mode', 'payment_mode_id', 'category_id',
'pr.currency_name', 'me.name', 'me.userid'
'pr.currency_name', 'me.name', 'me.user_id'
)
->from($this->getTableName(), 'b')
->innerJoin('b', 'cospend_projects', 'pr', $qb->expr()->eq('b.project_id', 'pr.id'))
Expand Down Expand Up @@ -741,7 +724,7 @@ public function searchBills(string $projectId, string $term, ?int $deleted = 0):
$dbCategoryId = (int)$row['category_id'];
$dbProjectCurrencyName = $row['currency_name'];
$dbPayerName = $row['name'];
$dbPayerUserId = $row['userid'];
$dbPayerUserId = $row['user_id'];
$bills[] = [
'id' => $dbBillId,
'projectId' => $projectId,
Expand Down
20 changes: 10 additions & 10 deletions lib/Db/BillOwer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
use OCP\AppFramework\Db\Entity;

/**
* @method int getBillid()
* @method void setBillid(int $billid)
* @method int getMemberid()
* @method void setMemberid(int $memberid)
* @method int getBillId()
* @method void setBillId(int $billId)
* @method int getMemberId()
* @method void setMemberId(int $memberId)
**/
class BillOwer extends Entity implements \JsonSerializable {

protected int $billid = 0;
protected int $memberid = 0;
protected int $billId = 0;
protected int $memberId = 0;

public function __construct() {
$this->addType('id', 'integer');
$this->addType('billid', 'integer');
$this->addType('memberid', 'integer');
$this->addType('bill_id', 'integer');
$this->addType('member_id', 'integer');
}

#[\ReturnTypeWillChange]
public function jsonSerialize() {
return [
'id' => $this->getId(),
'billid' => $this->getBillid(),
'memberid' => $this->getMemberid(),
'billid' => $this->getBillId(),
'memberid' => $this->getMemberId(),
];
}
}
4 changes: 2 additions & 2 deletions lib/Db/BillOwerMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function deleteBillOwersOfBill(int $billId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where(
$qb->expr()->eq('billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
$qb->expr()->eq('bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_INT))
);
$nbDeleted = $qb->executeStatement();
return $nbDeleted;
Expand All @@ -70,7 +70,7 @@ public function getOwersOfBill(int $billId): array {

$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('billid', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_STR)));
->where($qb->expr()->eq('bill_id', $qb->createNamedParameter($billId, IQueryBuilder::PARAM_STR)));

return $this->findEntities($qb);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Db/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use OCP\AppFramework\Db\Entity;

/**
* @method void setProjectid(string $projectid)
* @method string getProjectid()
* @method void setProjectId(string $projectId)
* @method string getProjectId()
* @method void setName(string|null $name)
* @method string|null getName()
* @method void setColor(string|null $color)
Expand All @@ -23,14 +23,14 @@
* @method int getOrder()
*/
class Category extends Entity implements \JsonSerializable {
protected string $projectid = '';
protected string $projectId = '';
protected ?string $name = null;
protected ?string $color = null;
protected ?string $encodedIcon = null;
protected int $order = 0;

public function __construct() {
$this->addType('projectid', 'string');
$this->addType('project_id', 'string');
$this->addType('name', 'string');
$this->addType('color', 'string');
$this->addType('encoded_icon', 'string');
Expand All @@ -40,7 +40,7 @@ public function __construct() {
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'projectid' => $this->getProjectid(),
'projectid' => $this->getProjectId(),
'name' => $this->getName(),
'color' => $this->getColor(),
'icon' => $this->getEncodedIcon() === null ? null : urldecode($this->getEncodedIcon()),
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/CategoryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getCategoryOfProject(string $projectId, int $id): Category {
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));
->andWhere($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));

return $this->findEntity($qb);
}
Expand All @@ -76,7 +76,7 @@ public function getCategoriesOfProject(string $projectId): array {

$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));
->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));

return $this->findEntities($qb);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Db/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
use OCP\AppFramework\Db\Entity;

/**
* @method void setProjectid(string $projectid)
* @method string getProjectid()
* @method void setProjectId(string $projectId)
* @method string getProjectId()
* @method void setName(string|null $name)
* @method string|null getName()
* @method void setExchangeRate(float|null $exchangeRate)
* @method float|null getExchangeRate()
*/
class Currency extends Entity implements \JsonSerializable {
protected string $projectid = '';
protected string $projectId = '';
protected ?string $name = null;
protected ?float $exchangeRate = null;

public function __construct() {
$this->addType('projectid', 'string');
$this->addType('project_id', 'string');
$this->addType('name', 'string');
$this->addType('exchange_rate', 'float');
}

public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'projectid' => $this->getProjectid(),
'projectid' => $this->getProjectId(),
'name' => $this->getName(),
'exchange_rate' => $this->getExchangeRate(),
];
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/CurrencyMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getCurrencyOfProject(string $projectId, int $id): Currency {
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));
->andWhere($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));

return $this->findEntity($qb);
}
Expand All @@ -76,7 +76,7 @@ public function getCurrenciesOfProject(string $projectId): array {

$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('projectid', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));
->where($qb->expr()->eq('project_id', $qb->createNamedParameter($projectId, IQueryBuilder::PARAM_STR)));

return $this->findEntities($qb);
}
Expand Down
Loading

0 comments on commit 5d8dee9

Please sign in to comment.