Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kovakoodattu kirjoitusvuosi vertailu muutettu dynaamiseksi #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ poetry run invoke lint

## DoD
![Definition of done ](https://github.com/kimmomuli/Lukuvinkkikirjasto/blob/main/dokumentaatio/definiton_of_done.md)

5 changes: 4 additions & 1 deletion src/services/kirjavinkki_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import date

def tarkista_merkkijonomuoto(sana) -> bool:
if isinstance(sana, str):
return True
Expand All @@ -11,6 +13,7 @@ def tarkista_numeromuoto(numero) -> bool:


def tarkista_kirjavinkki(otsikko, kirjailija, kirjoitusvuosi) -> str:
three_years_from_this_year = int(date.today().year) + 3

if not tarkista_merkkijonomuoto(otsikko):
return "Otsikon pitää olla merkkijono"
Expand All @@ -24,7 +27,7 @@ def tarkista_kirjavinkki(otsikko, kirjailija, kirjoitusvuosi) -> str:

if not tarkista_numeromuoto(kirjoitusvuosi):
return "Kirjoitusvuosi pitää olla numero"
if not 1 < int(kirjoitusvuosi) < 2025:
if not 1 < int(kirjoitusvuosi) < three_years_from_this_year:
return "Kirjoitusvuosi pitää olla numero väliltä 1-2025"

return ""