Skip to content

Commit

Permalink
v0.0.14
Browse files Browse the repository at this point in the history
( ̄y▽ ̄)╭ Ohohoho.....
  • Loading branch information
ADR1811 committed Sep 15, 2023
2 parents a9f3291 + 7812290 commit 0af7537
Show file tree
Hide file tree
Showing 41 changed files with 2,027 additions and 122 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sh dev.sh

- [@DestroyCom](https://github.com/DestroyCom)
- [@ADR1811](https://github.com/ADR1811)
- [@lucag322](https://github.com/ADR1811)
- [@lucag322](https://github.com/lucag322)
- [@ThomAzgo](https://github.com/ThomAzgo)
- [@Hiteazel](https://github.com/Hiteazel)

Expand Down
195 changes: 195 additions & 0 deletions sera-back/app/Http/Controllers/ApiKeyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\ApiKey;

class ApiKeyController extends Controller
{

/**
* @OA\Post(
* path="/api/api-keys",
* tags={"API Key"},
* summary="Create an API key",
* description="Create an API key",
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"name","expires_at","never_expires"},
* @OA\Property(property="name", type="string", example="My API key"),
* @OA\Property(property="description", type="string", example="My API key description"),
* @OA\Property(property="expires_at", type="string", format="date-time", example="2021-09-14T21:34:35.000000Z"),
* @OA\Property(property="never_expires", type="boolean", example="false"),
* )
* ),
* @OA\Response(
* response=201,
* description="API key created successfully",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="API key created successfully"),
* )
* ),
* @OA\Response(
* response=400,
* description="Validation error",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="The given data was invalid."),
* @OA\Property(property="errors", type="object", example={"name": {"The name field is required."}}),
* )
* ),
* @OA\Response(
* response=401,
* description="Unauthenticated",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="Unauthenticated."),
* )
* ),
* )
*/
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string',
'description' => 'nullable|string',
'expires_at' => 'date',
'never_expires' => 'required|boolean',
]);

$apiKey = new ApiKey;
$apiKey->user_id = $request->user()->id;
$apiKey->key = bin2hex(random_bytes(32));
$apiKey->name = $validated['name'];
$apiKey->description = $validated['description'];
$apiKey->expires_at = $validated['never_expires'] ? null : $validated['expires_at'];
$apiKey->save();

return response()->json([
'message' => 'API key created successfully',
'data' => $apiKey,
], 201);
}

/**
* @OA\Post(
* path="/api/api-keys/{apikey_id}/recreate",
* tags={"API Key"},
* summary="Recreate an API key",
* description="Recreate an API key",
* @OA\Parameter(
* name="apikey_id",
* in="path",
* description="ID of the API key to recreate",
* required=true,
* @OA\Schema(
* type="integer",
* format="int64"
* )
* ),
* @OA\Response(
* response=200,
* description="API key recreated successfully",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="API key recreated successfully"),
* )
* ),
* @OA\Response(
* response=404,
* description="API key not found",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="API key not found"),
* )
* ),
* )
*/
public function recreate($apikey_id)
{
$apiKey = ApiKey::find($apikey_id);

if (!$apiKey) {
return response()->json([
'message' => 'API key not found',
], 404);
}

$apiKey->key = bin2hex(random_bytes(32));
$apiKey->save();

return response()->json([
'message' => 'API key recreated successfully',
'data' => $apiKey,
], 200);
}

/**
* @OA\Delete(
* path="/api/api-keys/{apikey_id}",
* tags={"API Key"},
* summary="Delete an API key",
* description="Delete an API key",
* @OA\Parameter(
* name="apikey_id",
* in="path",
* description="ID of the API key to delete",
* required=true,
* @OA\Schema(
* type="integer",
* format="int64"
* )
* ),
* @OA\Response(
* response=200,
* description="API key deleted successfully",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="API key deleted successfully"),
* )
* ),
* @OA\Response(
* response=404,
* description="API key not found",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="API key not found"),
* )
* ),
* )
*/
public function destroy($apikey_id)
{
$apiKey = ApiKey::find($apikey_id);

if (!$apiKey) {
return response()->json([
'message' => 'API key not found',
], 404);
}

$apiKey->delete();

return response()->json([
'message' => 'API key deleted successfully',
], 200);
}

/**
* @OA\Get(
* path="/api/api-keys",
* tags={"API Key"},
* summary="Get all API keys",
* description="Get all API keys",
* @OA\Response(
* response=200,
* description="API keys retrieved successfully",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="API keys retrieved successfully"),
* )
* ),
* )
*/
public function index(){
// get all api keys but remove key from the response
$apiKeys = ApiKey::all()->makeHidden('key');
return response()->json($apiKeys, 200);
}
}
125 changes: 125 additions & 0 deletions sera-back/app/Http/Controllers/CourseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Project;

class CourseController extends Controller
{
/**
* @OA\Get(
* path="/courses",
* operationId="getCourseList",
* tags={"Courses"},
* summary="Get list of courses",
* description="Returns list of courses",
* @OA\Response(
* response=200,
* description="successful operation",
* ),
* @OA\Response(
* response=401,
* description="Unauthorized",
* ),
* )
*/
public function index()
{
$projects = Project::where('status', 'published')
->select('id', 'title', 'description')
->paginate(15);

return response()->json(
$projects,
200
);
}

/**
* @OA\Get(
* path="/courses/{id}",
* operationId="getCourseById",
* tags={"Courses"},
* summary="Get course information",
* description="Returns course data",
* @OA\Parameter(
* name="id",
* description="Course id",
* required=true,
* in="path",
* @OA\Schema(
* type="integer",
* format="int64"
* )
* ),
* @OA\Response(
* response=200,
* description="successful operation",
* ),
* @OA\Response(
* response=401,
* description="Unauthorized",
* ),
* @OA\Response(
* response=404,
* description="Not found",
* ),
* )
*/
public function show($id)
{
$project = Project::with(['videoReviews' => function ($query) {
$query->where('validated', true);
}, 'videoReviews.ressource', 'subtitles.ressource', 'edito.knowledges'])->find($id);

if (!$project) {
return response()->json(['error' => 'Projet introuvable'], 404);
}

$json = [
"Title" => $project->title,
"Description" => $project->description,
"Video" => null,
"Subtitles" => [],
"Edito" => null,
];

if ($project->videoReviews) {
$video = $project->videoReviews->first();
$videoRessource = $video->ressource;
$json["Video"] = [
"Name" => $videoRessource->name,
"Url" => $videoRessource->url,
"Type" => $videoRessource->type,
"Description" => $videoRessource->description,
];
}

foreach ($project->subtitles as $subtitle) {
$subtitleRessource = $subtitle->ressource;
$json["Subtitles"][$subtitle->lang] = $subtitleRessource->url;
}

if ($project->edito) {
$edito = $project->edito;
$editoJson = [
"Title" => $edito->title,
"Description" => $edito->description,
"Knowledges" => $edito->knowledges->map(function ($knowledge) {
return [
"Name" => $knowledge->name,
"Infos" => $knowledge->infos,
"Image" => $knowledge->image,
"Type" => $knowledge->type,
];
}),
"Images" => $edito->images,
];
$json["Edito"] = $editoJson;
}

return response()->json($json, 200);
}

}
10 changes: 10 additions & 0 deletions sera-back/app/Http/Controllers/EditoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public function store(Request $request, $project_id)

$edito->save();

$steps = json_decode($project->steps);
$steps->{'Editorial'}->have_edito = true;
$project->steps = json_encode($steps);


return response()->json($edito, 201);
}

Expand Down Expand Up @@ -383,6 +388,11 @@ public function destroy($id)
'message' => 'Edito not found'
], 404);
}
$project = Project::find($edito->project_id);
$steps = json_decode($project->steps);
$steps->{'Editorial'}->have_edito = false;
$project->steps = json_encode($steps);
$project->save();

$edito->delete();

Expand Down
6 changes: 3 additions & 3 deletions sera-back/app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function index(Request $request)
$request->validate([
'maxPerPage' => 'integer',
'sort' => 'string|in:asc,desc',
'status' => 'string|in:ongoing,completed,cancelled',
'status' => 'string|in:ongoing,published,cancelled',
]);

$maxPerPage = $request->input('maxPerPage', 10);
Expand Down Expand Up @@ -366,7 +366,7 @@ public function show($id)
* @OA\Property(
* property="status",
* type="string",
* enum={"ongoing", "completed", "cancelled"},
* enum={"ongoing", "published", "cancelled"},
* ),
* @OA\Property(
* property="change_color",
Expand Down Expand Up @@ -435,7 +435,7 @@ public function update(Request $request, $id): JsonResponse
'description' => 'string',
'start_date' => 'date',
'end_date' => 'date',
'status' => 'string|in:ongoing,completed,cancelled',
'status' => 'string|in:ongoing,published,cancelled',
'change_color' => 'boolean',
]);

Expand Down
Loading

0 comments on commit 0af7537

Please sign in to comment.