Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip #69

Merged
merged 21 commits into from
Oct 6, 2023
Merged

Wip #69

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@nextcloud"
]
}
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
/node_modules/
/vendor/
/vendor/
/build/artifacts/
/*.iml

# The content of this directories is build from the JS source (`src/`) when running `npm run build`
js/
css/
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ source:
# Builds the source package for the app store, ignores php and js tests
.PHONY: appstore
appstore:
make npm
rm -rf $(appstore_build_directory)
mkdir -p $(appstore_build_directory)
tar cvzf $(appstore_package_name).tar.gz \
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This requires the following things to be present:
* curl: used if phpunit and composer are not installed to fetch them from the web
* npm: for building and testing everything JS, only required if a package.json is placed inside the **js/** folder

The make command will install or update Composer dependencies if a composer.json is present and also **npm run build** if a package.json is present in the **js/** folder. The npm **build** script should use local paths for build systems and package managers, so people that simply want to build the app won't need to install npm libraries globally, e.g.:
The make command will install or update Composer dependencies if a composer.json is present and also **npm run build** if a package.json is present. The npm **build** script should use local paths for build systems and package managers, so people that simply want to build the app won't need to install npm libraries globally, e.g.:

**package.json**:
```json
Expand All @@ -25,7 +25,6 @@ The make command will install or update Composer dependencies if a composer.json
}
```


## Publish to App Store

First get an account for the [App Store](http://apps.nextcloud.com/) then run:
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<category>tools</category>
<bugs>https://github.com/tobiasKaminsky/GroceryList/issues</bugs>
<dependencies>
<nextcloud min-version="12" max-version="20"/>
<nextcloud min-version="27" max-version="28"/>
</dependencies>
<navigations>
<navigation>
Expand Down
41 changes: 19 additions & 22 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<?php
/**
* Create your routes in here. The name is the lowercase name of the controller
* without the controller part, the stuff after the hash is the method.
* e.g. page#index -> OCA\GroceryList\Controller\GroceryListController->index()
*
* The controller class has to be registered in the application.php file since
* it's instantiated in there
*/
return [
'routes' => [
['name' => 'GroceryList#showGroceryList', 'url' => '/list/{id}', 'verb' => 'GET'],

['name' => 'GroceryList#index', 'url' => '/', 'verb' => 'GET'],

['name' => 'GroceryList#lists', 'url' => '/lists', 'verb' => 'GET'],
['name' => 'GroceryList#saveList', 'url' => '/lists', 'verb' => 'POST'],
['name' => 'GroceryList#deleteList', 'url' => '/lists/{id}', 'verb' => 'DELETE'],
['name' => 'GroceryList#updateList', 'url' => '/lists/{id}', 'verb' => 'POST'],
['name' => 'GroceryList#showList', 'url' => '/list/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#lists', 'url' => '/api/lists', 'verb' => 'GET'],
['name' => 'GroceryList#saveList', 'url' => '/api/lists', 'verb' => 'POST'],
['name' => 'GroceryList#deleteList', 'url' => '/api/lists/{id}', 'verb' => 'DELETE'],
['name' => 'GroceryList#updateList', 'url' => '/api/lists/{id}', 'verb' => 'POST'],
['name' => 'GroceryList#renameList', 'url' => '/api/list/{id}', 'verb' => 'POST'],
['name' => 'GroceryList#showList', 'url' => '/api/list/{id}', 'verb' => 'GET'],

['name' => 'GroceryList#listItems', 'url' => '/items/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#addItem', 'url' => '/item/add', 'verb' => 'POST'],
['name' => 'GroceryList#checkItem', 'url' => '/item/check', 'verb' => 'POST'],
['name' => 'GroceryList#updateItem', 'url' => '/item/update', 'verb' => 'POST'],
['name' => 'GroceryList#listItems', 'url' => '/api/items/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#addItem', 'url' => '/api/item/add', 'verb' => 'POST'],
['name' => 'GroceryList#checkItem', 'url' => '/api/item/check', 'verb' => 'POST'],
['name' => 'GroceryList#updateItem', 'url' => '/api/item/update', 'verb' => 'POST'],
['name' => 'GroceryList#hideItem', 'url' => '/api/item/hide', 'verb' => 'POST'],
['name' => 'GroceryList#deleteItem', 'url' => '/item/{id}', 'verb' => 'DELETE'],

['name' => 'GroceryList#listCategories', 'url' => '/categories/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#listAllCategories', 'url' => '/all_categories/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#addCategory', 'url' => '/category/{id}/add', 'verb' => 'POST'],
['name' => 'GroceryList#updateCategory', 'url' => '/category/update', 'verb' => 'POST'],
['name' => 'GroceryList#listCategories', 'url' => '/api/categories/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#listAllCategories', 'url' => '/api/all_categories/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#addCategory', 'url' => '/api/category/{id}/add', 'verb' => 'POST'],
['name' => 'GroceryList#updateCategory', 'url' => '/api/category/update', 'verb' => 'POST'],

['name' => 'GroceryList#sharees', 'url' => '/sharees/{id}', 'verb' => 'GET'],
['name' => 'GroceryList#sharees', 'url' => '/api/sharees/{id}', 'verb' => 'GET'],
]
];
121 changes: 91 additions & 30 deletions lib/Controller/GroceryListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace OCA\GroceryList\Controller;

