1
+ from typing import List
2
+ from uuid import uuid4
3
+
4
+ from datetime import datetime
5
+ from sqlalchemy import String , UUID , text , DateTime , ForeignKey , Boolean
6
+ from sqlalchemy .orm import Mapped , mapped_column , relationship
7
+
8
+ from app import services
9
+ from app .database .db import Base
10
+
11
+
12
+ class CrimeReport (Base ):
13
+ __tablename__ = "crimereports"
14
+
15
+ id : Mapped [UUID ] = mapped_column ("id" , UUID , primary_key = True , nullable = False , default = uuid4 , server_default = text ("uuid_generate_v4()" ), index = True , quote = False )
16
+ crimeNumber : Mapped [str ] = mapped_column ("crimenumber" , String (40 ), nullable = False , quote = False )
17
+ contractId : Mapped [UUID ] = mapped_column ("contractid" , ForeignKey ("contracts.id" ), nullable = False , quote = False )
18
+ contract : Mapped ["Contract" ] = relationship ("Contract" , back_populates = "crimeReports" )
19
+ createdOn : Mapped [datetime ] = mapped_column ("createdon" , DateTime , nullable = False , default = datetime .utcnow (), server_default = text ("(current_timestamp at time zone 'utc')" ), quote = False )
20
+ closedOn : Mapped [datetime ] = mapped_column ("closedon" , DateTime , nullable = True , quote = False )
21
+
22
+
23
+ def __eq__ (self , other : dict ):
24
+ return all ([
25
+ str (self .id ) == str (other .get ("id" , None )),
26
+ str (self .contractId ) == str (other .get ("contractId" , None )),
27
+ str (self .crimeNumber ) == str (other .get ("crimeNumber" , None )),
28
+ str (self .createdOn ) == str (other .get ("createdOn" , None ))
29
+ ])
30
+
31
+ def send_crime_report_added_email (self ):
32
+ email_html_content = services .email_helpers .build_crime_report_added_email (crime_report = self )
33
+ services .email_helpers .send_email (
34
+ destination = self .contract .client .emailAddress ,
35
+ subject = "Your Stolen Bike" ,
36
+ content = email_html_content )
37
+
38
+ def send_crime_report_closed_email (self ):
39
+ email_html_content = services .email_helpers .build_crime_report_closed_email (crime_report = self )
40
+ services .email_helpers .send_email (
41
+ destination = self .contract .client .emailAddress ,
42
+ subject = "Your Stolen Bike" ,
43
+ content = email_html_content
44
+ )
0 commit comments