Skip to content

Commit

Permalink
ongoing for module activities
Browse files Browse the repository at this point in the history
  • Loading branch information
datenangebot committed Apr 13, 2021
1 parent b91f14f commit 21d18f0
Show file tree
Hide file tree
Showing 23 changed files with 3,180 additions and 228 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Health
##### version 1.0.2
##### version 1.1.0
### Track your health. Use the advantages of a trusted platform.

The app provides different modules to track your health data.
Expand All @@ -10,10 +10,14 @@ Following modules are served
- Measurement
- Sleep
- Smoking
- Activities


### Changelog

v1.1.0
- add module activities

v1.0.2
- fix db definitions to work with nc21
- fix constructor parameter for mapper to work with nc21
Expand Down
3 changes: 2 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Following modules are served
- Measurement
- Sleep
- Smoking
- Activities
Health is everything.]]></description>
<version>1.0.2</version>
<version>1.1.0</version>
<licence>agpl</licence>
<author mail="flost-dev@mailbox.org" >Florian Steffens</author>
<namespace>Health</namespace>
Expand Down
6 changes: 6 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@
['name' => 'smokingdata#create', 'url' => '/smoking/dataset/person/{personId}', 'verb' => 'POST'],
['name' => 'smokingdata#delete', 'url' => '/smoking/dataset/{id}', 'verb' => 'DELETE'],
['name' => 'smokingdata#update', 'url' => '/smoking/dataset/{id}', 'verb' => 'PUT'],

// activities data
['name' => 'activitiesdata#findByPerson', 'url' => '/activities/dataset/person/{personId}', 'verb' => 'GET'],
['name' => 'activitiesdata#create', 'url' => '/activities/dataset/person/{personId}', 'verb' => 'POST'],
['name' => 'activitiesdata#delete', 'url' => '/activities/dataset/{id}', 'verb' => 'DELETE'],
['name' => 'activitiesdata#update', 'url' => '/activities/dataset/{id}', 'verb' => 'PUT'],
]
];
2,083 changes: 1,864 additions & 219 deletions js/health-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/health-main.js.map

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions lib/Controller/ActivitiesdataController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Florian Steffens <flost-dev@mailbox.org>
*
* @author Florian Steffens <flost-dev@mailbox.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Health\Controller;

use OCA\Health\Services\ActivitiesdataService;
use OCP\IRequest;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;

