Can create the notes with more optional parameters

This commit is contained in:
Matias De lellis
2020-09-19 13:54:39 -03:00
parent 4f260c9af0
commit 5e076da22a
3 changed files with 58 additions and 6 deletions

View File

@@ -96,9 +96,27 @@ class NoteApiController extends ApiController {
* @param string $title
* @param string $content
* @param string $color
* @param bool $isPinned
* @param array $sharedWith
* @param array $tags
* @param array $attachments
*/
public function create(string $title, string $content, string $color = null) {
$note = $this->noteService->create($this->userId, $title, $content, $color);
public function create(string $title,
string $content,
string $color = null,
bool $isPinned = false,
array $sharedWith = [],
array $tags = [],
array $attachments = [])
{
$note = $this->noteService->create($this->userId,
$title,
$content,
$color,
$isPinned,
$sharedWith,
$tags,
$attachments);
$etag = md5(json_encode($note));

View File

@@ -90,9 +90,27 @@ class NoteController extends Controller {
* @param string $title
* @param string $content
* @param string $color
* @param bool $isPinned
* @param array $sharedWith
* @param array $tags
* @param array $attachments
*/
public function create(string $title, string $content, string $color = null) {
$note = $this->noteService->create($this->userId, $title, $content, $color);
public function create(string $title,
string $content,
string $color = null,
bool $isPinned = false,
array $sharedWith = [],
array $tags = [],
array $attachments = [])
{
$note = $this->noteService->create($this->userId,
$title,
$content,
$color,
$isPinned,
$sharedWith,
$tags,
$attachments);
$etag = md5(json_encode($note));

View File

@@ -152,9 +152,21 @@ class NoteService {
* @param string $userId
* @param string $title
* @param string $content
* @param string $color
* @param string $color optional color.
* @param bool $isPinned optional if note must be pinned
* @param array $sharedWith optional list of shares
* @param array $tags optional list of tags
* @param array $attachments optional list of attachments
*/
public function create(string $userId, string $title, string $content, string $color = NULL): Note {
public function create(string $userId,
string $title,
string $content,
string $color = null,
bool $isPinned = false,
array $sharedWith = [],
array $tags = [],
array $attachments = []): ?Note
{
if (is_null($color)) {
$color = $this->settingsService->getColorForNewNotes();
}
@@ -168,17 +180,21 @@ class NoteService {
$hcolor = $this->colormapper->insert($hcolor);
}
// Create note and insert it
$note = new Note();
$note->setTitle($title);
$note->setContent($content);
$note->setPinned($isPinned ? 1 : 0);
$note->setTimestamp(time());
$note->setColorId($hcolor->id);
$note->setUserId($userId);
$newNote = $this->notemapper->insert($note);
// TODO: Insert optional shares, tags and attachments.
// Insert true color pin and tags to response
$newNote->setColor($hcolor->getColor());
$newNote->setIsPinned(false);