mirror of
https://github.com/kristoferssolo/LU-bookstore.git
synced 2025-10-21 18:00:34 +00:00
feat(Book): strip before save
This commit is contained in:
parent
6410a97e2b
commit
ce1c171bb0
@ -18,14 +18,14 @@ def _check_stock_value(instance, attribute, value):
|
|||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def _to_isbn(number: str):
|
def _to_isbn(number: str):
|
||||||
return ISBN(number)
|
return ISBN(number.strip())
|
||||||
|
|
||||||
|
|
||||||
@define
|
@define
|
||||||
class Book:
|
class Book:
|
||||||
isbn: ISBN = field(converter=_to_isbn, validator=validators.instance_of(ISBN), on_setattr=setters.frozen, repr=lambda value: f"'{value}'")
|
isbn: ISBN = field(converter=_to_isbn, validator=validators.instance_of(ISBN), on_setattr=setters.frozen, repr=lambda value: f"'{value}'")
|
||||||
title: str = field()
|
title: str = field(converter=str.strip)
|
||||||
author: str = field()
|
author: str = field(converter=str.strip)
|
||||||
price: float = field(converter=float, validator=[validators.instance_of(float), _check_price_value])
|
price: float = field(converter=float, validator=[validators.instance_of(float), _check_price_value])
|
||||||
stock: int = field(converter=int, validator=[validators.instance_of(int), _check_stock_value])
|
stock: int = field(converter=int, validator=[validators.instance_of(int), _check_stock_value])
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user