aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
authorwinter2024-12-08 18:04:37 +0000
committerwinter2024-12-08 18:04:37 +0000
commitb00185ddbac9ac3de975a3954f2ede2f24458f6a (patch)
tree265ccaae497e2788ed7de8f6b08a0d5a77ea16dc /routes
parent13647d55bd8085a2b3a686b8aad3b28b0faf693a (diff)
implement notes
Diffstat (limited to 'routes')
-rw-r--r--routes/actor.php41
-rw-r--r--routes/note.php26
2 files changed, 32 insertions, 35 deletions
diff --git a/routes/actor.php b/routes/actor.php
index 710adfa..5879538 100644
--- a/routes/actor.php
+++ b/routes/actor.php
@@ -2,6 +2,7 @@
use WpfTest\HttpResponseStatus\NotFound;
use WpfTest\Model\Actor;
+use WpfTest\Model\Note;
use WpfTest\Router;
Router::getInstance()->mount('/user/:handle', function (array $args) {
@@ -9,35 +10,33 @@ Router::getInstance()->mount('/user/:handle', function (array $args) {
if ($actor == null) {
throw new NotFound("i don't know any local user called " . $args['handle']);
}
+ json_response($actor);
+});
+
+Router::getInstance()->mount('/user/:handle/basicFeed', function (array $args) {
+ $actor = Actor::findLocalByHandle($args['handle']);
+ $notes = Note::findAllWithAuthor($actor);
+ // TODO: implement pagination
json_response([
- 'type' => 'actor',
- 'dbgIsLocal' => $actor->isLocal,
- 'self' => path_to_uri("/user/$actor->handle"),
- 'created' => $actor->created?->format('c'),
- 'modified' => $actor->modified?->format('c'),
- 'homepage' => path_to_uri("/$actor->handle"),
- 'handle' => $actor->handle,
- 'displayName' => $actor->displayName,
- 'bio' => $actor->bio,
- 'pronouns' => $actor->pronouns,
- 'automated' => $actor->automated,
- 'endpoints' => [
- 'basicFeed' => path_to_uri("/user/$actor->handle/basicFeed")
- ]
+ 'page' => 1,
+ 'totalPages' => 1,
+ 'nextPage' => null,
+ 'previousPage' => null,
+ 'items' => array_map(function (Note $note) {
+ return $note->uri;
+ }, $notes)
]);
});
-Router::getInstance()->mount('/user/:username/basicFeed', function (array $args) {
- if ($args['username'] != 'winter') {
- throw new NotFound('i only know about winter');
- }
+Router::getInstance()->mount('/user/:handle/fullFeed', function (array $args) {
+ $actor = Actor::findLocalByHandle($args['handle']);
+ $notes = Note::findAllWithAuthor($actor);
+ // TODO: implement pagination here as well
json_response([
'page' => 1,
'totalPages' => 1,
'nextPage' => null,
'previousPage' => null,
- 'items' => [
- path_to_uri('/post/1')
- ]
+ 'items' => $notes
]);
}); \ No newline at end of file
diff --git a/routes/note.php b/routes/note.php
index 9c5e507..e43c2a1 100644
--- a/routes/note.php
+++ b/routes/note.php
@@ -1,20 +1,18 @@
<?php
+use WpfTest\HttpResponseStatus\NotFound;
+use WpfTest\Model\Actor;
+use WpfTest\Model\Note;
+use WpfTest\Model\NoteAttachment;
use WpfTest\Router;
Router::getInstance()->mount('/post/:id', function (array $args) {
- json_response([
- 'type' => 'note',
- 'self' => path_to_uri('/post/' . $args['id']),
- 'created' => '2024-12-06T20:14:00+00:00',
- 'author' => path_to_uri('/user/winter'),
- 'plainContent' => 'meow :3',
- 'language' => 'eng',
- 'inReplyTo' => null,
- 'threadApex' => path_to_uri('/post/' . $args['id']),
- 'privacy' => [
- 'scope' => 'public',
- 'indexable' => true
- ]
- ]);
+ $note = Note::find($args['id']);
+ if ($note == null) {
+ throw new NotFound("i don't know that note");
+ }
+ if (!$note->author->isLocal) {
+ throw new NotFound("i don't want to tell you about non local posts sorry");
+ }
+ json_response($note);
});