Skip to content
Open

Lab1 #79

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
140 changes: 140 additions & 0 deletions DDD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
## Opis zadania

Celem projektu jest przygotowanie fragmentu modelu domenowego bezpiecznej aplikacji bankowej zgodnie z zasadami Domain Driven Design. Model obejmuje trzy Bounded Contexty: *Zarządzanie Kontem*, *Przelewy* oraz *Uwierzytelnienie*. W ramach kontekstów zdefiniowano agregaty, encje i obiekty wartości reprezentujące operacje bankowe, zarządzanie kontem oraz logikę autoryzacji. Projekt nie ma być kompletnym modelem bankowości, lecz uporządkowanym przykładem zastosowania DDD.

---

![Diagram](Diagram_DDD.drawio.png)

---

## Bounded Contexts

### 1. Zarządzanie Kontem

Kontekst odpowiedzialny za dane konta bankowego oraz operacje wpływające na stan konta.

#### Agregat
- **KontoBankowe**

#### Encje

1. KontoBankowe
- **DaneKonta**
- **ParametryKonta**
- **LimityKonta**

1. Klient
- **DanePodstawowe**
- **Kontakt**

1. Karta
- **DaneKarty**
- **ParametryKarty**
- **LimityKarty**

#### Value Objects


1. DaneKonta
- **NumerKonta** number
- **Saldo** number
- **Waluta** string

1. ParametryKonta
- **CzyZablokowane** bool

1. LimityKonta
- **LimitPrzelewu** number
- **Limit Blik** number

1. DanePodstawowe
- **Imie** string
- **Nazwisko** string
- **Adres** string
- **Pesel** string

1. Kontakt
- **AdresKorespondencyjny** string
- **Email** string (wymuszenie regexem @)
- **NumerTelefonu** number

1. DaneKarty
- **NumerKarty** number
- **WażnośćKarty** date
- **KodBezpieczeństwa** number

1. ParametryKarty
- **Czy aktywna** bool

1. LimityKarty
- **Limit Płatności** Number
---

### 2. Przelewy

Kontekst odpowiedzialny za inicjowanie i obsługę przelewów wychodzących.

#### Agregat
- **Przelew**

#### Encje
1. Przelew
- **DanePrzelewu**
- **KwotaPrzelewu**
- **Data**

#### Value Objects

1. Daneprzelewu
- **NumerKontaDocelowego** number
- **TytułPrzelewu** string

1. Kwota przelewu
- **Kwota** number
- **Waluta** string

1. Data
- **DataWykonania** date

---

### 3. Uwierzytelnienie

Kontekst odpowiadający za zarządzanie tożsamością użytkownika i dostępem do operacji.

#### Agregat
- **Uwierzytelnienie**

#### Encje
1. Uwierzytelnienie
- **Sesja**
- **Dane**

#### Value Objects

1. Sesja
- **Cookie** string
- **Czas rozpoczęcia** date
- **Czas wygaśnięcia** date
- **Identyfikator urządzenia** string

1. Dane
- **Login** string, number
- **HashHasła** string
- **TokenSesyjny** string


## Integracja między kontekstami

- **Przelewy → Zarządzanie Kontem**
Przelew przed wykonaniem sprawdza saldo konta poprzez usługę domenową (domain service) lub przez port w warstwie aplikacyjnej. Wywołanie powinno być asynchroniczne (event/command) lub poprzez bezpieczny synchronizowany port z ograniczeniem czasowym.

- **Uwierzytelnienie → Przelewy / Zarządzanie Kontem**
Uwierzytelnienie dostarcza token sesyjny wymagany przed wykonaniem operacji na koncie lub inicjowaniem przelewu. Walidacja uprawnień odbywa się w warstwie aplikacyjnej przed wykonaniem operacji w agregacie.

## Inne operacje

1. W obrębie tego samego kontekstu:
- Klient może zmienić limity karty, czy też konta bankowego
- Klient może zmienić dane kontaktowe
Binary file added Diagram_DDD.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion Python/Flask_Book_Library/project/books/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from project import db
from project.books.models import Book
from project.books.forms import CreateBook
from markupsafe import escape


# Blueprint for books
Expand All @@ -13,8 +14,19 @@
def list_books():
# Fetch all books from the database
books = Book.query.all()
safe_books = [
{
"id": b.id,
"name": escape(b.name),
"author": escape(b.author),
"year_published": b.year_published,
"book_type": escape(b.book_type),
"status": escape(b.status)
}
for b in books
]
print('Books page accessed')
return render_template('books.html', books=books)
return render_template('books.html', books=safe_books)


# Route to fetch books in JSON format
Expand Down
12 changes: 11 additions & 1 deletion Python/Flask_Book_Library/project/customers/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import render_template, Blueprint, request, redirect, url_for, jsonify
from project import db
from project.customers.models import Customer
from markupsafe import escape


# Blueprint for customers
Expand All @@ -12,8 +13,17 @@
def list_customers():
# Fetch all customers from the database
customers = Customer.query.all()
safe_customers = [
{
"id": c.id,
"name": escape(c.name),
"author": escape(c.city),
"year_published": c.age
}
for c in customers
]
print('Customers page accessed')
return render_template('customers.html', customers=customers)
return render_template('customers.html', customers=safe_customers)


# Route to fetch customers in JSON format
Expand Down
16 changes: 15 additions & 1 deletion Python/Flask_Book_Library/project/loans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from project.loans.forms import CreateLoan
from project.books.models import Book
from project.customers.models import Customer
from markupsafe import escape


# Blueprint for loans
Expand Down Expand Up @@ -38,9 +39,22 @@ def list_customers_json():
def list_loans():
# Fetch all loans from the database
loans = Loan.query.all()
safe_loans = [
{
"id": l.id,
"customer_name": escape(l.customer_name),
"book_name": escape(l.book_name),
"loan_date": escape(l.loan_date),
"return_date": escape(l.return_date),
"original_author": escape(l.original_author),
"original_year_published": escape(l.original_year_published),
"original_book_type": escape(l.original_book_type)
}
for l in loans
]
# Render the loans.html template with the loans
print('Loans page accessed')
return render_template('loans.html', loans=loans, form=CreateLoan())
return render_template('loans.html', loans=safe_loans, form=CreateLoan())


# Route to handle loan creation form
Expand Down