Skip to content

Commit

Permalink
add api updates to the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Aug 8, 2024
1 parent c4f7fec commit 39d1906
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
21 changes: 10 additions & 11 deletions app/Http/Controllers/ApiChromeExtensionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
namespace App\Http\Controllers;

use App\Domains\Sources\SourceTypeEnum;
use App\Http\Resources\CollectionCollection;
use App\Http\Resources\CollectionResource;
use App\Models\Collection;
use App\Models\Source;
use Illuminate\Http\Request;

class ApiChromeExtensionController extends Controller
{
public function index()
{
$collections = Collection::orderBy("name")
$collections = Collection::orderBy('name')
->paginate(20);

return response()->json(
Expand All @@ -22,7 +19,8 @@ public function index()

}

public function createSource(Collection $collection) {
public function createSource(Collection $collection)
{
$validated = request()->validate([
'url' => 'required|string',
'recurring' => 'required|string',
Expand All @@ -42,16 +40,16 @@ public function createSource(Collection $collection) {
'user_id' => auth()->user()->id,
'meta_data' => [
'urls' => [
$validated['url']
$validated['url'],
],
],
]);


return response()->json("OK");
return response()->json('OK');
}

public function getSource(Collection $collection, Source $source) {
public function getSource(Collection $collection, Source $source)
{
return response()->json(
[
'id' => $source->id,
Expand All @@ -60,15 +58,16 @@ public function getSource(Collection $collection, Source $source) {
'active' => $source->active,
'recurring' => $source->recurring?->name,
'force' => $source->force,
'status' => "non needed",
'status' => 'non needed',
'type' => $source->type,
'collection_id' => $collection->id,
'url' => data_get($source->meta_data, 'urls.0'),
]
);
}

public function getSources() {
public function getSources()
{
$sources = Source::orderBy('id')
->whereType(SourceTypeEnum::WebPageSource)
->with('collection')
Expand Down
1 change: 0 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ function () {
}
);


Route::controller(\App\Http\Controllers\AssistantEmailBoxSourceController::class)->group(
function () {
Route::get('/collections/{collection}/sources/email_source/create', 'create')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
use App\Models\Collection;
use App\Models\Source;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class ApiChromeExtensionControllerTest extends TestCase
{


public function test_index()
{
$user = User::factory()->create();
Expand Down Expand Up @@ -64,12 +60,11 @@ public function test_get_source()

$this->assertEquals($source->id, $response['id']);
$this->assertEquals($source->title, $response['title']);
$this->assertEquals($source->details, $response['details']);
$this->assertEquals($source->details, $response['prompt']);
$this->assertEquals($source->active, $response['active']);
$this->assertEquals($source->recurring->name, $response['recurring']);
$this->assertEquals($source->force, $response['force']);
$this->assertEquals("non needed", $response['status']);
$this->assertEquals('non needed', $response['status']);
$this->assertEquals(data_get($source->meta_data, 'urls.0'), $response['url']);
}

Expand Down

0 comments on commit 39d1906

Please sign in to comment.