Skip to content

Commit

Permalink
adding transactions controller in swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gabriel committed Oct 19, 2021
1 parent 1249957 commit fa299b9
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 19 deletions.
28 changes: 24 additions & 4 deletions app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,30 @@ public function store(Request $request): JsonResponse {
}

/**
* Display the specified resource.
*
* @param int $id
* @return JsonResponse
* @OA\Get (
* path="/account/{id}",
* operationId="finAccountByID",
* tags={"Account"},
* summary="Find Account by Id",
* description="Find Account by Id",
* security={{"bearer_token":{}}},
* @OA\Parameter(name="id", in="path", description="useful data by id", required=true),
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(
* @OA\Property(property="account", type="object", ref="#/components/schemas/Account"),
* )
* ),
* @OA\Response(
* response=400,
* description="Bad Request",
* ),
* @OA\Response(
* response=403,
* description="Forbidden"
* )
* )
*/
public function showByID(int $id): JsonResponse {
$person = Account::where('id', $id)->first();
Expand Down
117 changes: 109 additions & 8 deletions app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,73 @@ public function showAll(): Collection|array {
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return JsonResponse
* @OA\Post(
* path="/transaction",
* operationId="transactionStore",
* tags={"Transaction"},
* summary="Register Transaction",
* description="Register Transaction",
* security={{"bearer_token":{}}},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(
* property="source_account",
* type="string",
* description="Source Account",
* example="222A12311"
* ),
* @OA\Property(
* property="destination_account",
* type="string",
* description="Destination Account",
* example="44222A12311"
* ),
* @OA\Property(
* property="operation_type",
* type="string",
* description="Operation Type",
* example="abono"
* ),
* @OA\Property(
* property="amount",
* type="decimal",
* description="Amount",
* example="120.1234"
* ),
* @OA\Property(
* property="concept",
* type="string",
* description="Concept",
* example="Pago de Servicio"
* ),
* @OA\Property(
* property="reference",
* type="string",
* description="Reference",
* example="F112334"
* )
* )
* )
* ),
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="transaction created successfully"),
* @OA\Property(property="transaction", type="object", ref="#/components/schemas/Transaction"),
* )
* ),
* @OA\Response(
* response=400,
* description="Bad Request",
* ),
* @OA\Response(
* response=403,
* description="Forbidden"
* )
* )
*/
public function store(Request $request): JsonResponse {
$validator = Validator::make($request->all(), [
Expand Down Expand Up @@ -100,10 +163,48 @@ public function showByID(int $id): JsonResponse {
}

/**
* Show the form for editing the specified resource.
*
*
* @return JsonResponse
* @OA\Get(
* path="/transaction/own-user",
* operationId="transactionStore",
* tags={"Transaction"},
* summary="Transaction for a Current User",
* description="Transaction for a Current User",
* security={{"bearer_token":{}}},
* @OA\Parameter(parameter="page", name="page",in="query", required=false, description="Page in pagination"),
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(
* @OA\Property(property="current_page", type="integer", example="2"),
* @OA\Property(property="data", type="array", @OA\Items( type="object", ref="#/components/schemas/Transaction" ) ),
* @OA\Property(property="first_page_url", type="string", example="http://localhost/api/transaction/own-user?page=1"),
* @OA\Property(property="from", type="string", example="5"),
* @OA\Property(property="last_page", type="string", example="3"),
* @OA\Property(property="last_page_url", type="string", example="http://localhost/api/transaction/own-user?page=3"),
* @OA\Property(property="links", type="array", @OA\Items(
* type="object",
* @OA\Property(property="url", type="string", example="http://localhost/api/transaction/own-user?page=1" ),
* @OA\Property(property="label", type="string", example="1" ),
* @OA\Property(property="active", type="boolean", example="false" ),
* )
* ),
* @OA\Property(property="next_page_url", type="string", example="http://localhost/api/transaction/own-user?page=4"),
* @OA\Property(property="path", type="string", example="http://localhost/api/transaction/own-user"),
* @OA\Property(property="per_page", type="integer", example="5"),
* @OA\Property(property="prev_page_url", type="string", example="http://localhost/api/transaction/own-user?page=4"),
* @OA\Property(property="to", type="integer", example="10"),
* @OA\Property(property="total", type="integer", example="14"),
* )
* ),
* @OA\Response(
* response=400,
* description="Bad Request",
* ),
* @OA\Response(
* response=403,
* description="Forbidden"
* )
* )
*/
public function showOwnUser(): JsonResponse {
$user = auth()->user();
Expand Down
9 changes: 7 additions & 2 deletions app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* @OA\Property(property="account_number", type="string", maxLength=100, example="00919222G122"),
* @OA\Property(property="person_id", type="integer", readOnly="false", example="2211"),
* @OA\Property(property="product", type="string", maxLength=32, example="BBVA CC"),
* @OA\Property(property="balance", type="decimal", maxLength=32, example="12.5"),
* @OA\Property(property="created_at", type="string", readOnly="true", format="date-time", description="Datetime marker of verification status", example="2019-02-25 12:59:20"),
* @OA\Property(property="updated_at", type="string", readOnly="true", format="date-time", description="Datetime marker of verification status", example="2019-02-25 12:59:20"),
* @OA\Property(property="deleted_at",type="string", readOnly="true", format="date-time", description="Datetime marker of verification status", example="2019-02-25 12:59:20")
Expand All @@ -28,7 +27,13 @@
class Account extends Model {
use HasFactory;

protected $fillable = ['account_number', 'person_id', 'product', 'balance', 'nip', 'status'];
protected $fillable = ['account_number', 'person_id', 'product'];

protected $hidden = [
'nip',
'balance',
'status',
];

public function person() {
return $this->belongsTo(Person::class);
Expand Down
Loading

0 comments on commit fa299b9

Please sign in to comment.