Skip to content

Commit c581d7d

Browse files
authored
Add routes for authors, tags, licences, object packs and sc5 packs (#162)
Add routes for authors, tags, licences, object packs and sc5 packs
1 parent b43df81 commit c581d7d

18 files changed

+243
-44
lines changed

DatabaseExporter/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
foreach (var o in db.SC5FilePacks
5151
.Include(l => l.Licence)
52-
.Select(x => new ExpandedTblPack<TblSC5FilePack>(x, x.Authors, x.Tags))
52+
.Select(x => new ExpandedTblPack<TblSC5FilePack, TblSC5File>(x, x.SC5Files, x.Authors, x.Tags))
5353
.ToList()
5454
.OrderBy(x => x.Pack.Name))
5555
{
@@ -76,7 +76,7 @@
7676

7777
foreach (var o in db.ObjectPacks
7878
.Include(l => l.Licence)
79-
.Select(x => new ExpandedTblPack<TblLocoObjectPack>(x, x.Authors, x.Tags))
79+
.Select(x => new ExpandedTblPack<TblLocoObjectPack, TblLocoObject>(x, x.Objects, x.Authors, x.Tags))
8080
.ToList()
8181
.OrderBy(x => x.Pack.Name))
8282
{

Definitions/DTO/DtoAuthorEntry.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace OpenLoco.Definitions.DTO
2+
{
3+
public record DtoAuthorEntry(
4+
int Id,
5+
string Name);
6+
}

Definitions/DTO/DtoDatObjectWithMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OpenLoco.Definitions.DTO
66
{
7-
public record DtoDatObjectWithMetadata(
7+
public record DtoObjectDescriptorWithMetadata(
88
int Id,
99
string UniqueName,
1010
string DatName,

Definitions/DTO/DtoExtensions.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using OpenLoco.Definitions.Database;
2+
using OpenLoco.Definitions.SourceData;
3+
4+
namespace OpenLoco.Definitions.DTO
5+
{
6+
public static class DtoExtensions
7+
{
8+
public static DtoObjectDescriptor ToDtoDescriptor(this TblLocoObject x)
9+
=> new(
10+
x.Id,
11+
x.DatName,
12+
x.DatChecksum,
13+
x.ObjectSource,
14+
x.ObjectType,
15+
x.VehicleType,
16+
x.Availability,
17+
x.Name,
18+
x.Description,
19+
x.CreationDate,
20+
x.LastEditDate,
21+
x.UploadDate
22+
);
23+
24+
public static DtoObjectEntry ToDtoEntry(this TblLocoObject x)
25+
=> new(
26+
x.Id,
27+
x.DatName,
28+
x.DatChecksum);
29+
30+
public static DtoScenarioEntry ToDtoEntry(this TblSC5File x)
31+
=> new(
32+
x.Id,
33+
x.Name);
34+
35+
public static DtoItemPackEntry ToDtoEntry(this TblSC5FilePack x)
36+
=> new(
37+
x.Id,
38+
x.Name,
39+
x.Description,
40+
x.CreationDate,
41+
x.LastEditDate,
42+
x.UploadDate,
43+
x.Licence);
44+
45+
public static DtoItemPackEntry ToDtoEntry(this TblLocoObjectPack x)
46+
=> new(
47+
x.Id,
48+
x.Name,
49+
x.Description,
50+
x.CreationDate,
51+
x.LastEditDate,
52+
x.UploadDate,
53+
x.Licence);
54+
55+
public static DtoItemPackDescriptor<DtoObjectEntry> ToDtoDescriptor(this ExpandedTblPack<TblLocoObjectPack, TblLocoObject> x)
56+
=> new(
57+
x.Pack.Id,
58+
x.Pack.Name,
59+
x.Pack.Description,
60+
x.Items.Select(x => x.ToDtoEntry()).ToList(),
61+
x.Authors,
62+
x.Pack.CreationDate,
63+
x.Pack.LastEditDate,
64+
x.Pack.UploadDate,
65+
x.Tags,
66+
x.Pack.Licence);
67+
68+
public static DtoItemPackDescriptor<DtoScenarioEntry> ToDtoDescriptor(this ExpandedTblPack<TblSC5FilePack, TblSC5File> x)
69+
=> new(
70+
x.Pack.Id,
71+
x.Pack.Name,
72+
x.Pack.Description,
73+
x.Items.Select(x => x.ToDtoEntry()).ToList(),
74+
x.Authors,
75+
x.Pack.CreationDate,
76+
x.Pack.LastEditDate,
77+
x.Pack.UploadDate,
78+
x.Tags,
79+
x.Pack.Licence);
80+
}
81+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using OpenLoco.Definitions.Database;
2+
3+
namespace OpenLoco.Definitions.DTO
4+
{
5+
public record DtoItemPackDescriptor<T>(
6+
int Id,
7+
string Name,
8+
string? Description,
9+
ICollection<T> Items,
10+
ICollection<TblAuthor> Authors,
11+
DateTimeOffset? CreationDate,
12+
DateTimeOffset? LastEditDate,
13+
DateTimeOffset UploadDate,
14+
ICollection<TblTag> Tags,
15+
TblLicence? Licence);
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using OpenLoco.Definitions.Database;
2+
3+
namespace OpenLoco.Definitions.DTO
4+
{
5+
public record DtoItemPackEntry(
6+
int Id,
7+
string Name,
8+
string? Description,
9+
DateTimeOffset? CreationDate,
10+
DateTimeOffset? LastEditDate,
11+
DateTimeOffset UploadDate,
12+
TblLicence? Licence);
13+
}

Definitions/DTO/DtoLicenceEntry.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace OpenLoco.Definitions.DTO
2+
{
3+
public record DtoLicenceEntry(
4+
int Id,
5+
string Name,
6+
string LicenceText);
7+
}

Definitions/DTO/DtoObjectIndexEntry.cs renamed to Definitions/DTO/DtoObjectDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace OpenLoco.Definitions.DTO
55
{
6-
public record DtoObjectIndexEntry(
6+
public record DtoObjectDescriptor(
77
int Id,
88
string DatName,
99
uint DatChecksum,

Definitions/DTO/DtoObjectEntry.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace OpenLoco.Definitions.DTO
2+
{
3+
public record DtoObjectEntry(
4+
int Id,
5+
string DatName,
6+
uint DatChecksum);
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace OpenLoco.Definitions.DTO
2+
{
3+
public record DtoScenarioEntry(
4+
int Id,
5+
string Name);
6+
}

0 commit comments

Comments
 (0)