Skip to content

Commit

Permalink
feat: update store method
Browse files Browse the repository at this point in the history
  • Loading branch information
halivert committed Jul 29, 2023
1 parent 78eaecf commit c4f76cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/API/CreditCard/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class CreditCard extends Model
'limit',
];

protected $casts = [
'due_date' => 'integer',
'closing_date' => 'integer',
'interest_rate' => 'decimal:2',
'limit' => 'decimal:2'
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
Expand Down
14 changes: 13 additions & 1 deletion app/API/CreditCard/v1/CreditCardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use App\API\CreditCard\CreditCard;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class CreditCardController extends Controller
{
Expand All @@ -25,9 +27,19 @@ public function index(Request $request): CreditCardCollection

/**
* Store a newly created resource in storage.
*
* @return JsonResponse
*/
public function store(StoreCreditCardRequest $request): void
public function store(StoreCreditCardRequest $request): JsonResponse
{
$attrs = $request->validated();

$creditCard = $request->user()->creditCards()->create($attrs);

return response()->json(
new CreditCardResource($creditCard),
Response::HTTP_CREATED
);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions lang/es_MX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"The given data was invalid.": "Los datos proporcionados no son válidos.",
"(and :count more errors)": "(y :count errores más)",
"(and :count more error)": "(y otro error más)"
}

0 comments on commit c4f76cc

Please sign in to comment.