Skip to content

Commit

Permalink
v0.0.13
Browse files Browse the repository at this point in the history
🚀😘💕😘💕
  • Loading branch information
Hiteazel committed Sep 14, 2023
2 parents cd8e6f4 + 3fc85fc commit a9f3291
Show file tree
Hide file tree
Showing 55 changed files with 3,526 additions and 404 deletions.
778 changes: 778 additions & 0 deletions sera-back/app/Http/Controllers/EditoController.php

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions sera-back/app/Http/Controllers/KnowledgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class KnowledgeController extends Controller
* tags={"Knowledges"},
* summary="Get list of knowledges",
* description="Returns list of knowledges",
* @OA\Parameter(
* name="search",
* description="Search string",
* required=false,
* in="query",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Response(
* response=200,
* description="Successful operation",
Expand All @@ -28,7 +37,7 @@ class KnowledgeController extends Controller
* @OA\Property(property="name", type="string", example="Knowledge 1"),
* @OA\Property(property="infos", type="string", example="Infos about knowledge 1"),
* @OA\Property(property="type", type="string", example="video"),
* @OA\Property(property="imageURL", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="image", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* )
Expand All @@ -44,9 +53,19 @@ class KnowledgeController extends Controller
* )
* )
*/
public function index()
public function index(Request $request)
{
$knowledges = Knowledge::get();
$validated = $request->validate([
'search' => 'string',
]);

$knowledges = Knowledge::all();

if ($request->filled('search')){
$knowledges = Knowledge::where('name', 'like', '%'.$validated['search'].'%')
->orWhere('infos', 'like', '%'.$validated['search'].'%')
->get();
}

return response()->json($knowledges, 201);
}
Expand Down Expand Up @@ -77,7 +96,7 @@ public function index()
* @OA\Property(property="name", type="string", example="Knowledge 1"),
* @OA\Property(property="infos", type="string", example="Infos about knowledge 1"),
* @OA\Property(property="type", type="string", example="video"),
* @OA\Property(property="imageURL", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="image", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* )
Expand Down Expand Up @@ -124,7 +143,7 @@ public function store(Request $request)
'message' => 'Erreur lors de l\'upload du fichier'
], 400);
}
$knowledge->imageURL = $path;
$knowledge->image = $path;
}

$knowledge->save();
Expand Down Expand Up @@ -158,7 +177,7 @@ public function store(Request $request)
* @OA\Property(property="name", type="string", example="Knowledge 1"),
* @OA\Property(property="infos", type="string", example="Infos about knowledge 1"),
* @OA\Property(property="type", type="string", example="video"),
* @OA\Property(property="imageURL", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="image", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* )
Expand Down Expand Up @@ -224,7 +243,7 @@ public function show($id)
* @OA\Property(property="name", type="string", example="Knowledge 1"),
* @OA\Property(property="infos", type="string", example="Infos about knowledge 1"),
* @OA\Property(property="type", type="string", example="video"),
* @OA\Property(property="imageURL", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="image", type="string", example="https://sera-bucket.s3.eu-west-3.amazonaws.com/knowledges/1621538100.jpg"),
* @OA\Property(property="created_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2021-05-20 08:55:00"),
* )
Expand Down Expand Up @@ -274,7 +293,7 @@ public function update(Request $request, $id)
$knowledge->type = $validated['type'];
}
if ($request->image != null) {
$previousPath = $knowledge->imageURL;
$previousPath = $knowledge->image;
if ($previousPath != null){
Storage::disk('s3')->delete($previousPath);
}
Expand All @@ -290,7 +309,7 @@ public function update(Request $request, $id)
'message' => 'Erreur lors de l\'upload du fichier'
], 400);
}
$knowledge->imageURL = $path;
$knowledge->image = $path;
}

$knowledge->save();
Expand Down Expand Up @@ -345,8 +364,8 @@ public function destroy($id)
}


