You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

3 years ago
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Wish;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class OwnWishController extends Controller
{
// *ONLY* for an users own wishes!!!
function OwnWishes(Request $request) {
return Wish::where("owner_id", $request->user()->id)
->get()
->makeHidden(["claimed_by"]);
}
function CreateWish(Request $request) {
$validator = Validator::make($request->all(), [
"wish" => "required|max:400",
]);
if($validator->fails()) {
return response()->json($validator->errors(), 400);
}
$newWish = new Wish([
"wish" => $request->input("wish"),
"owner_id" => $request->user()->id,
"claimed_by" => 0,
]);
$newWish->save();
return response()->json($newWish, 200);
}
function DeleteWish(Request $request, Wish $wish)
{
if ($wish->owner_id !== $request->user()->id) {
return response()->json("Nicht dein Wunsch... warum versuchst du das überhaupt?", 403);
}
if ($wish->claimed_by !== 0) {
return response()->json("Hmm...lass mal lieber. Das hat schon jemand reserviert.", 403);
}
$wish->delete();
return response()->json("Erfolreich gelöscht.", 200);
}
function ClaimedWishes(Request $request) {
return $request->user()->claimed;
}
}