refac: 변경한 DTO에 따라 코드 수정
- Spatie/DataTransferObject 대비
- MapFrom,MapTo -> RawName
- Strict -> 항상
- 심지어 raw type도 더 까다롭게
- array에 MapConverter 적용
- NullIsUndefined 적용
- 빈 nullable arg자리에 null 강제 지정
- Vue3에 v-model.number 지정
- input type="number" 기준
This commit is contained in:
@@ -2,33 +2,32 @@
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use sammo\DTO\Attr\Convert;
|
||||
use sammo\DTO\Converter\MapConverter;
|
||||
use sammo\DTO\SelectItem;
|
||||
use Spatie\DataTransferObject\Attributes\CastWith;
|
||||
use Spatie\DataTransferObject\Attributes\Strict;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use Spatie\DataTransferObject\Casters\ArrayCaster;
|
||||
|
||||
//https://json2dto.atymic.dev/
|
||||
|
||||
|
||||
|
||||
#[Strict]
|
||||
class BettingInfo extends DataTransferObject
|
||||
class BettingInfo extends DTO
|
||||
{
|
||||
public int $id;
|
||||
public string $type;
|
||||
public string $name;
|
||||
public bool $finished;
|
||||
public int $selectCnt;
|
||||
public ?bool $isExlusive;
|
||||
public bool $reqInheritancePoint;
|
||||
public int $openYearMonth;
|
||||
public int $closeYearMonth;
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $type,
|
||||
public string $name,
|
||||
public bool $finished,
|
||||
public int $selectCnt,
|
||||
public ?bool $isExclusive,
|
||||
public bool $reqInheritancePoint,
|
||||
public int $openYearMonth,
|
||||
public int $closeYearMonth,
|
||||
|
||||
/** @var \sammo\DTO\SelectItem[] */
|
||||
#[CastWith(ArrayCaster::class, itemType: SelectItem::class)]
|
||||
public array $candidates;
|
||||
public ?array $winner;
|
||||
|
||||
/** @var \sammo\DTO\SelectItem[] */
|
||||
#[Convert(MapConverter::class, [SelectItem::class])]
|
||||
public array $candidates,
|
||||
public ?array $winner,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,32 +2,28 @@
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\Attributes\MapFrom;
|
||||
use Spatie\DataTransferObject\Attributes\MapTo;
|
||||
use Spatie\DataTransferObject\Attributes\Strict;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use sammo\DTO\Attr\NullIsUndefined;
|
||||
use sammo\DTO\Attr\RawName;
|
||||
|
||||
#[Strict]
|
||||
class BettingItem extends DataTransferObject
|
||||
class BettingItem extends DTO
|
||||
{
|
||||
#[MapFrom('id')]
|
||||
#[MapTo('id')]
|
||||
public null|int $rowID = null;
|
||||
public function __construct(
|
||||
#[RawName('id')]
|
||||
#[NullIsUndefined]
|
||||
public ?int $rowID,
|
||||
|
||||
#[MapFrom('betting_id')]
|
||||
#[MapTo('betting_id')]
|
||||
public int $bettingID;
|
||||
#[RawName('betting_id')]
|
||||
public int $bettingID,
|
||||
|
||||
#[MapFrom('general_id')]
|
||||
#[MapTo('general_id')]
|
||||
public int $generalID;
|
||||
#[RawName('general_id')]
|
||||
public int $generalID,
|
||||
|
||||
#[MapFrom('user_id')]
|
||||
#[MapTo('user_id')]
|
||||
public null|int $userID;
|
||||
#[RawName('user_id')]
|
||||
public ?int $userID,
|
||||
|
||||
#[MapFrom('betting_type')]
|
||||
#[MapTo('betting_type')]
|
||||
public string $bettingType;
|
||||
public int $amount;
|
||||
#[RawName('betting_type')]
|
||||
public string $bettingType,
|
||||
public int $amount,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\Attributes\Strict;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use sammo\DTO\Attr\Convert;
|
||||
use sammo\DTO\Converter\MapConverter;
|
||||
|
||||
#[Strict]
|
||||
class SelectItem extends DataTransferObject
|
||||
class SelectItem extends DTO
|
||||
{
|
||||
public string $title;
|
||||
public ?string $info;
|
||||
public ?bool $isHtml;
|
||||
public ?array $aux;
|
||||
public function __construct(
|
||||
public string $title,
|
||||
public ?string $info,
|
||||
public ?bool $isHtml,
|
||||
#[Convert(MapConverter::class, ['string', 'int', 'float', 'array', 'null', 'bool'])]
|
||||
public ?array $aux,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,37 +2,33 @@
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\Attributes\MapFrom;
|
||||
use Spatie\DataTransferObject\Attributes\MapTo;
|
||||
use Spatie\DataTransferObject\Attributes\Strict;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use sammo\DTO\Attr\NullIsUndefined;
|
||||
use sammo\DTO\Attr\RawName;
|
||||
|
||||
#[Strict]
|
||||
class VoteComment extends DataTransferObject
|
||||
class VoteComment extends DTO
|
||||
{
|
||||
public ?int $id;
|
||||
public function __construct(
|
||||
#[NullIsUndefined]
|
||||
public ?int $id,
|
||||
|
||||
#[MapFrom('vote_id')]
|
||||
#[MapTo('vote_id')]
|
||||
public int $voteID;
|
||||
#[RawName('vote_id')]
|
||||
public int $voteID,
|
||||
|
||||
#[MapFrom('general_id')]
|
||||
#[MapTo('general_id')]
|
||||
public int $generalID;
|
||||
#[RawName('general_id')]
|
||||
public int $generalID,
|
||||
|
||||
#[MapFrom('nation_id')]
|
||||
#[MapTo('nation_id')]
|
||||
public int $nationID;
|
||||
#[RawName('nation_id')]
|
||||
public int $nationID,
|
||||
|
||||
#[MapFrom('nation_name')]
|
||||
#[MapTo('nation_name')]
|
||||
public string $nationName;
|
||||
#[RawName('nation_name')]
|
||||
public string $nationName,
|
||||
|
||||
#[MapFrom('general_name')]
|
||||
#[MapTo('general_name')]
|
||||
public string $generalName;
|
||||
#[RawName('general_name')]
|
||||
public string $generalName,
|
||||
|
||||
public string $text;
|
||||
public string $text,
|
||||
|
||||
public string $date;
|
||||
public string $date,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
+11
-16
@@ -2,23 +2,18 @@
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\Attributes\CastWith;
|
||||
use Spatie\DataTransferObject\Attributes\Strict;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use Spatie\DataTransferObject\Casters\ArrayCaster;
|
||||
|
||||
//https://json2dto.atymic.dev/
|
||||
|
||||
#[Strict]
|
||||
class VoteInfo extends DataTransferObject
|
||||
class VoteInfo extends DTO
|
||||
{
|
||||
public int $id;
|
||||
public string $title;
|
||||
public int $multipleOptions;
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $title,
|
||||
public int $multipleOptions,
|
||||
|
||||
public string $startDate;
|
||||
public ?string $endDate;
|
||||
public string $startDate,
|
||||
public ?string $endDate,
|
||||
|
||||
/** @var string[] */
|
||||
public array $options;
|
||||
/** @var string[] */
|
||||
public array $options,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user