Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
3.0 kB
2
Indexable
Never
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use App\user_detail;
use App\Recipe;
use App\Ingredient;
use App\Units;
use Auth;
use DB;
use File;
use Illuminate\Support\Facades\Mail;

class ApiController extends Controller
{
    public function __construct (
        User $user, 
        user_detail $user_detail,
        Recipe $recipe,
        Ingredient $ingredient,
        Units $units
        )
    {
        $this->User = $user;
        $this->user_detail = $user_detail;
        $this->Recipe = $recipe;
        $this->Ingredient = $ingredient;
        $this->Units = $units;
    }

    public function sendmail($email, $subject, $content=null)
    {
        $data = [
            'address' => $email,
            'subject' => $subject,
            'content' => $content
        ];
        Mail::to($email)->send(new \App\Mail\git_mail($data));
        $return = ['Status' => 'Mail Sent Successfully!'];
        return $return;
    }

    public function signup(Request $request)
	{
        $data = $request->data;
        $decrypted = decryptData($data);
        // dd(json_decode($decrypted));
        $user_id = $this->User->addUser($decrypted);
        // dd($user_id);
        return $this->user_detail->addUserDetail($decrypted, $user_id);
    }

    public function editProfile(Request $request)
    {
        $user_id = $this->User->edit_profile($request);
        return $this->user_detail->edit_user_detail($request, $user_id);
    }
    
	public function login(Request $request)
	{
        // dd(json_encode($request->all()));
        $data = $request->data;
        $decrypted = decryptData($data);
        return $this->User->login_user($decrypted);
    }
    
    public function decrypt(Request $request)
	{
        $data = $request->data;
		$decrypted = decryptData($data);
		exit($decrypted);
    }
    
    // OTP match for login
    public function matchOTPForLogin(Request $request)
    {
        return $this->User->matchOtp($request);
    }

    public function addRecipe(Request $request)
    {
        $recipe_id = $this->Recipe->add_recipe($request);
        return $this->Ingredient->add_ingredient($request, $recipe_id);
    }

    public function viewRecipes(Request $request)
    {
        // dd($request->all());
        return $this->Recipe->view_recipes($request);
    }

    public function editRecipe(Request $request)
    {
        $recipe_id = $this->Recipe->edit_recipe($request);
        return $this->Ingredient->edit_ingredient($request, $recipe_id);
    }

    public function deleteRecipe(Request $request)
    {
        return $this->Recipe->delete_recipe($request);
    }

    public function myRecipe($user_id)
    {
        return $this->Recipe->my_recipe($user_id);
    }

    // public function insertUnit(Request $request)
    // {
    //     return $this->Units->add_unit($request);
    // }

}