203 lines
7.2 KiB
PHP
203 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\DiplomModel\Worker;
|
|
use App\Models\Doctor;
|
|
use App\Models\Image;
|
|
use App\Models\Patient;
|
|
use App\Models\SetOfSportsExercises;
|
|
use App\Models\SetsOfSportsActivities;
|
|
use App\Models\SportCourses;
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
use App\Models\SportTasks;
|
|
use Cassandra\Date;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Str;
|
|
|
|
class AdminController extends Controller
|
|
{
|
|
|
|
//Добавление новой тренировки
|
|
public function AddSportTasks(Request $request)
|
|
{
|
|
$error = Validator::make($request->all(), [
|
|
'name' => 'required',
|
|
'description' => 'required',
|
|
'count' => 'required',
|
|
'id_image' => 'required',
|
|
// 'id_sport_courses' => 'required',
|
|
]);//1024
|
|
if ($error->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
|
}
|
|
else{
|
|
SportTasks::create([
|
|
'name' => $request->name,
|
|
'description' => $request->description,
|
|
'count' => $request->count,
|
|
'id_image' => $request->id_image,
|
|
//'id_sport_courses' => $request->id_sport_courses,
|
|
]);
|
|
return response(['Новое упражнение было добавлено'], 200);
|
|
}
|
|
}
|
|
|
|
//Добавление курса(название)
|
|
public function AddSportCourses(Request $request)
|
|
{
|
|
$error = Validator::make($request->all(), [
|
|
'name' => 'required',
|
|
'description' => 'required',
|
|
]);//1024
|
|
if ($error->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
|
}
|
|
else{
|
|
SportCourses::create([
|
|
'name' => $request->name,
|
|
'description' => $request->description,
|
|
'visibility' => 1,
|
|
]);
|
|
return response(['Новое курс(название) был добавлен'], 200);
|
|
}
|
|
}
|
|
//Отключение курса(название)
|
|
public function VisivilitySportCourses(Request $request)
|
|
{
|
|
$error = Validator::make($request->all(), [
|
|
'id' => 'required',
|
|
]);//1024
|
|
if ($error->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
|
}
|
|
else{
|
|
$SportCourses = SportCourses::where('id', $request->id)->first();
|
|
if ($SportCourses != null) {
|
|
if($SportCourses->visibility == 0){
|
|
$SC = $SportCourses;
|
|
$SC->visibility = 1;
|
|
$SC->update();
|
|
return response(['Включение курса'], 200);
|
|
}
|
|
else if($SportCourses->visibility == 1){
|
|
$SC = $SportCourses;
|
|
$SC->visibility = 0;
|
|
$SC->update();
|
|
return response(['Отключение курса'], 200);
|
|
}
|
|
else{
|
|
return response(['Ошибка, неизвестные данные в поле'], 400);
|
|
}
|
|
}
|
|
else{
|
|
return response(['Такого курса нету'], 400);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Добавление фотографии
|
|
function AddImage(Request $request)
|
|
{
|
|
$valid = Validator::make($request->all(),[
|
|
'name'=>'required',
|
|
'url_image' => 'image|mimes:jpg,png,jpeg,gif,svg',
|
|
'count'=>'required',
|
|
//'url_image' => 'required|image|mimes:jpg,png,jpeg,gif,svg',
|
|
]);
|
|
if ($valid->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $valid->errors()]], 400);
|
|
}
|
|
else{
|
|
if($request->image != null){
|
|
Image::create([
|
|
'name'=>$request->name,
|
|
'url_image' => '/storage/app/' . Storage::putFile('images', $request->file('url_image')),
|
|
'count'=>$request->count,
|
|
]);
|
|
}
|
|
else{
|
|
Image::create([
|
|
'name'=>$request->name,
|
|
'count'=>$request->count,
|
|
]);
|
|
}
|
|
|
|
|
|
return response(['Фотография добавлена'], 200);
|
|
}
|
|
}
|
|
|
|
//Создание аккаунта врачу
|
|
public function CreateAccountDoctor(Request $request)
|
|
{
|
|
$error = Validator::make($request->all(), [
|
|
'login' => 'required',
|
|
'password' => 'required',
|
|
]);//1024
|
|
if ($error->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
|
}
|
|
else{
|
|
Doctor::create([
|
|
'login' => $request->login,
|
|
'password' => Hash::make($request->password),
|
|
'api_token' => Str::random(80)
|
|
]);
|
|
return response(['Аккаунт врача был создан'], 200);
|
|
}
|
|
}
|
|
|
|
//Создание набора курсов
|
|
public function CreateSetsOfSportsActivities(Request $request){
|
|
$error = Validator::make($request->all(), [
|
|
'name' => 'required|unique:sets_of_sports_activities',
|
|
'day' => 'required',
|
|
'description' => 'required',
|
|
'id_sport_courses' => 'required',
|
|
]);
|
|
|
|
if ($error->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
|
}
|
|
else{
|
|
SetsOfSportsActivities::create([
|
|
'name' => $request->name,
|
|
'day' => $request->day,
|
|
'description' => $request->description,
|
|
'id_sport_courses' => $request->id_sport_courses,
|
|
]);
|
|
return response(['Новый набор добавлен'], 200);
|
|
}
|
|
}
|
|
|
|
//Создание связи набора курса и упражнения
|
|
public function CreateSetsOfSportsExercises(Request $request){
|
|
$error = Validator::make($request->all(), [
|
|
'number' => 'required',
|
|
'id_sports_tasks' => 'required',
|
|
'id_sets_of_sports_activities' => 'required',
|
|
]);
|
|
|
|
if ($error->fails()) {
|
|
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
|
}
|
|
else{
|
|
SetOfSportsExercises::create([
|
|
'number' => $request->number,
|
|
'id_sports_tasks' => $request->id_sports_tasks,
|
|
'id_sets_of_sports_activities' => $request->id_sets_of_sports_activities,
|
|
]);
|
|
return response(['Создание связи между набором для курса и упражнения'], 200);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|