Skip to content

Commit 6e827a1

Browse files
committed
Store and retrieve barcodes (#9)
1 parent 20be0a9 commit 6e827a1

File tree

9 files changed

+148
-7
lines changed

9 files changed

+148
-7
lines changed

backend/Discapp.API/Controllers/QueueController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public async Task<ActionResult<RecordReply>> PostMyEntity(int[] input)
3636
records.Available.Add(new()
3737
{
3838
RecordID = record.RecordID,
39-
Image = $"data:image/jpeg;base64,{base64String}"
39+
Image = $"data:image/jpeg;base64,{base64String}",
40+
Barcode = record.Barcode
4041
});
4142
}
4243
else

backend/Discapp.API/Migrations/20240925201944_RecordBarcodes.Designer.cs

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace Discapp.API.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class RecordBarcodes : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.AlterColumn<DateTime>(
15+
name: "Recorded",
16+
table: "Records",
17+
type: "datetime(6)",
18+
nullable: false,
19+
oldClrType: typeof(DateTime),
20+
oldType: "datetime(6)",
21+
oldDefaultValue: new DateTime(2024, 8, 7, 22, 21, 54, 557, DateTimeKind.Local).AddTicks(4690));
22+
23+
migrationBuilder.AddColumn<string>(
24+
name: "Barcode",
25+
table: "Records",
26+
type: "longtext",
27+
nullable: false)
28+
.Annotation("MySql:CharSet", "utf8mb4");
29+
}
30+
31+
/// <inheritdoc />
32+
protected override void Down(MigrationBuilder migrationBuilder)
33+
{
34+
migrationBuilder.DropColumn(
35+
name: "Barcode",
36+
table: "Records");
37+
38+
migrationBuilder.AlterColumn<DateTime>(
39+
name: "Recorded",
40+
table: "Records",
41+
type: "datetime(6)",
42+
nullable: false,
43+
defaultValue: new DateTime(2024, 8, 7, 22, 21, 54, 557, DateTimeKind.Local).AddTicks(4690),
44+
oldClrType: typeof(DateTime),
45+
oldType: "datetime(6)");
46+
}
47+
}
48+
}

backend/Discapp.API/Migrations/ApplicationDbContextModelSnapshot.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
1717
{
1818
#pragma warning disable 612, 618
1919
modelBuilder
20-
.HasAnnotation("ProductVersion", "8.0.7")
20+
.HasAnnotation("ProductVersion", "8.0.8")
2121
.HasAnnotation("Relational:MaxIdentifierLength", 64);
2222

2323
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
2424

25-
modelBuilder.Entity("Discapp.API.Data.Queue", b =>
25+
modelBuilder.Entity("Discapp.Shared.Data.Queue", b =>
2626
{
2727
b.Property<int>("Id")
2828
.ValueGeneratedOnAdd()
@@ -38,14 +38,18 @@ protected override void BuildModel(ModelBuilder modelBuilder)
3838
b.ToTable("Queue");
3939
});
4040

41-
modelBuilder.Entity("Discapp.API.Data.Record", b =>
41+
modelBuilder.Entity("Discapp.Shared.Data.Record", b =>
4242
{
4343
b.Property<int>("Id")
4444
.ValueGeneratedOnAdd()
4545
.HasColumnType("int");
4646

4747
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
4848

49+
b.Property<string>("Barcode")
50+
.IsRequired()
51+
.HasColumnType("longtext");
52+
4953
b.Property<string>("FilePath")
5054
.IsRequired()
5155
.HasColumnType("longtext");
@@ -54,9 +58,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
5458
.HasColumnType("int");
5559

5660
b.Property<DateTime>("Recorded")
57-
.ValueGeneratedOnAdd()
58-
.HasColumnType("datetime(6)")
59-
.HasDefaultValue(new DateTime(2024, 8, 7, 22, 21, 54, 557, DateTimeKind.Local).AddTicks(4690));
61+
.HasColumnType("datetime(6)");
6062

6163
b.HasKey("Id");
6264

backend/Discapp.API/Models/AvailableRecord.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public class AvailableRecord
44
{
55
public int RecordID { get; set; }
66
public string Image { get; set; } = "";
7+
public string Barcode { get; set; } = "";
78
}
89
}

backend/Discapp.Shared/Data/Record.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class Record
77
public int Id { get; set; }
88
public int RecordID { get; set; }
99
public string FilePath { get; set; } = "";
10+
public string Barcode { get; set; } = "";
1011
public DateTime Recorded { get; set; }
1112
}
1213
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Discapp.Worker.Models;
2+
3+
public class DiscogReleaseIdentifiers
4+
{
5+
public string Type { get; set; } = "";
6+
public string Value { get; set; } = "";
7+
public string? Description { get; set; }
8+
}

backend/Discapp.Worker/Models/DiscogsRelease.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ namespace Discapp.Worker.Models;
33
public class DiscogsRelease
44
{
55
public string Thumb { get; set; } = "";
6+
public List<DiscogReleaseIdentifiers> Identifiers { get; set; } = [];
67
}

backend/Discapp.Worker/Worker.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ private async Task ProcessQueue(ApplicationDbContext dbContext, CancellationToke
6969
string filePath = Path.Combine(_pathOptions.ImagePath, queueItem.RecordID.ToString() + ".jpg");
7070
await File.WriteAllBytesAsync(filePath, imageBytes, stoppingToken);
7171

72+
string recordBarcode = releaseData.Identifiers
73+
.Where(id => id.Type == "Barcode")
74+
.Select(id => id.Value.Replace(" ", ""))
75+
.FirstOrDefault() ?? "";
76+
7277
Record? existingRecord = await dbContext.Records
7378
.FirstOrDefaultAsync(r => r.RecordID == queueItem.RecordID, stoppingToken);
7479

@@ -84,6 +89,7 @@ private async Task ProcessQueue(ApplicationDbContext dbContext, CancellationToke
8489
{
8590
RecordID = queueItem.RecordID,
8691
FilePath = $"{queueItem.RecordID.ToString()}.jpg",
92+
Barcode = recordBarcode,
8793
Recorded = DateTime.Now
8894
};
8995
dbContext.Records.Add(newRecord);

0 commit comments

Comments
 (0)