feat: Implement the actual card creation

This commit is contained in:
Dendy 2025-04-09 08:39:18 +02:00
parent 9093b1a0f8
commit 3ac2cd7319
3 changed files with 30 additions and 1 deletions

View File

@ -206,7 +206,10 @@ class CreateProductionCommand extends Command
)); ));
$theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]); $theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]);
dd(SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm)); $newSlNote = SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm);
if (!$this->ankiService->addNote($newSlNote, 'production')) {
throw new \Exception('Failed to add note!');
}
printf( printf(
<<<FMNT <<<FMNT

View File

@ -22,6 +22,11 @@ class Note
{ {
return $this->id; return $this->id;
} }
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getModel(): string public function getModel(): string
{ {
return $this->model; return $this->model;
@ -36,6 +41,11 @@ class Note
$this->fields = $fields; $this->fields = $fields;
return $this; return $this;
} }
/** @return list<string> */
public function getTags(): array
{
return $this->tags;
}
// ------------------------------------------------------- Anki-related --- // ------------------------------------------------------- Anki-related ---

View File

@ -32,6 +32,22 @@ class AnkiService
return $result; return $result;
} }
/** The note's id is updated on success.
* @return bool True on success
*/
public function addNote(Note &$note, string $deckName): bool
{
$note->setId($this->request('addNote', ['note' => [
'deckName' => $deckName,
'modelName' => $note->getModel(),
'fields' => $note->getFields(),
'options' => ['allowDuplicate' => false],
'tags' => array_merge($note->getTags(), ['anker_made']),
]]));
return $note->getId() !== null;
}
public function findNotesIds(string $query): array public function findNotesIds(string $query): array
{ {
return $this->request('findNotes', ['query' => $query]); return $this->request('findNotes', ['query' => $query]);