diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index 36cba4ab..71723f4e 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -82,6 +82,14 @@ class MicropubController extends Controller 'location' => config('app.url') . "/likes/$like->id", ], 201)->header('Location', config('app.url') . "/likes/$like->id"); } + if ($request->has('properties.bookmark-of') || $request->has('bookmark-of')) { + $bookmark = (new BookmarkService())->createBookmark($request); + + return response()->json([ + 'response' => 'created', + 'location' => config('app.url') . "/bookmarks/$bookmark->id", + ], 201)->header('Location', config('app.url') . "/bookmarks/$bookmark->id"); + } $data = []; $data['client-id'] = $tokenData->getClaim('client_id'); if ($request->header('Content-Type') == 'application/json') { diff --git a/app/Services/BookmarkService.php b/app/Services/BookmarkService.php new file mode 100644 index 00000000..c7290bd0 --- /dev/null +++ b/app/Services/BookmarkService.php @@ -0,0 +1,53 @@ +header('Content-Type') == 'application/json') { + //micropub request + $url = normalize_url($request->input('properties.bookmark-of.0')); + $name = $request->input('properties.name.0'); + $content = $request->input('properties.content.0'); + $categories = $request->input('properties.category'); + } + if ( + ($request->header('Content-Type') == 'x-www-url-formencoded') + || + ($request->header('Content-Type') == 'multipart/form-data') + ) { + $url = normalize_url($request->input('bookmark-of')); + $name = $request->input('name'); + $content = $request->input('content'); + $categories = $request->input('category[]'); + } + + $bookmark = Bookmark::create([ + 'url' => $url, + 'name' => $name, + 'content' => $content, + ]); + + foreach($categories as $category) { + $tag = Tag::firstOrCreate(['tag' => $category]); + $bookmark->tags()->save($tag); + } + + ProcessBookmark::dispatch($bookmark); + + return $Bookmark; + } +}