Closed aluhrs13 closed 4 years ago
I've definitely got some suggestions for this. A little polymorphism around source sites would enable a strategy pattern for the lookups, which would make this more extensible. In short, rather than a load of URL properties on the Creator
type, it would have a property ICollection<SourceSite> Sources
where SourceSite
is an abstract type with a property URL
. There would then be derived types for ThingiverseSource
, ShapewaysSource
, etc, and so the logic would just be something like _context.Creator.FirstOrDefault(c => c.Sources.Any(site => site.URL == sourceUrl);
which would replace the entire if ... else if ... else
construct.
If the SourceSite
type also had a Parse
method that returned a standard object with name, image, description etc. then the various parsing methods in Create.cshtml.cs wouldn't be needed either, and adding new source sites would be as simple as implementing a new SourceSite
type (more or less).
Would we also want SourceSite
to have a user friendly name? For example, on https://theminiindex.com/Creators/Details?id=2 right now it just has "Patreon", "Shapeways", and "Thingiverse" but as we grow we'd likely want another field for sites like https://www.drivethrurpg.com/ where the site name isn't too pretty by itself.
Yes, probably. This can be a constant-value property on the derived types; something simple like this:
public class SourceSite
{
public abstract string DisplayName { get; }
}
public class ThingiverseSource : SourceSite
{
public override string DisplayName => "Thingiverse";
}
public class DriveThruRpgSource : SourceSite
{
public override string DisplayName => "DriveThruRPG";
}
I'm currently using the type discriminator for this, but actually that should be separate, in case the display name needs to change.
Designing some UI improvements and realized we probably also want SourceSites to have an icon associated with them. Probably fine if it's an icon we check-in as part of adding the parser. This'll let us show people which site a mini is from, mock-up in the bottom-right corner of each mini in this screenshot:
I like that. Simplest way is probably a display template for a mini thumbnail that takes the source site as a parameter, and then inside the template it can just use Razor to set the correct CSS class on the overlay, which gives it the relevant image.
I'll see if I can include a prototype of it in my branch.
In OnPostAsync() of Create.cshtml.cs, it feels extremely fragile right now and doesn't scale too much more than its current state. Every new source of mini's makes it worse and worse. As part of this, the schema for a Creator shouldn't include a weird hard-coded list of URLs, but should have an array of URLs that can be whatever.