Skip to content

Commit

Permalink
Merge branch 'dev' into feature/model
Browse files Browse the repository at this point in the history
  • Loading branch information
Huib8 committed Dec 21, 2023
2 parents e1c7bc9 + d75f9c4 commit faeaacf
Show file tree
Hide file tree
Showing 36 changed files with 1,100 additions and 288 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
25 changes: 25 additions & 0 deletions docs/toast_notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Create a toast notification

we're using [vue-toastification](https://github.com/Maronato/vue-toastification) to create toast notifications.

``component.vue``
```html
<template>
<div>
<button @click="openToast">Open Toast</button>
</div>
</template>

<script>
import { useToast } from "vue-toastification";
export default {
methods: {
openToast() {
const toast = useToast();
toast.success("Hello World!");
},
},
};
</script>

```
10 changes: 10 additions & 0 deletions src/app/Enums/ModifiedEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Enums;

enum ModifiedEnum: string
{
case inserted = 'I';
case modified = 'M';
case deleted = 'D';
}
3 changes: 3 additions & 0 deletions src/app/Enums/ResponseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
enum ResponseStatus: string
{
case success = 'success';
case created = 'created';
case error = 'error';
case unauthorized = 'unauthorized';
case forbidden = 'forbidden';
Expand All @@ -16,6 +17,7 @@ public function getStatusCode(): int
{
return match ($this) {
static::success => 200,
static::created => 201,
static::error => 400,
static::unauthorized => 401,
static::forbidden => 403,
Expand All @@ -30,6 +32,7 @@ public function label(): string
return match ($this) {
static::success => 'Success',
static::error => 'Error',
static::created => 'Created',
static::unauthorized => 'Unauthorized',
static::forbidden => 'Forbidden',
static::notFound => 'Not Found',
Expand Down
44 changes: 40 additions & 4 deletions src/app/Http/Controllers/FineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace App\Http\Controllers;

use App\Enums\ModifiedEnum;
use App\Enums\ResponseStatus;
use App\Http\Requests\FineRequest;
use App\Models\Fine;
use Illuminate\Http\Request;
use App\Traits\CommonTrait;

class FineController extends Controller
{
use CommonTrait;
/**
* Display a listing of the resource.
*/
Expand All @@ -26,9 +31,21 @@ public function create()
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
public function store(FineRequest $request)
{
//
$validated = $request->validated();
$fine = Fine::create([
'grant_id' => $validated['grant_id'],
'amount' => $validated['amount'],
'modified_kind' => ModifiedEnum::inserted,
'modified_user' => Auth()->id(),
]);

return $this->CommonResponse(
ResponseStatus::created,
'Fine created successfully',
['fine' => $fine],
);
}

/**
Expand All @@ -52,14 +69,33 @@ public function edit(Fine $fine)
*/
public function update(Request $request, Fine $fine)
{
//
$validated = $request->validated();

//TODO: Check: do we want to update the grant_id?
$fine->update([
'amount' => $validated['amount'],
'modified_kind' => ModifiedEnum::modified,
'modified_user' => Auth()->id(),
]);

return $this->CommonResponse(
ResponseStatus::success,
'Fine updated successfully',
['fine' => $fine],
);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Fine $fine)
{
//
$fine->delete();

return $this->CommonResponse(
ResponseStatus::success,
'Fine deleted successfully',
null,
);
}
}
45 changes: 40 additions & 5 deletions src/app/Http/Controllers/GrantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace App\Http\Controllers;

use App\Enums\ModifiedEnum;
use App\Enums\ResponseStatus;
use App\Http\Requests\GrantRequest;
use App\Models\Grant;
use Illuminate\Http\Request;
use App\Traits\CommonTrait;

class GrantController extends Controller
{
use CommonTrait;
/**
* Display a listing of the resource.
*/
Expand All @@ -26,9 +31,21 @@ public function create()
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
public function store(GrantRequest $request)
{
//
$validated = $request->validated();
$grant = Grant::create([
'user_id' => $validated['user_id'],
'item_id' => $validated['item_id'],
'borrowed_date' => $validated['borrowed_date'],
'return_date' => $validated['return_date'],
'modified_kind' => ModifiedEnum::inserted,
'modified_user' => Auth()->id(),
]);
return $this->CommonResponse(
ResponseStatus::created,
'Grant created successfully',
$grant);
}

/**
Expand All @@ -50,16 +67,34 @@ public function edit(Grant $grant)
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Grant $grant)
public function update(GrantRequest $request, Grant $grant)
{
//
$validated = $request->validated();

$grant->update([
'user_id' => $validated['user_id'],
'item_id' => $validated['item_id'],
'borrowed_date' => $validated['borrowed_date'],
'return_date' => $validated['return_date'],
'modified_kind' => ModifiedEnum::modified,
'modified_user' => Auth()->id(),
]);

return $this->CommonResponse(
ResponseStatus::success,
'Grant updated successfully',
['grant' => $grant]);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Grant $grant)
{
//
$grant->delete();
return $this->CommonResponse(
ResponseStatus::success,
'Grant deleted successfully',
null);
}
}
67 changes: 50 additions & 17 deletions src/app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,97 @@

namespace App\Http\Controllers;

use App\Enums\ModifiedEnum;
use App\Enums\ResponseStatus;
use App\Http\Requests\ItemRequest;
use App\Models\Item;
use Illuminate\Http\Request;
use App\Traits\CommonTrait;

class ItemController extends Controller
{
use CommonTrait;
/**
* Display a listing of the resource.
*/
public function index()
{
//
// render page
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
// render page
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
public function store(ItemRequest $request)
{
//
$validated = $request->validated();

$item = Item::create([
'Identifier' => '', //TODO: Use trait to generate valid identifier
'type' => $validated['type'],
'name' => $validated['name'],
'description' => $validated['description'],
'category' => $validated['category'],
'ISBN' => $validated['ISBN'],
'rating' => $validated['rating'],
'borrowing_time' => $validated['borrowing_time'],
'modified_kind' => 'I',
'modified_user' => auth()->user()->id,
]);
}

/**
* Display the specified resource.
*/
public function show(Item $item)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Item $item)
{
//
// render page
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, Item $item)
public function update(ItemRequest $request, Item $item)
{
//
$validated = $request->validated();

// update the items with the new data
$item->update([
'type' => $validated['type'],
'name' => $validated['name'],
'description' => $validated['description'],
'category' => $validated['category'],
'ISBN' => $validated['ISBN'],
'rating' => $validated['rating'],
'borrowing_time' => $validated['borrowing_time'],
'modified_kind' => ModifiedEnum::modified,
'modified_user' => auth()->id(),
]);

return $this->CommonResponse(
ResponseStatus::success,
'Item updated',
$item
);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Item $item)
{
//
$item->delete();
return $this->CommonResponse(
ResponseStatus::success,
'Item deleted',
null,
);
}
}
Loading

0 comments on commit faeaacf

Please sign in to comment.