Skip to content

Commit

Permalink
Merge pull request #45 from andreciornavei/develop
Browse files Browse the repository at this point in the history
added deposit feature; adjust api;
  • Loading branch information
andreciornavei authored Mar 7, 2024
2 parents 855166d + a92b1e3 commit b186ad9
Show file tree
Hide file tree
Showing 36 changed files with 557 additions and 122 deletions.
4 changes: 2 additions & 2 deletions backend/app/Domain/Usecases/AuthLogin/AuthLoginDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public function __construct(array $data)

public function getUsername()
{
return $this->username;
return $this->username ?? null;
}

public function getPassword()
{
return $this->password;
return $this->password ?? null;
}
}
6 changes: 3 additions & 3 deletions backend/app/Domain/Usecases/AuthRegister/AuthRegisterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public function __construct(array $data)

public function getEmail()
{
return $this->email;
return $this->email ?? null;
}

public function getUsername()
{
return $this->username;
return $this->username ?? null;
}

public function getPassword()
{
return $this->password;
return $this->password ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class TransactionCreateDto
{
private string $description;
private float $factor;
private int $amount;
private string | null $document;
private string $userId;
private string $userUsername;
private float $userBalance;
private $description;
private $factor;
private $amount;
private $document;
private $userId;
private $userUsername;
private $userBalance;

public function __construct(array $data)
{
Expand All @@ -23,36 +23,36 @@ public function __construct(array $data)

public function getFactor()
{
return $this->factor;
return $this->factor ?? null;
}

public function getAmount()
{
return $this->amount;
return $this->amount ?? null;
}

public function getDocument()
{
return $this->document;
return $this->document ?? null;
}

public function getDescription()
{
return $this->description;
return $this->description ?? null;
}

public function getUserBalance()
{
return $this->userBalance;
return $this->userBalance ?? null;
}

public function getUserId()
{
return $this->userId;
return $this->userId ?? null;
}

public function getUserUsername()
{
return $this->userUsername;
return $this->userUsername ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Validator;

use App\Domain\Entities\TransactionEntity;
use App\Domain\Entities\UserEntity;
use App\Domain\Providers\IStorageProvider;
use App\Domain\Usecases\TransactionCreate\TransactionCreateDto;
use App\Domain\Usecases\UserUpdateBalance\UserUpdateBalanceDto;
Expand All @@ -22,7 +23,7 @@ public function __construct(
) {
}

public function handler(TransactionCreateDto $dto): TransactionEntity
public function handler(TransactionCreateDto $dto): UserEntity | TransactionEntity
{
// mount payload
$payload = [
Expand All @@ -44,7 +45,7 @@ public function handler(TransactionCreateDto $dto): TransactionEntity
'user_username' => 'required|string',
'balance' => 'required|numeric',
'factor' => 'required|numeric|in:-1,1',
'description' => 'required|string|min:6',
'description' => 'required|string|min:2',
'document' => 'required_if:factor,1',
'amount' => [
'required',
Expand Down Expand Up @@ -129,7 +130,7 @@ public function handler(TransactionCreateDto $dto): TransactionEntity

// decrese user balance if factor is a purchase
if ($createdTransaction->getFactor() == -1) {
$this->userUpdateBalanceUsecase->handler(new UserUpdateBalanceDto([
return $this->userUpdateBalanceUsecase->handler(new UserUpdateBalanceDto([
"user_id" => $createdTransaction->getUserId(),
"increment_balance" => $createdTransaction->getAmount() * $createdTransaction->getFactor()
]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

class TransactionFindDto
{
private string | null $limit;
private string | null $cursor;
private string | null $filter_id;
private string | null $filter_user_id;
private $limit;
private $cursor;
private $filter_id;
private $filter_user_id;
private $filter_status;

public function __construct(array $data)
Expand All @@ -21,26 +21,26 @@ public function __construct(array $data)

public function getLimit()
{
return $this->limit;
return $this->limit ?? null;
}

public function getCursor()
{
return $this->cursor;
return $this->cursor ?? null;
}

public function getFilterId()
{
return $this->filter_id;
return $this->filter_id ?? null;
}

public function getFilterUserId()
{
return $this->filter_user_id;
return $this->filter_user_id ?? null;
}

public function getFilterStatus()
{
return $this->filter_status;
return $this->filter_status ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class TransactionUpdateDto
{
private string $id;
private string $status;
private $id;
private $status;

public function __construct(array $data)
{
Expand All @@ -18,11 +18,11 @@ public function __construct(array $data)

public function getId()
{
return $this->id;
return $this->id ?? null;
}

public function getStatus()
{
return $this->status;
return $this->status ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class TransactionUploadCheckDto
{

private string $user_id;
private $user_id;

public function __construct(array $data)
{
Expand All @@ -18,6 +18,6 @@ public function __construct(array $data)

public function getUserId()
{
return $this->user_id;
return $this->user_id ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class UserUpdateBalanceDto
{
private string $user_id;
private string $increment_balance;
private $user_id;
private $increment_balance;

public function __construct(array $data)
{
Expand Down
2 changes: 1 addition & 1 deletion backend/app/Http/Controllers/AuthLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function handler(Request $request)
$response = new Response(json_encode(auth()->user()));
return $response
->withHeaders(['Cache-Control' => 'no-cache, private'])
->withCookie(cookie("Authorization", $token, 60, null, null, false, true, false, "none"));
->withCookie(cookie("Authorization", $token, 60, null, null, false, true, false, null));
} catch (Exception $error) {
return response()->json(json_decode($error->getMessage()), 401);
}
Expand Down
27 changes: 22 additions & 5 deletions frontend/src/components/drawer-header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { Typography } from '@mui/material'
import { Stack, Typography } from '@mui/material'
import { DrawerHeadWrapper } from './styles'
import { useAuth } from '@hooks/auth'

export const DrawerHead = (): JSX.Element => {
export const DrawerHeader = (): JSX.Element => {
const auth = useAuth()
return (
<DrawerHeadWrapper>
<Typography variant="h5" color="white">
BNB Bank
</Typography>
<Stack direction="column">
<Typography variant="h5" color="white">
BNB Bank
</Typography>
<Stack direction="column">
<Typography
variant="caption"
color="white"
lineHeight={1}
fontWeight="bold"
>
{auth.user?.username || 'unknown'}
</Typography>
<Typography variant="caption" color="white" lineHeight={1}>
{auth.user?._id || 'unknown'}
</Typography>
</Stack>
</Stack>
</DrawerHeadWrapper>
)
}
19 changes: 12 additions & 7 deletions frontend/src/components/form-input-file/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { useState } from 'react'
import { Controller } from 'react-hook-form'
import { FormInputFileProps } from './types'
import { FileContentSelector } from './components/file-content-selector'
import { FormHelperText, Stack } from '@mui/material'

export const FormInputFile = ({
name,
error,
control,
}: FormInputFileProps): JSX.Element => {
const [base64Image, setBase64Image] = useState<string | undefined>(undefined)
Expand All @@ -27,22 +29,25 @@ export const FormInputFile = ({
<Controller
name={name}
control={control}
defaultValue=""
render={({ field }) => (
<>
render={({ field: { onChange, value, ...field } }) => (
<Stack direction="column">
<input
accept="image/*"
id="file-target"
type="file"
value={field.value}
style={{ display: 'none' }}
onChange={handleFileChange}
{...field}
onChange={(e) => [
onChange(e?.target?.files?.[0]),
handleFileChange(e),
]}
/>
<FileContentSelector
base64Image={base64Image}
onRemove={() => setBase64Image(undefined)}
onRemove={() => [setBase64Image(undefined), onChange(undefined)]}
/>
</>
<FormHelperText error={!!error}>{error}</FormHelperText>
</Stack>
)}
/>
</>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/form-input-file/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Control, FieldValues } from 'react-hook-form'
export type FormInputFileProps = {
name: string
control: Control<FieldValues, any>
error?: string
}

export type FileContentSelectorProps = {
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/pages/_private/components/private-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrivatePageContext } from '../context'
import { Drawer, DrawerBackground } from '../styles'
import { useContextSelector } from 'use-context-selector'
import { DrawerItem } from '../../../components/drawer-item'
import { DrawerHead } from '../../../components/drawer-header'
import { DrawerHeader } from '../../../components/drawer-header'

import {
ArrowBendRightDown,
Expand All @@ -16,8 +16,10 @@ import {
SignOut,
Signature,
} from '@phosphor-icons/react'
import { useAuth } from '@hooks/auth'

export const PrivateDrawer = (): JSX.Element => {
const auth = useAuth()
const open = useContextSelector(PrivatePageContext, (s) => s.open)
const toggleDrawer = useContextSelector(
PrivatePageContext,
Expand All @@ -38,7 +40,7 @@ export const PrivateDrawer = (): JSX.Element => {
}}
>
<DrawerBackground role="presentation" onClick={() => toggleDrawer(false)}>
<DrawerHead />
<DrawerHeader />
<List>
<DrawerItem href="balance" label="BALANCE" icon={Scales} />
<DrawerItem href="incomes" label="INCOMES" icon={ArrowBendRightUp} />
Expand All @@ -56,7 +58,11 @@ export const PrivateDrawer = (): JSX.Element => {
/>
<DrawerItem href="settings" label="SETTINGS" icon={Gear} />
<DrawerItem href="help" label="HELP" icon={Question} />
<DrawerItem href="/" label="SIGN OUT" icon={SignOut} />
<DrawerItem
label="SIGN OUT"
icon={SignOut}
onClick={() => auth.disconnect()}
/>
</List>
</DrawerBackground>
</Drawer>
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/pages/balance/view.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Box, Stack, Typography, useTheme } from '@mui/material'
import { useAuth } from '@hooks/auth'
import { AppNavbar } from '@components/app-navbar'
import { ResumeButton } from '../../components/resume-button'
import { CaretDown, Plus } from '@phosphor-icons/react'
import { formatAmount, formatDate } from '@utils/formatter'
import { ResumeButton } from '../../components/resume-button'
import { Box, Stack, Typography, useTheme } from '@mui/material'

export const BalancePageView = (): JSX.Element => {
const { user } = useAuth()
const { palette } = useTheme()
return (
<Stack direction="column">
<AppNavbar title="BNB Bank" variant="primary" />
<ResumeButton
size="regular"
resumeLabel="Current Balance"
resumeValue="$ 6320,00"
actionLabel="August, 2021"
resumeValue={formatAmount(user?.balance || 0)}
actionLabel={formatDate(new Date())}
color={palette.secondary}
actionIcon={CaretDown}
actionIconDirection="horizontal"
Expand Down
Loading

0 comments on commit b186ad9

Please sign in to comment.