Skip to content

Commit

Permalink
Implemented Basic UI Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ksainc committed Oct 7, 2023
1 parent 34fa1f2 commit 319c9b5
Show file tree
Hide file tree
Showing 7 changed files with 1,375 additions and 262 deletions.
15 changes: 15 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,20 @@
'url' => '/list-services',
'verb' => 'GET'
],
[
'name' => 'UserConfiguration#createService',
'url' => '/create-service',
'verb' => 'PUT'
],
[
'name' => 'UserConfiguration#modifyService',
'url' => '/modify-service',
'verb' => 'PUT'
],
[
'name' => 'UserConfiguration#deleteService',
'url' => '/delete-service',
'verb' => 'PUT'
],
]
];
881 changes: 791 additions & 90 deletions js/data-userSettings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/data-userSettings.js.map

Large diffs are not rendered by default.

88 changes: 85 additions & 3 deletions lib/Controller/UserConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __construct(IRequest $request,
$this->DataService = $DataService;
$this->userId = $userId;
}

/**
* handels collections list requests
*
Expand All @@ -48,7 +47,6 @@ public function listCollections(string $type): DataResponse {
}

}

/**
* handels formats list requests
*
Expand All @@ -72,7 +70,6 @@ public function listFormats(string $type): DataResponse {
}

}

/**
* handels services list requests
*
Expand All @@ -96,4 +93,89 @@ public function listServices(): DataResponse {
}

}
/**
* handels services create requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function createService(array $data): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// evaluate, if required data is present
if (!empty($data['service_id']) && !empty($data['service_token']) &&
!empty($data['data_type']) && !empty($data['data_collection']) && !empty($data['format'])) {
// assign user id
$data['uid'] = $this->userId;
// create service
$rs = $this->DataService->createService($this->userId, $data);
}
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}
/**
* handels services modify requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function modifyService(array $data): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// evaluate, if required data is present
if (!empty($data['id']) && !empty($data['service_id']) && !empty($data['service_token']) &&
!empty($data['data_type']) && !empty($data['data_collection']) && !empty($data['format'])) {
// force read only permissions until write is implemented
$data['permissions'] = 'R';
// modify service
$rs = $this->DataService->modifyService($this->userId,(string) $data['id'], $data);
}
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}
/**
* handels services delete requests
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function deleteService($data): DataResponse {

// evaluate if user id is present
if ($this->userId === null) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
// evaluate, if required data is present
if (!empty($data['id'])) {
// delete service
$rs = $this->DataService->deleteService($this->userId,(string) $data['id']);
}
// return response
if (isset($rs)) {
return new DataResponse($rs);
} else {
return new DataResponse($rs['error'], 401);
}

}

}
121 changes: 96 additions & 25 deletions lib/Db/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public function __construct(IDBConnection $db) {
public function listByUserId(string $uid) : array {

// construct data store command
$dc = $this->DataStore->getQueryBuilder();
$cmd = $this->DataStore->getQueryBuilder();
if (empty($uid)) {
$dc->select('*')
$cmd->select('*')
->from($this->DataStoreTable);
}
else {
$dc->select('*')
$cmd->select('*')
->from($this->DataStoreTable)
->where($dc->expr()->eq('uid', $dc->createNamedParameter($uid)));
->where($cmd->expr()->eq('uid', $cmd->createNamedParameter($uid)));
}
// execute command
$rs = $dc->executeQuery()->fetchAll();
$dc->executeQuery()->closeCursor();
$rs = $cmd->executeQuery()->fetchAll();
$cmd->executeQuery()->closeCursor();
// return result or null
if (is_array($rs) && count($rs) > 0) {
return $rs;
Expand All @@ -83,12 +83,12 @@ public function listByUserId(string $uid) : array {
public function fetch(int $id) : array {

// construct data store command
$dc = $this->DataStore->getQueryBuilder();
$dc->select('*')
$cmd = $this->DataStore->getQueryBuilder();
$cmd->select('*')
->from($this->DataStoreTable)
->where($dc->expr()->eq('id', $dc->createNamedParameter($id)));
->where($cmd->expr()->eq('id', $cmd->createNamedParameter($id)));
// execute command and return result
return $this->findEntity($dc);
return $this->findEntity($cmd);

}

Expand All @@ -104,12 +104,12 @@ public function fetch(int $id) : array {
public function fetchByServiceId(string $id) : array {

// construct data store command
$dc = $this->DataStore->getQueryBuilder();
$dc->select('*')
$cmd = $this->DataStore->getQueryBuilder();
$cmd->select('*')
->from($this->DataStoreTable)
->where($dc->expr()->eq('service_id', $dc->createNamedParameter($id)));
->where($cmd->expr()->eq('service_id', $cmd->createNamedParameter($id)));
// execute command
$result = $dc->execute();
$result = $cmd->execute();
// return result
return $result->fetch();

Expand All @@ -120,23 +120,94 @@ public function fetchByServiceId(string $id) : array {
*
* @since Release 1.0.0
*
* @param array $entry collection of field names and values
* @param string $uid nextcloud user id
* @param array $data entry data
*
* @return array
* @return bool
*/
public function create(array $entry) : int {
public function create(array $data) : bool {

// construct data store command
$dc = $this->DataStore->getQueryBuilder();
$dc->insert($this->DataStoreTable);
foreach ($entry as $column => $value) {
$dc->setValue($column, $dc->createNamedParameter($value));
$cmd = $this->DataStore->getQueryBuilder();
$cmd->insert($this->DataStoreTable);
foreach ($data as $column => $value) {
$cmd->setValue($column, $cmd->createNamedParameter($value));
}
// execute command
$dc->execute();

// Get the ID of the newly inserted record (if needed)
return $this->DataStore->lastInsertId();
$cmd->execute();
// return result
return true;

}
/**
* modify a service entry in the data store
*
* @since Release 1.0.0
*
* @param string $id entry id
* @param array $data entry data
*
* @return bool
*/
public function modify(string $id, array $data) : bool {

// construct data store command
$cmd = $this->DataStore->getQueryBuilder();
$cmd->update($this->DataStoreTable)
->where($cmd->expr()->eq('id', $cmd->createNamedParameter($id)));
foreach ($data as $column => $value) {
$cmd->set($column, $cmd->createNamedParameter($value));
}
// execute command
$cmd->execute();
// return result
return true;

}
/**
* modify a service entry accessed data in the data store
*
* @since Release 1.0.0
*
* @param string $id entry id
* @param array $on accessed timestamp
* @param array $from accessed from
*
* @return bool
*/
public function modifyAccessed(string $id, int $on, string $from) : bool {

// construct data store command
$cmd = $this->DataStore->getQueryBuilder();
$cmd->update($this->DataStoreTable)
->where($cmd->expr()->eq('id', $cmd->createNamedParameter($id)))
->set('accessed_on', $cmd->createNamedParameter($on))
->set('accessed_from', $cmd->createNamedParameter($from));
// execute command
$cmd->execute();
// return result
return true;

}
/**
* delete a service entry from the data store
*
* @since Release 1.0.0
*
* @param string $id entry id
*
* @return bool
*/
public function delete(string $id) : bool {

// construct data store command
$cmd = $this->DataStore->getQueryBuilder();
$cmd->delete($this->DataStoreTable)
->where($cmd->expr()->eq('id', $cmd->createNamedParameter($id)));
// execute command
$cmd->execute();
// return result
return true;

}

Expand Down
Loading

0 comments on commit 319c9b5

Please sign in to comment.