use Exception;

use OCA\GroceryList\Db\Category;
use OCA\GroceryList\Db\CategoryMapper;
use OCA\GroceryList\Db\GroceryList;
Expand All @@ -17,14 +15,15 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;

class GroceryListController extends Controller {
class GroceryListController extends Controller
{

private $groceryListMapper;
private $itemMapper;
private $categoryMapper;
private $shareeMapper;
private GroceryListMapper $groceryListMapper;
private ItemMapper $itemMapper;
private CategoryMapper $categoryMapper;
private ShareeGroceryListMapper $shareeMapper;
private $userId;
private $logger;
private ILogger $logger;

public function __construct($AppName,
IRequest $request,
Expand All @@ -33,7 +32,8 @@ public function __construct($AppName,
CategoryMapper $categoryMapper,
ShareeGroceryListMapper $shareeMapper,
ILogger $logger,
$UserId) {
$UserId)
{
parent::__construct($AppName, $request);
$this->groceryListMapper = $groceryListMapper;
$this->itemMapper = $itemMapper;
Expand All @@ -47,15 +47,29 @@ public function __construct($AppName,
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index() {
public function index()
{
// Register all scripts and styles we use on the frontend
\OCP\Util::addScript($this->appName, $this->appName . '-main'); // adding `js/grocerylist-main.mjs` generated from JS source
\OCP\Util::addStyle($this->appName, $this->appName . '-style'); // adding `css/grocerylist-style.css` generated from JS source
// return the template we use (see `templates/` folder)
return new TemplateResponse('grocerylist', 'main');
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function showGroceryList($id)
{
return $this->index();
}

/**
* @NoAdminRequired
*/
public function lists() {
public function lists()
{
return new DataResponse($this->groceryListMapper->findAll());
}

Expand All @@ -64,7 +78,8 @@ public function lists() {
* @param string $title
* @return DataResponse
*/
public function saveList(string $title) {
public function saveList(string $title)
{
$groceryList = new GroceryList();
$groceryList->setTitle($title);
$groceryList->setUserId($this->userId);
Expand All @@ -77,7 +92,8 @@ public function saveList(string $title) {
* @param int $id
* @return \OCP\AppFramework\Db\Entity
*/
public function deleteList(int $id) {
public function deleteList(int $id)
{
$groceryList = $this->groceryListMapper->find($id);
$this->groceryListMapper->delete($groceryList);

Expand All @@ -87,24 +103,40 @@ public function deleteList(int $id) {
/**
* @NoAdminRequired
* @param int $id
* @param string $name
* @param string $quantity
* @param int $category
* @return DataResponse
* @param string $title
* @param string $showOnlyUnchecked
*/
public function updateList(int $id, string $title, int $showOnlyUnchecked) {
public function renameList(int $id, string $title)
{
$list = $this->groceryListMapper->find($id);
$list->setTitle($title);

$this->groceryListMapper->update($list);
}


/**
* @NoAdminRequired
* @param int $id
* @param string $title
* @param string $showOnlyUnchecked
*/
public function updateList(int $id, string $title = '', int $showOnlyUnchecked = 0)
{
$list = $this->groceryListMapper->find($id);
$list->setShowOnlyUnchecked($showOnlyUnchecked);
$list->setTitle($title);

return new DataResponse($this->groceryListMapper->update($list));
$this->groceryListMapper->update($list);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @return DataResponse
*/
public function showList(int $id) {
public function showList(int $id)
{
return new DataResponse($this->groceryListMapper->find($id));
}

Expand All @@ -113,15 +145,26 @@ public function showList(int $id) {
* @NoCSRFRequired
* @param int $id
*/
public function listItems(int $id) {
public function listItems(int $id)
{
return new DataResponse($this->itemMapper->findAll($id));
}

/**
* @NoAdminRequired
* @param int $id
*/
public function listCategories(int $id) {
public function deleteItem(int $id) {
$item = $this->itemMapper->find($id);
$this->itemMapper->delete($item);
}

/**
* @NoAdminRequired
* @param int $id
*/
public function listCategories(int $id)
{
$returnList = [];
$categories = $this->categoryMapper->findAll($id);

Expand All @@ -138,7 +181,8 @@ public function listCategories(int $id) {
* @NoAdminRequired
* @param int $id
*/
public function listAllCategories(int $id) {
public function listAllCategories(int $id)
{
return new DataResponse($this->categoryMapper->findAll($id));
}

Expand All @@ -150,7 +194,8 @@ public function listAllCategories(int $id) {
* @param int $list
* @return DataResponse
*/
public function addItem(string $name, string $quantity, int $category, int $list) {
public function addItem(string $name, string $quantity, int $category, int $list)
{
$item = new Item();
$item->setName($name);
$item->setQuantity($quantity);
Expand All @@ -168,7 +213,8 @@ public function addItem(string $name, string $quantity, int $category, int $list
* @param int $category
* @return DataResponse
*/
public function updateItem(int $id, string $name, string $quantity, int $category) {
public function updateItem(int $id, string $name, string $quantity, int $category)
{
$item = $this->itemMapper->find($id);
$item->setName($name);
$item->setQuantity($quantity);
Expand All @@ -177,13 +223,25 @@ public function updateItem(int $id, string $name, string $quantity, int $categor
return new DataResponse($this->itemMapper->update($item));
}

/**
* @NoAdminRequired
*/
public function hideItem(int $id)
{
$item = $this->itemMapper->find($id);
$item->setHidden(time());

return new DataResponse($this->itemMapper->update($item));
}

/**
* @NoAdminRequired
* @param string $id
* @param int $checked
* @return DataResponse
*/
public function checkItem(int $id, int $checked) {
public function checkItem(int $id, int $checked)
{
$item = $this->itemMapper->find($id);
$item->setChecked($checked);

Expand All @@ -196,7 +254,8 @@ public function checkItem(int $id, int $checked) {
* @param string $name
* @return DataResponse
*/
public function addCategory(int $id, string $name) {
public function addCategory(int $id, string $name)
{
$category = new Category();
$category->setList($id);
$category->setName($name);
Expand All @@ -213,7 +272,8 @@ public function addCategory(int $id, string $name) {
* @param string $newName
* @return DataResponse
*/
public function updateCategory(int $id, string $newName) {
public function updateCategory(int $id, string $newName)
{
$category = $this->categoryMapper->find($id);
$category->setName($newName);

Expand All @@ -226,7 +286,8 @@ public function updateCategory(int $id, string $newName) {
* @NoAdminRequired
* @param int $id
*/
public function sharees(int $id): DataResponse {
public function sharees(int $id): DataResponse
{
return new DataResponse($this->shareeMapper->find($id));
}
}
}
6 changes: 4 additions & 2 deletions lib/Db/CategoryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public function findAll(int $id) {
->from($this->getTableName())
->where(
$qb->expr()->eq('list', $qb->createNamedParameter($id))
);
)
->orderBy("order")
;

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