Skip to content

Commit cebfb29

Browse files
committed
feat: add subject and description fields to invoices
1 parent 575f432 commit cebfb29

File tree

8 files changed

+40
-6
lines changed

8 files changed

+40
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE invoices
3+
DROP COLUMN subject;
4+
ALTER TABLE invoices
5+
DROP COLUMN description;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Your SQL goes here
2+
ALTER TABLE invoices
3+
ADD COLUMN subject VARCHAR(128) NOT NULL DEFAULT '';
4+
ALTER TABLE invoices
5+
ADD COLUMN description VARCHAR(512) NOT NULL DEFAULT '';
6+

src/api/invoices.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ pub struct CreateInvoice {
4242
// TODO: maybe validate with https://crates.io/crates/iban_validate/
4343
#[garde(byte_length(max = 128))]
4444
pub bank_account_number: String,
45+
#[garde(byte_length(min = 1, max = 128))]
46+
pub subject: String,
47+
#[garde(byte_length(max = 512))]
48+
pub description: String,
4549
/// The rows of the invoice
4650
#[garde(length(min = 1), dive)]
4751
pub rows: Vec<CreateInvoiceRow>,
@@ -93,6 +97,8 @@ pub struct PopulatedInvoice {
9397
pub recipient_name: String,
9498
pub recipient_email: String,
9599
pub bank_account_number: String,
100+
pub subject: String,
101+
pub description: String,
96102
pub address: Address,
97103
pub rows: Vec<InvoiceRow>,
98104
pub attachments: Vec<Attachment>,
@@ -111,6 +117,8 @@ impl PopulatedInvoice {
111117
creation_time: invoice.creation_time,
112118
recipient_name: invoice.recipient_name,
113119
recipient_email: invoice.recipient_email,
120+
subject: invoice.subject,
121+
description: invoice.description,
114122
address,
115123
bank_account_number: invoice.bank_account_number,
116124
rows,

src/database/invoices.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ impl DatabaseConnection {
4444
address_id: address.id,
4545
recipient_name: invoice.recipient_name,
4646
recipient_email: invoice.recipient_email,
47+
subject: invoice.subject,
48+
description: invoice.description,
4749
bank_account_number: invoice.bank_account_number,
4850
};
4951

src/models.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ pub struct Invoice {
7878
/// A back account number can be at most 128 characters
7979
pub bank_account_number: String,
8080
pub address_id: i32,
81+
/// The subject of the invoice, has to be between 1 and 128 characters long
82+
pub subject: String,
83+
/// The description of the invoice, containing e.g. reasons for the purchase
84+
/// can be at most 512 characters
85+
pub description: String,
8186
}
8287

8388
impl Invoice {
@@ -98,6 +103,8 @@ pub struct NewInvoice {
98103
pub recipient_name: String,
99104
pub recipient_email: String,
100105
pub bank_account_number: String,
106+
pub subject: String,
107+
pub description: String,
101108
}
102109

103110
/// A single row of an invoice

src/schema.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ diesel::table! {
5757
#[max_length = 128]
5858
bank_account_number -> Varchar,
5959
address_id -> Int4,
60+
#[max_length = 128]
61+
subject -> Varchar,
62+
#[max_length = 512]
63+
description -> Varchar,
6064
}
6165
}
6266

src/tests/invoices.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ async fn create() {
5252
attachments: vec![],
5353
recipient_name: "Velkoja".into(),
5454
recipient_email: "velkoja@velat.com".into(),
55+
subject: "Pelikonsoleita".into(),
56+
description: "Ostettiin pelikonsoleita ku ei ollu tarpeeks".into(),
5557
address: NewAddress {
5658
street: "Otakaari 18A 69".into(),
5759
city: "Espoo".into(),
@@ -90,6 +92,8 @@ async fn create_list_all() {
9092
zip: "02jotain".into(),
9193
},
9294
bank_account_number: "ei ole".into(),
95+
subject: "Pelikonsoleita".into(),
96+
description: "Ostettiin pelikonsoleita ku ei ollu tarpeeks".into(),
9397
rows: vec![
9498
CreateInvoiceRow {
9599
product: String::from("pleikkari"),

templates/invoice.typ

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
footer: [
66
Laskut hyväksytään Tietokillan hallituksen kokouksissa.
7-
Ongelmatapauksissa ota yhteyttä rahastonhoitajaan: rahastonhoitaja\@tietokilta.fi
7+
Ongelmatapauksissa ota yhteyttä rahastonhoitajaan: #link("mailto:rahastonhoitaja@tietokilta.fi").
88
Tarkemmat yhteystiedot löydät killan sivuilta.
99
],
1010
)
@@ -60,8 +60,8 @@
6060

6161
== Tietokilta
6262

63-
*Aihe*: puuttuu \
64-
*Perustelut*: puuttuu \
63+
*Aihe*: #data.subject \
64+
*Perustelut*: #data.description \
6565

6666
=== Erittely
6767
#let rows = data.rows.map(it => ([#it.quantity #it.unit], [#it.product],
@@ -74,9 +74,7 @@
7474

7575
*IBAN-tilinumero*: #data.bank_account_number \
7676

77-
=== Muuta:
78-
79-
==== LIITTEET:
77+
=== LIITTEET:
8078
#data.attachments.map(a => a.filename).join(",")
8179

8280
#for file in data.attachments {

0 commit comments

Comments
 (0)