-
-
Notifications
You must be signed in to change notification settings - Fork 50
Database Creation #135
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
Merged
Merged
Database Creation #135
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
c3d4b48
add the ability to resolve users and parents
johguentner 31bd869
Apply fixes from StyleCI (#115)
mechelon 27f4fe9
Merge branch 'dev' into feature/resolve
johguentner 9a3dbb3
fix: modify changed method within `NotionParent`
johguentner 3c9c845
add prototypical relation resolving
johguentner 29c991a
Apply fixes from StyleCI (#124)
mechelon c7a5bf2
create trait for title attribute
johguentner f19db04
add property type names within `Property::class`
johguentner 8963193
add comment for clarification
johguentner 29d56f5
add `HasTitle` traidMapping of `Entity::class`
johguentner 8356792
implementation: start with database-building
johguentner 0deaee7
Apply fixes from StyleCI (#134)
mechelon 44aee37
implement further and polish database creation
johguentner 766c7ab
Merge branch 'feature/database-creation' of https://github.com/5am-co…
johguentner 589455a
Apply fixes from StyleCI (#136)
mechelon 478f224
add further database attributes
johguentner b9f3eda
Merge branch 'feature/database-creation' of https://github.com/5am-co…
johguentner 667928e
Apply fixes from StyleCI (#137)
mechelon 85190f9
Merge branch 'dev' into feature/database-creation
johguentner 2e70438
fix: in `HttpRecorder`, allow query to be empty
johguentner f6c870d
fix: missing default name for status properties
johguentner 97be981
add tests for db creation in databases endpoint
johguentner 53c15fb
polish `PestHttpRecorder::class`
johguentner 2edd4ea
add query names to `RecordedEndpoint` tests
johguentner 039f8f9
update existing snapshots
johguentner ad5d85d
Apply fixes from StyleCI (#141)
mechelon 39d981d
add no-title-property test
johguentner 71416dc
update current snapshots (database creation)
johguentner 5ef1f93
Apply fixes from StyleCI (#142)
mechelon 04f9be6
Merge branch 'dev' into feature/database-creation
johguentner 68cb62f
Merge branch 'dev' into feature/resolve
johguentner fe961c8
add and polish phpdocs
johguentner fe0707c
Apply fixes from StyleCI (#144)
mechelon 1e4f0ff
Merge branch 'dev' into feature/resolve
johguentner 246396f
polish phpdocs of comment endpoint
johguentner d27f4ff
Apply fixes from StyleCI (#145)
mechelon 9a3730b
polish: add newline to improve readability
johguentner 69e15bd
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel…
johguentner 55fe958
Apply fixes from StyleCI (#146)
mechelon 2b11b70
add `parentOf` to access parents easily
johguentner a82ebeb
Apply fixes from StyleCI (#147)
mechelon eb7b39b
polish `PestHttpRecorder::class`
johguentner c83c9b1
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel…
johguentner cd8116d
Apply fixes from StyleCI (#148)
mechelon e73207a
add tests for `Notion::resolve()`; polish record
johguentner 13a560d
build snapshots for resolve and
johguentner 1c27736
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel…
johguentner 44626bb
Apply fixes from StyleCI (#152)
mechelon b01fc99
add simple phpdbg code coverage (cmd)
johguentner 0cbd9de
add additional tests for resolve endpoint
johguentner 1f6aa11
Apply fixes from StyleCI (#153)
mechelon 54f10a3
Merge branch 'feature/resolve' into feature/database-creation
johguentner a389879
add missing properties for database creation test
johguentner 9d2e153
updated snapshots (database creation)
johguentner fe76f73
Apply fixes from StyleCI (#154)
mechelon 9334b9b
minor polishes and cleanup
johguentner 6e54138
Apply fixes from StyleCI (#158)
mechelon 7129653
minor fix for resolve tests
johguentner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ vendor | |
.phpunit.result.cache | ||
coverage/ | ||
.phpunit.cache/ | ||
.env* | ||
.env* | ||
coverage-report |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
<?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; | ||
|
||
/** | ||
* @var Databases | ||
*/ | ||
private Databases $databasesEndpoint; | ||
|
||
/** | ||
* DatabaseBuilder constructor. | ||
* | ||
* @param Databases $databasesEndpoint | ||
*/ | ||
public function __construct(Databases $databasesEndpoint) | ||
{ | ||
$this->databasesEndpoint = $databasesEndpoint; | ||
$this->payload = [ | ||
'is_inline' => false, | ||
'parent' => [], | ||
'title' => [ | ||
[ | ||
'text' => [ | ||
'content' => '', | ||
], | ||
], | ||
], | ||
'properties' => [], | ||
]; | ||
} | ||
|
||
/** | ||
* Creates database within given page. | ||
* | ||
* @param string $pageId | ||
* @return Database | ||
*/ | ||
public function createInPage(string $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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's right there, isn't it ?