Skip to content

Commit 50444df

Browse files
committed
🗃️ Modify Use Data Structure to support description field
Part of #753 Signed-off-by: Leonardo Colman Lopes <dev@leonardo.colman.com.br>
1 parent 6b2cae3 commit 50444df

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

app/src/main/kotlin/br/com/colman/petals/use/repository/Use.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ data class Use(
1313

1414
val costPerGram: BigDecimal = BigDecimal.ZERO,
1515

16-
val id: String = UUID.randomUUID().toString()
16+
val id: String = UUID.randomUUID().toString(),
17+
18+
val description: String = ""
1719
) {
1820

1921
@Transient
@@ -35,6 +37,7 @@ data class Use(
3537
if (date != other.date) return false
3638
if (amountGrams != other.amountGrams) return false
3739
if (costPerGram != other.costPerGram) return false
40+
if (description != other.description) return false
3841

3942
return true
4043
}
@@ -43,6 +46,7 @@ data class Use(
4346
var result = date.hashCode()
4447
result = 31 * result + amountGrams.hashCode()
4548
result = 31 * result + costPerGram.hashCode()
49+
result = 31 * result + description.hashCode()
4650
return result
4751
}
4852
}

app/src/main/kotlin/br/com/colman/petals/use/repository/UseRepository.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ fun Use.toEntity(): UseEntity = UseEntity(
4444
date.format(ISO_LOCAL_DATE_TIME),
4545
amountGrams.toPlainString(),
4646
costPerGram.toPlainString(),
47-
id
47+
id,
48+
description
4849
)
4950

5051
fun UseEntity.toUse() = Use(
5152
parse(date),
5253
amount_grams.toBigDecimal(),
5354
cost_per_gram.toBigDecimal(),
54-
id
55+
id,
56+
description
5557
)

app/src/main/sqldelight/br/com/colman/petals/Use.sq

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ CREATE TABLE Use(
22
date TEXT NOT NULL,
33
amount_grams TEXT NOT NULL,
44
cost_per_gram TEXT NOT NULL,
5-
id TEXT PRIMARY KEY
5+
id TEXT PRIMARY KEY,
6+
description TEXT NOT NULL DEFAULT ""
67
);
78

89
upsert:
9-
INSERT INTO Use(date, amount_grams, cost_per_gram, id) VALUES ?
10+
INSERT INTO Use(date, amount_grams, cost_per_gram, id, description) VALUES ?
1011
ON CONFLICT (id) DO UPDATE SET date = excluded.date,
1112
amount_grams = excluded.amount_grams,
13+
description = excluded.description,
1214
cost_per_gram = excluded.cost_per_gram;
1315

1416
selectLast:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE Use ADD COLUMN description TEXT NOT NULL DEFAULT "";

0 commit comments

Comments
 (0)