Skip to content

Release v1.1.0 with new features and minor fixes #160

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 96 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
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
3c9c845
add prototypical relation resolving
johguentner Feb 16, 2023
29c991a
Apply fixes from StyleCI (#124)
mechelon Feb 16, 2023
aa67de9
add .env* to .gitignore
johguentner Feb 18, 2023
8f9d690
ensure .env.testing is loaded for config
johguentner Feb 18, 2023
04ca44a
implement `PestPLuginHttpRecorder`
johguentner Feb 18, 2023
7bd0fec
register `PestPluginHttpRecorder`
johguentner Feb 18, 2023
b8119d7
add new `EndpointCommentsTest`
johguentner Feb 18, 2023
4f219da
add autogenerated stubs
johguentner Feb 18, 2023
2bb3d61
Apply fixes from StyleCI (#126)
mechelon Feb 18, 2023
c39d2f7
polish/fix registering of `recordAndFakeLater`
johguentner Feb 18, 2023
6448c31
Apply fixes from StyleCI (#127)
mechelon Feb 18, 2023
2e27835
Do not serialize scalar values
richardhj Apr 9, 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
81b1dce
change namespace and name of `HttpRecorder`
johguentner Apr 30, 2023
6bc6bbf
Apply fixes from StyleCI (#138)
mechelon Apr 30, 2023
bd57daa
fix: move definitions of macros to src folder
johguentner Apr 30, 2023
142d84c
fix: ignore .env.testing file if it does not exist
johguentner Apr 30, 2023
51f7139
Apply fixes from StyleCI (#139)
mechelon Apr 30, 2023
bdb333f
rename snapshot folder
johguentner Apr 30, 2023
95523d9
polish `PestHttpRecorder` implementation
johguentner Apr 30, 2023
ea1c4bd
Apply fixes from StyleCI (#140)
mechelon Apr 30, 2023
83e9442
change permissions for snapshot directory
johguentner Apr 30, 2023
7395c7b
cleanup: remove commented line
johguentner Apr 30, 2023
6d990af
Merge pull request #128 from 5am-code/refactor/record-and-fake-tests
johguentner Apr 30, 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
c3a88cd
Merge branch 'main' into dev
johguentner 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
0c0233f
Merge pull request #129 from richardhj/patch-1
johguentner Apr 30, 2023
96f7377
add tests for checking `asText()`method
johguentner Apr 30, 2023
fe961c8
add and polish phpdocs
johguentner May 2, 2023
fe0707c
Apply fixes from StyleCI (#144)
mechelon May 2, 2023
d16d87b
Merge branch 'main' into dev
johguentner 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
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
ca767a0
Merge pull request #143 from 5am-code/fix/as-text-for-scalar-values
johguentner Jun 9, 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
9334b9b
minor polishes and cleanup
johguentner Jun 16, 2023
6e54138
Apply fixes from StyleCI (#158)
mechelon Jun 16, 2023
7129653
minor fix for resolve tests
johguentner Jun 16, 2023
07a320e
Merge pull request #116 from 5am-code/feature/resolve
johguentner Jun 16, 2023
690f3eb
Apply fixes from StyleCI (#159)
mechelon Jun 16, 2023
207e873
Merge pull request #135 from 5am-code/feature/database-creation
johguentner Jun 16, 2023
aa20eb8
add quote block type
Gummibeer Jun 19, 2023
a33aeb1
php cs fix
Gummibeer Jun 19, 2023
1bd5694
add missing test cases
Gummibeer Jun 20, 2023
1679318
fix php cs
Gummibeer Jun 20, 2023
6b31bcd
Merge pull request #161 from Gummibeer/add-quote-block
johguentner Jun 20, 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
vendor
.phpunit.result.cache
coverage/
.phpunit.cache/
.phpunit.cache/
.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
245 changes: 245 additions & 0 deletions src/Builder/DatabaseBuilder.php
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;
}
}
Loading