class ActivitiesdataController extends Controller {

protected $userId;
protected $activitiesdataService;

public function __construct($appName, IRequest $request, ActivitiesdataService $aS, $userId) {
parent::__construct($appName, $request);
$this->activitiesdataService = $aS;
$this->userId = $userId;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param int $personId
* @return DataResponse
*/
public function findByPerson(int $personId): DataResponse
{
return new DataResponse($this->activitiesdataService->getAllByPersonId($personId));
}

/**
* @NoAdminRequired
*
* @param int $personId
* @param string $datetime
* @param int|null $calories
* @param float|null $duration
* @param int|null $category
* @param int|null $feeling
* @param int|null $intensity
* @param float|null $distance
* @param string $comment
* @return DataResponse
*/
public function create(int $personId, string $datetime, int $calories = null, float $duration = null, int $category = null, int $feeling = null, int $intensity = null, float $distance = null, string $comment = ''): DataResponse
{
return new DataResponse($this->activitiesdataService->create($personId, $datetime, $calories, $duration, $category, $feeling, $intensity, $distance, $comment));
}

/**
* @NoAdminRequired
*
* @param int $id
* @return DataResponse
*/
public function delete(int $id): DataResponse
{
return new DataResponse($this->activitiesdataService->delete($id));
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string $datetime
* @param int|null $calories
* @param float|null $duration
* @param int|null $category
* @param int|null $feeling
* @param int|null $intensity
* @param float|null $distance
* @param string $comment
* @return DataResponse
*/
public function update(int $id, string $datetime, int $calories = null, float $duration = null, int $category = null, int $feeling = null, int $intensity = null, float $distance = null, string $comment = ''): DataResponse
{
return new DataResponse($this->activitiesdataService->update($id, $datetime, $calories, $duration, $category, $feeling, $intensity, $distance, $comment));
}
}
67 changes: 67 additions & 0 deletions lib/Db/Activitiesdata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* @copyright Copyright (c) 2020 Florian Steffens <flost-dev@mailbox.org>
*
* @author Florian Steffens <flost-dev@mailbox.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Health\Db;

use JsonSerializable;

use OCP\AppFramework\Db\Entity;

class Activitiesdata extends Entity implements JsonSerializable {

protected $personId;
protected $datetime;
protected $calories;
protected $duration;
protected $category;
protected $feeling;
protected $intensity;
protected $distance;
protected $comment;

public function __construct() {
$this->addType('id','integer');
$this->addType('personId','integer');
$this->addType('duration','float');
$this->addType('category','integer');
$this->addType('feeling','integer');
$this->addType('intensity','integer');
$this->addType('distance','float');
}

public function jsonSerialize(): array
{
return [
'id' => $this->id,
'personId' => $this->personId,
'datetime' => $this->datetime,
'calories' => $this->calories,
'duration' => $this->duration,
'category' => $this->category,
'feeling' => $this->feeling,
'intensity' => $this->intensity,
'distance' => $this->distance,
'comment' => $this->comment,
];
}
}
62 changes: 62 additions & 0 deletions lib/Db/ActivitiesdataMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @copyright Copyright (c) 2020 Florian Steffens <flost-dev@mailbox.org>
*
* @author Florian Steffens <flost-dev@mailbox.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Health\Db;

use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;

class ActivitiesdataMapper extends QBMapper {

public function __construct(IDBConnection $db) {
parent::__construct($db, 'health_activitiesdata', Activitiesdata::class);
}

public function find(int $id): Entity
{
$qb = $this->db->getQueryBuilder();

$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($id))
);

return $this->findEntity($qb);
}

public function findAll(int $personId): array
{
$qb = $this->db->getQueryBuilder();

$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('person_id', $qb->createNamedParameter($personId))
);

return $this->findEntities($qb);
}

}
30 changes: 28 additions & 2 deletions lib/Db/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ class Person extends Entity implements JsonSerializable {
protected $smokingStartValue;
protected $smokingPrice;

// module activities
protected $activitiesColumnCalories;
protected $activitiesColumnDuration;
protected $activitiesColumnCategory;
protected $activitiesColumnFeeling;
protected $activitiesColumnIntensity;
protected $activitiesColumnDistance;
protected $activitiesDistanceUnit;

public function __construct() {
// general
$this->addType('id','integer');
Expand All @@ -121,8 +130,16 @@ public function __construct() {
$this->addType('enabledModuleSleep', 'boolean');
$this->addType('enabledModuleSmoking', 'boolean');

// module weight
$this->addType('weightTarget', 'float');
// module activities
$this->addType('activitiesColumnCalories', 'boolean');
$this->addType('activitiesColumnDuration', 'boolean');
$this->addType('activitiesColumnCategory', 'boolean');
$this->addType('activitiesColumnFeeling', 'boolean');
$this->addType('activitiesColumnIntensity', 'boolean');
$this->addType('activitiesColumnDistance', 'boolean');

// module weight
$this->addType('weightTarget', 'float');
$this->addType('weightTargetInitialWeight', 'float');
$this->addType('weightColumnWeight', 'boolean');
$this->addType('weightColumnBodyfat', 'boolean');
Expand Down Expand Up @@ -195,6 +212,15 @@ public function jsonSerialize(): array
'enabledModuleNutrition' => $this->enabledModuleNutrition,
'enabledModuleSmoking' => $this->enabledModuleSmoking,

// module activities
'activitiesColumnCalories' => $this->activitiesColumnCalories,
'activitiesColumnDuration' => $this->activitiesColumnDuration,
'activitiesColumnCategory' => $this->activitiesColumnCategory,
'activitiesColumnFeeling' => $this->activitiesColumnFeeling,
'activitiesColumnIntensity' => $this->activitiesColumnIntensity,
'activitiesColumnDistance' => $this->activitiesColumnDistance,
'activitiesDistanceUnit' => $this->activitiesDistanceUnit,

// module weight
'weightMeasurementName' => $this->weightMeasurementName,
'weightUnit' => $this->weightUnit,
Expand Down
Loading

0 comments on commit 21d18f0

Please sign in to comment.