if ($knowledge->imageURL != null){
Storage::disk('s3')->delete($knowledge->imageURL);
if ($knowledge->image != null){
Storage::disk('s3')->delete($knowledge->image);
}

$knowledge->delete();
Expand Down
21 changes: 21 additions & 0 deletions sera-back/app/Models/Edito.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Edito extends Model
{
use HasFactory;

public function project()
{
return $this->hasOne(Project::class);
}

public function knowledges()
{
return $this->belongsToMany(Knowledge::class, 'edito_knowledge', 'edito_id', 'knowledge_id');
}
}
7 changes: 6 additions & 1 deletion sera-back/app/Models/Knowledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Knowledge extends Model
{
use HasFactory;

public function getImageURLAttribute($value)
public function getimageAttribute($value)
{
// si value null, return null
if (!$value) {
Expand All @@ -33,4 +33,9 @@ public function getImageURLAttribute($value)

return $temporaryUrl;
}

public function editos()
{
return $this->belongsToMany(Edito::class, 'edito_knowledge', 'knowledge_id', 'edito_id');
}
}
5 changes: 5 additions & 0 deletions sera-back/app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public function subtitles()
{
return $this->hasMany(Subtitle::class);
}

public function edito()
{
return $this->hasOne(Edito::class);
}
}
4 changes: 2 additions & 2 deletions sera-back/config/knowledge-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

return [
"Location",
"Personalitie",
"Personality",
"Instrument",
"Music",
"Event",
"Other"
];
];
31 changes: 27 additions & 4 deletions sera-back/config/roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["store","destroy","index"],
"knowledges" => ["show", "index", "store", "update", "destroy", "getTypes"],
"edito" => ["show", "index", "store", "update", "destroy","removeImage","addKnowledge","removeKnowledge"],
],
"project_manager" => [
"projects-requests" => ["show", "index", "update"],
Expand All @@ -28,6 +29,8 @@
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["store","destroy","index"],
"knowledges" => ["show", "index", "store", "update", "destroy", "getTypes"],
"edito" => ["show", "index", "store", "update", "destroy","removeImage","addKnowledge","removeKnowledge"],

],
"professor" => [
"users" => ["iso","show", "index", "roles", "image", "password","reservations"],
Expand All @@ -37,7 +40,11 @@
"video-reviews" => ["getReviewsByProjectId","addAComment","getVideoValidated"],
"ressources" => ["show", "index", "store", "update", "destroy", "getTypes"],
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["index"],
"subtitles" => ["index","show"],
"edito" => ["show", "index"],
"transcriptions" => ["index","show"],


],
"video_team" => [
"users" => ["iso","show", "index", "roles", "image", "password","reservations"],
Expand All @@ -47,7 +54,11 @@
"video-reviews" => ["getReviewsByProjectId","addAComment","getTemporaryUploadUrl","getVideoValidated"],
"ressources" => ["show", "index", "store", "update", "destroy", "getTypes"],
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["index"],
"subtitles" => ["index","show"],
"edito" => ["show", "index"],
"transcriptions" => ["index","show"],


],
"video_editor" => [
"users" => ["iso","show", "index", "roles", "image", "password","reservations"],
Expand All @@ -57,7 +68,11 @@
"video-reviews" => ["getReviewsByProjectId","store","destroy","addAComment","getTemporaryUploadUrl","getVideoValidated"],
"ressources" => ["show", "index", "store", "update", "destroy", "getTypes"],
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["index"],
"subtitles" => ["index","show"],
"edito" => ["show", "index"],
"transcriptions" => ["index","show"],


],
"transcription_team" => [
"users" => ["iso","show", "index", "roles", "image", "password","reservations"],
Expand All @@ -69,6 +84,8 @@
"transcriptions" => ["index", "store", "destroy"],
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["store","destroy","index"],
"edito" => ["show", "index"],

],
"traduction_team" => [
"users" => ["iso","show", "index", "roles", "image", "password","reservations"],
Expand All @@ -79,6 +96,10 @@
"ressources" => ["show", "index", "store", "update", "destroy", "getTypes"],
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["store","destroy","index"],
"edito" => ["show", "index"],
"transcriptions" => ["index","show"],


],
"editorial_team" => [
"users" => ["iso","show", "index", "roles", "image", "password","reservations"],
Expand All @@ -88,7 +109,9 @@
"video-reviews" => ["addAComment","getVideoValidated"],
"ressources" => ["show", "index", "store", "update", "destroy", "getTypes"],
"notifications" => ["index", "store", "show", "update", "destroy"],
"subtitles" => ["index"],
"subtitles" => ["index","show"],
"knowledges" => ["show", "index", "store", "update", "destroy", "getTypes"],
"edito" => ["show", "index", "store", "update", "destroy","removeImage","addKnowledge","removeKnowledge"],
"transcriptions" => ["index","show"],
],
];
31 changes: 31 additions & 0 deletions sera-back/database/factories/EditoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Edito>
*/
class EditoFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{

// toutes mes images vont être /template.jpeg. Il faut en mettre max 5 et au minimum 0
$images = [];
for ($i = 0; $i < rand(0, 5); $i++) {
$images[] = '/template.jpeg';
}
return [
'title' => $this->faker->realText(20),
'description' => $this->faker->realText(500),
'images' => json_encode($images),
];
}
}
2 changes: 1 addition & 1 deletion sera-back/database/factories/KnowledgeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function definition(): array
'name' => $this->faker->realText(20),
'type' => $this->faker->randomElement(config('knowledge-type')),
'infos' => $this->faker->realText(200),
'imageURL' => $this->faker->boolean() ? '/template.jpeg' : null,
'image' => $this->faker->boolean() ? '/template.jpeg' : null,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up(): void
$table->string('name')->nullable(false);
$table->enum('type', $types)->nullable(false);
$table->text('infos')->nullable(false);
$table->string('imageURL')->nullable(true);
$table->string('image')->nullable(true);
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('editos', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->onDelete('cascade');
$table->string('title');
$table->text('description');
$table->json('images')->nullable(false)->default('[]');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('editos');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('edito_knowledge', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('knowledge_id');
$table->unsignedBigInteger('edito_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('edito_knowledge');
}
};
17 changes: 17 additions & 0 deletions sera-back/database/seeders/EditoSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class EditoSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}
Loading

0 comments on commit a9f3291

Please sign in to comment.