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

Feature/notion models and commands #121

Draft
wants to merge 82 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
4f06203
very prototypical implementation for NotionModels
johguentner Feb 2, 2023
1a52591
Apply fixes from StyleCI (#101)
mechelon Feb 2, 2023
2ff9739
Merge branch 'dev' into feature/notion-models-and-commands
johguentner Feb 2, 2023
b828f88
Merge branch 'feature/notion-models-and-commands' of https://github.c…
johguentner Feb 2, 2023
bba2098
fix: after merge of filter-changes
johguentner Feb 4, 2023
c3d4b48
add the ability to resolve users and parents
johguentner Feb 6, 2023
31bd869
Apply fixes from StyleCI (#115)
mechelon Feb 6, 2023
27f4fe9
Merge branch 'dev' into feature/resolve
johguentner Feb 6, 2023
9a3dbb3
fix: modify changed method within `NotionParent`
johguentner Feb 6, 2023
cf07ff9
add `asText` override to title and text property
johguentner Feb 16, 2023
8c53b2a
polish notion model creation and usage
johguentner Feb 16, 2023
ea5cc25
Apply fixes from StyleCI (#120)
mechelon Feb 16, 2023
9fe5ae3
Merge branch 'dev' into feature/notion-models-and-commands
johguentner Feb 16, 2023
18240e4
Merge branch 'feature/notion-models-and-commands' of https://github.c…
johguentner Feb 16, 2023
bbaa2a9
fix: remove duplicated `asText`
johguentner Feb 16, 2023
4cbdff9
Apply fixes from StyleCI (#122)
mechelon Feb 16, 2023
911d8c6
polish: exclude `$page` of `NotionModel`
johguentner Feb 16, 2023
99c2523
Merge branch 'feature/notion-models-and-commands' of https://github.c…
johguentner Feb 16, 2023
516ccc7
Merge branch 'feature/resolve' into feature/notion-models-and-commands
johguentner Feb 16, 2023
f828d7d
Apply fixes from StyleCI (#123)
mechelon Feb 16, 2023
3c9c845
add prototypical relation resolving
johguentner Feb 16, 2023
0f180a9
Merge branch 'feature/resolve' into feature/notion-models-and-commands
johguentner Feb 16, 2023
29c991a
Apply fixes from StyleCI (#124)
mechelon Feb 16, 2023
27620d3
Apply fixes from StyleCI (#125)
mechelon Feb 16, 2023
c7a5bf2
create trait for title attribute
johguentner Apr 28, 2023
f19db04
add property type names within `Property::class`
johguentner Apr 28, 2023
8963193
add comment for clarification
johguentner Apr 28, 2023
29d56f5
add `HasTitle` traidMapping of `Entity::class`
johguentner Apr 28, 2023
8356792
implementation: start with database-building
johguentner Apr 28, 2023
0deaee7
Apply fixes from StyleCI (#134)
mechelon Apr 28, 2023
44aee37
implement further and polish database creation
johguentner Apr 29, 2023
766c7ab
Merge branch 'feature/database-creation' of https://github.com/5am-co…
johguentner Apr 29, 2023
589455a
Apply fixes from StyleCI (#136)
mechelon Apr 29, 2023
478f224
add further database attributes
johguentner Apr 29, 2023
b9f3eda
Merge branch 'feature/database-creation' of https://github.com/5am-co…
johguentner Apr 29, 2023
667928e
Apply fixes from StyleCI (#137)
mechelon Apr 29, 2023
85190f9
Merge branch 'dev' into feature/database-creation
johguentner Apr 30, 2023
2e70438
fix: in `HttpRecorder`, allow query to be empty
johguentner Apr 30, 2023
f6c870d
fix: missing default name for status properties
johguentner Apr 30, 2023
97be981
add tests for db creation in databases endpoint
johguentner Apr 30, 2023
53c15fb
polish `PestHttpRecorder::class`
johguentner Apr 30, 2023
2edd4ea
add query names to `RecordedEndpoint` tests
johguentner Apr 30, 2023
039f8f9
update existing snapshots
johguentner Apr 30, 2023
ad5d85d
Apply fixes from StyleCI (#141)
mechelon Apr 30, 2023
39d981d
add no-title-property test
johguentner Apr 30, 2023
71416dc
update current snapshots (database creation)
johguentner Apr 30, 2023
5ef1f93
Apply fixes from StyleCI (#142)
mechelon Apr 30, 2023
04f9be6
Merge branch 'dev' into feature/database-creation
johguentner Apr 30, 2023
68cb62f
Merge branch 'dev' into feature/resolve
johguentner Apr 30, 2023
fe961c8
add and polish phpdocs
johguentner May 2, 2023
fe0707c
Apply fixes from StyleCI (#144)
mechelon May 2, 2023
1e4f0ff
Merge branch 'dev' into feature/resolve
johguentner May 2, 2023
246396f
polish phpdocs of comment endpoint
johguentner May 2, 2023
d27f4ff
Apply fixes from StyleCI (#145)
mechelon May 2, 2023
9a3730b
polish: add newline to improve readability
johguentner May 2, 2023
69e15bd
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel…
johguentner May 2, 2023
55fe958
Apply fixes from StyleCI (#146)
mechelon May 2, 2023
4244807
git
johguentner May 2, 2023
2b11b70
add `parentOf` to access parents easily
johguentner May 2, 2023
a82ebeb
Apply fixes from StyleCI (#147)
mechelon May 2, 2023
eb7b39b
polish `PestHttpRecorder::class`
johguentner Apr 30, 2023
c83c9b1
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel…
johguentner May 3, 2023
cd8116d
Apply fixes from StyleCI (#148)
mechelon May 3, 2023
e73207a
add tests for `Notion::resolve()`; polish record
johguentner Jun 9, 2023
13a560d
build snapshots for resolve and
johguentner Jun 9, 2023
1c27736
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel…
johguentner Jun 9, 2023
44626bb
Apply fixes from StyleCI (#152)
mechelon Jun 9, 2023
b01fc99
add simple phpdbg code coverage (cmd)
johguentner Jun 10, 2023
0cbd9de
add additional tests for resolve endpoint
johguentner Jun 10, 2023
1f6aa11
Apply fixes from StyleCI (#153)
mechelon Jun 10, 2023
54f10a3
Merge branch 'feature/resolve' into feature/database-creation
johguentner Jun 10, 2023
a389879
add missing properties for database creation test
johguentner Jun 10, 2023
9d2e153
updated snapshots (database creation)
johguentner Jun 10, 2023
fe76f73
Apply fixes from StyleCI (#154)
mechelon Jun 10, 2023
f3aa549
fix type for workspace in `NotionParent::class`
johguentner Jun 10, 2023
7b7395b
add resolve/parent tests regarding NotionParent
johguentner Jun 10, 2023
016009e
add snapshot for parent testing
johguentner Jun 10, 2023
f945728
Apply fixes from StyleCI (#155)
mechelon Jun 10, 2023
4418da5
Merge branch 'feature/resolve' into feature/notion-models-and-commands
johguentner Jun 16, 2023
8dff823
Merge branch 'feature/database-creation' into feature/notion-models-a…
johguentner Jun 16, 2023
8f80b4a
move make-notion-model content to blade
johguentner Jun 16, 2023
4a17d50
Apply fixes from StyleCI (#157)
mechelon Jun 16, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor
.phpunit.result.cache
coverage/
.phpunit.cache/
.env*
.env*
coverage-report
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@
},
"scripts": {
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage-html coverage"
"test-coverage": "phpdbg -qrr ./vendor/bin/pest --coverage-html ./coverage-report"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
Expand Down
239 changes: 239 additions & 0 deletions src/Builder/DatabaseBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
<?php

namespace FiveamCode\LaravelNotionApi\Builder;

use FiveamCode\LaravelNotionApi\Endpoints\Databases;
use FiveamCode\LaravelNotionApi\Entities\Database;
use Illuminate\Support\Collection;

/**
* Class DatabaseBuilder.
*/
class DatabaseBuilder
{
/**
* @var array
*/
private array $payload;

/**
* DatabaseBuilder constructor.
*
* @param Databases $databasesEndpoint
*/
public function __construct(private Databases $databasesEndpoint)
{
$this->payload = [
'is_inline' => false,
'parent' => [],
'title' => [
[
'text' => [
'content' => '',
],
],
],
'properties' => [],
];
}

/**
* Creates database within given page.
*
* @param string $pageId
* @return Database
*/
public function createInPage($pageId): Database
{
$this->payload['parent'] = [
'type' => 'page_id',
'page_id' => $pageId,
];

if ($this->payload['properties'] === []) {
$this->addTitle();
}

return $this->databasesEndpoint->create($this->payload());
}

/**
* Sets the title for the database creation.
*
* @param string $title
* @return DatabaseBuilder
*/
public function title(string $title): DatabaseBuilder
{
$this->payload['title'] = [
[
'text' => [
'content' => $title,
],
],
];

return $this;
}

/**
* Sets the description for the database creation.
*
* @param string $description
* @return DatabaseBuilder
*/
public function description(string $description): DatabaseBuilder
{
$this->payload['description'] = [
[
'text' => [
'content' => $description,
],
],
];

return $this;
}

/**
* Sets the created database as inline (currently not supported).
*
* @todo increase Notion API Version, to make this work
*
* @return DatabaseBuilder
*/
public function inline(): DatabaseBuilder
{
$this->payload['is_inline'] = true;

return $this;
}

/**
* Sets the icon for the database creation.
*
* @param string $icon
* @return DatabaseBuilder
*/
public function iconEmoji(string $icon): DatabaseBuilder
{
$this->payload['icon'] = [
'type' => 'emoji',
'emoji' => $icon,
];

return $this;
}

/**
* Sets the icon for the database creation.
*
* @param string $url
* @return DatabaseBuilder
*/
public function iconExternal(string $url): DatabaseBuilder
{
$this->payload['icon'] = [
'type' => 'external',
'external' => [
'url' => $url,
],
];

return $this;
}

/**
* Sets the cover for the database creation.
*
* @param string $url
* @return DatabaseBuilder
*/
public function coverExternal(string $url): DatabaseBuilder
{
$this->payload['cover'] = [
'type' => 'external',
'external' => [
'url' => $url,
],
];

return $this;
}

/**
* Adds the property `title` database creation.
*
* @param string $name
* @return DatabaseBuilder
*/
public function addTitle(string $name = 'Name')
{
$this->add(PropertyBuilder::title($name));

return $this;
}

/**
* Adds one or multiple properties to the database creation.
*
* @param PropertyBuilder|Collection|DatabaseSchemeBuilder $properties
* @return DatabaseBuilder
*/
public function add(PropertyBuilder|Collection|DatabaseSchemeBuilder $properties): DatabaseBuilder
{
if ($properties instanceof PropertyBuilder) {
$properties = collect([$properties]);
}

if ($properties instanceof DatabaseSchemeBuilder) {
$properties = $properties->getProperties();
}

$properties->each(function (PropertyBuilder $property) {
$this->payload['properties'][$property->getName()] = $property->payload();
});

return $this;
}

/**
* Adds multiple properties to the database creation, similar to a Laravel migration.
*
* @param callable $callback
* @return DatabaseBuilder
*/
public function scheme(callable $callback): DatabaseBuilder
{
$builder = new DatabaseSchemeBuilder();
$callback($builder);

return $this->add($builder);
}

/**
* Adds a raw property to the database creation.
*
* @param string $title
* @param string $propertyType
* @param array|null $content
* @return DatabaseBuilder
*/
public function addRaw(string $title, string $propertyType, array $content = null): DatabaseBuilder
{
$this->payload['properties'][$title] = [];
$this->payload['properties'][$title][$propertyType] = $content ?? new \stdClass();

return $this;
}

/**
* Returns the payload for the database creation.
*
* @return array
*/
public function payload(): array
{
return $this->payload;
}
}
Loading