Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert song edit to React #1171

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Tests/DatabaseTests/Queries/SongQueriesDatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using VocaDb.Model.Database.Queries;
using VocaDb.Model.Database.Repositories;
using VocaDb.Model.DataContracts.ReleaseEvents;
using VocaDb.Model.DataContracts.Songs;
using VocaDb.Model.DataContracts.UseCases;
using VocaDb.Model.DataContracts.Users;
using VocaDb.Model.Domain.Globalization;
Expand Down Expand Up @@ -47,10 +48,11 @@ private SongQueries Queries(ISongRepository repository)
new VdbConfigManager(),
new EntrySubTypeNameFactory(),
new FollowedArtistNotifier(new FakeEntryLinkFactory(), new FakeUserMessageMailer(), new EnumTranslations(), new EntrySubTypeNameFactory()),
new FakeDiscordWebhookNotifier());
new FakeDiscordWebhookNotifier()
);
}

private async Task<SongForEditContract> Update(SongForEditContract contract)
private async Task<SongForEditForApiContract> Update(SongForEditForApiContract contract)
{
return await _context.RunTestAsync(async repository =>
{
Expand All @@ -71,7 +73,7 @@ public async Task Update_ReleaseEvent_Remove()
Db.ReleaseEvent.AllSongs.Contains(Db.Song).Should().BeTrue("Release event has song");

// Act
var contract = new SongForEditContract(Db.Song, ContentLanguagePreference.English)
var contract = new SongForEditForApiContract(Db.Song, ContentLanguagePreference.English, _userContext)
{
ReleaseEvent = null
};
Expand All @@ -97,10 +99,15 @@ await _context.RunTestAsync(async repository =>
{
var queries = Queries(repository);

var newEvent = repository.HandleTransaction(ctx => new ReleaseEventContract(ctx.Save(CreateEntry.ReleaseEvent("Mikumas")), ContentLanguagePreference.English, false));
var newEvent = repository.HandleTransaction(ctx => new ReleaseEventForApiContract(
rel: ctx.Save(CreateEntry.ReleaseEvent("Mikumas")),
languagePreference: ContentLanguagePreference.English,
fields: ReleaseEventOptionalFields.None,
thumbPersister: null
));

// Act
var contract = new SongForEditContract(Db.Song, ContentLanguagePreference.English)
var contract = new SongForEditForApiContract(Db.Song, ContentLanguagePreference.English, _userContext)
{
ReleaseEvent = newEvent
};
Expand All @@ -118,7 +125,7 @@ await _context.RunTestAsync(async repository =>
[TestCategory(TestCategories.Database)]
public async Task Update_Lyrics()
{
var contract = new SongForEditContract(Db.Song2, ContentLanguagePreference.English)
var contract = new SongForEditForApiContract(Db.Song2, ContentLanguagePreference.English, _userContext)
{
Lyrics = new[] { CreateEntry.LyricsForSongContract(TranslationType.Original) }
};
Expand Down
46 changes: 29 additions & 17 deletions Tests/Web/Controllers/DataAccess/SongQueriesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ private Task<NewSongCheckResultContract> CallFindDuplicates(string[] anyName = n
return (result.created, report);
}

private SongForEditContract EditContract()
private SongForEditForApiContract EditContract()
{
return new SongForEditContract(_song, ContentLanguagePreference.English);
return new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
}

private void AssertHasArtist(Song song, Artist artist, ArtistRoles? roles = null)
Expand Down Expand Up @@ -783,9 +783,9 @@ public async Task Revert()
{
_user.GroupId = UserGroupId.Moderator;
_permissionContext.RefreshLoggedUser(_repository);
SongForEditContract Contract()
SongForEditForApiContract Contract()
{
return new SongForEditContract(_song, ContentLanguagePreference.English);
return new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
}

await _queries.UpdateBasicProperties(Contract());
Expand Down Expand Up @@ -813,7 +813,7 @@ SongForEditContract Contract()
[TestMethod]
public async Task Update_Names()
{
var contract = new SongForEditContract(_song, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
contract.Names.First().Value = "Replaced name";
contract.UpdateNotes = "Updated song";

Expand Down Expand Up @@ -849,7 +849,7 @@ public async Task Update_Artists()
foreach (var name in newSong.Names)
_repository.Save(name);

var contract = new SongForEditContract(newSong, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(newSong, ContentLanguagePreference.English, _permissionContext);
contract.Artists = new[] {
CreateArtistForSongContract(artistId: _producer.Id),
CreateArtistForSongContract(artistId: _vocalist.Id),
Expand Down Expand Up @@ -878,7 +878,7 @@ public async Task Update_Artists_Notify()
_repository.Save(_user2.AddArtist(_vocalist2));
_repository.Save(_vocalist2);

var contract = new SongForEditContract(_song, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
contract.Artists = contract.Artists.Concat(new[] { CreateArtistForSongContract(_vocalist2.Id) }).ToArray();

await _queries.UpdateBasicProperties(contract);
Expand All @@ -896,7 +896,7 @@ public async Task Update_Artists_RemoveDeleted()
_repository.Save(_song.AddArtist(_vocalist2));
_vocalist2.Deleted = true;

var contract = new SongForEditContract(_song, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);

await _queries.UpdateBasicProperties(contract);

Expand All @@ -921,7 +921,7 @@ public async Task Update_Lyrics()
[TestMethod]
public async Task Update_PublishDate_From_PVs()
{
var contract = new SongForEditContract(_song, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
contract.PVs = new[] {
CreateEntry.PVContract(id: 1, pvId: "hoLu7c2XZYU", pvType: PVType.Reprint, publishDate: new DateTime(2015, 3, 9, 10, 0, 0)),
CreateEntry.PVContract(id: 2, pvId: "mikumikumiku", pvType: PVType.Original, publishDate: new DateTime(2015, 4, 9, 16, 0, 0))
Expand All @@ -937,9 +937,15 @@ public async Task Update_PublishDate_From_PVs()
[TestMethod]
public async Task Update_Weblinks()
{
var contract = new SongForEditContract(_song, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
contract.WebLinks = new[] {
new WebLinkContract("http://vocadb.net", "VocaDB", WebLinkCategory.Reference, disabled: false)
new WebLinkForApiContract
{
Url = "http://vocadb.net",
Description = "VocaDB",
Category = WebLinkCategory.Reference,
Disabled = false,
}
};

contract = await _queries.UpdateBasicProperties(contract);
Expand All @@ -951,9 +957,15 @@ public async Task Update_Weblinks()
[TestMethod]
public async Task Update_Weblinks_SkipWhitespace()
{
var contract = new SongForEditContract(_song, ContentLanguagePreference.English);
var contract = new SongForEditForApiContract(_song, ContentLanguagePreference.English, _permissionContext);
contract.WebLinks = new[] {
new WebLinkContract(" ", "VocaDB", WebLinkCategory.Reference, disabled: false)
new WebLinkForApiContract
{
Url = " ",
Description = "VocaDB",
Category = WebLinkCategory.Reference,
Disabled = false,
}
};

contract = await _queries.UpdateBasicProperties(contract);
Expand All @@ -968,7 +980,7 @@ public async Task Update_Weblinks_SkipWhitespace()
public async Task Update_ReleaseEvent_ExistingEvent_Selected()
{
var contract = EditContract();
contract.ReleaseEvent = new ReleaseEventContract(_releaseEvent, ContentLanguagePreference.English);
contract.ReleaseEvent = new ReleaseEventForApiContract(_releaseEvent, ContentLanguagePreference.English, ReleaseEventOptionalFields.None, thumbPersister: null);

await _queries.UpdateBasicProperties(contract);

Expand All @@ -982,7 +994,7 @@ public async Task Update_ReleaseEvent_ExistingEvent_Selected()
public async Task Update_ReleaseEvent_ExistingEvent_MatchByName()
{
var contract = EditContract();
contract.ReleaseEvent = new ReleaseEventContract { Name = _releaseEvent.DefaultName };
contract.ReleaseEvent = new ReleaseEventForApiContract { Name = _releaseEvent.DefaultName };

await _queries.UpdateBasicProperties(contract);

Expand All @@ -993,7 +1005,7 @@ public async Task Update_ReleaseEvent_ExistingEvent_MatchByName()
public async Task Update_ReleaseEvent_NewEvent_Standalone()
{
var contract = EditContract();
contract.ReleaseEvent = new ReleaseEventContract { Name = "Comiket 40" };
contract.ReleaseEvent = new ReleaseEventForApiContract { Name = "Comiket 40" };

await _queries.UpdateBasicProperties(contract);

Expand All @@ -1008,7 +1020,7 @@ public async Task Update_ReleaseEvent_NewEvent_SeriesEvent()
{
var series = _repository.Save(CreateEntry.EventSeries("Comiket"));
var contract = EditContract();
contract.ReleaseEvent = new ReleaseEventContract { Name = "Comiket 40" };
contract.ReleaseEvent = new ReleaseEventForApiContract { Name = "Comiket 40" };

await _queries.UpdateBasicProperties(contract);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public class ReleaseEventForApiContract : IReleaseEvent, IEntryBase

public ReleaseEventForApiContract() { }

public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference languagePreference, ReleaseEventOptionalFields fields, IAggregatedEntryImageUrlFactory thumbPersister)
#nullable enable
public ReleaseEventForApiContract(
ReleaseEvent rel,
ContentLanguagePreference languagePreference,
ReleaseEventOptionalFields fields,
IAggregatedEntryImageUrlFactory? thumbPersister
)
{
Category = rel.Category;
Date = rel.Date;
Expand Down Expand Up @@ -54,7 +60,7 @@ public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference la
Description = rel.Description;
}

if (thumbPersister != null && fields.HasFlag(ReleaseEventOptionalFields.MainPicture))
if (thumbPersister is not null && fields.HasFlag(ReleaseEventOptionalFields.MainPicture))
{
MainPicture = EntryThumbForApiContract.Create(EntryThumb.Create(rel) ?? EntryThumb.Create(rel.Series), thumbPersister);
}
Expand All @@ -69,7 +75,7 @@ public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference la
Series = new ReleaseEventSeriesContract(rel.Series, languagePreference);
}

if (fields.HasFlag(ReleaseEventOptionalFields.SongList) && rel.SongList != null)
if (fields.HasFlag(ReleaseEventOptionalFields.SongList) && rel.SongList is not null)
{
SongList = new SongListBaseContract(rel.SongList);
}
Expand All @@ -79,7 +85,7 @@ public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference la
Tags = rel.Tags.ActiveUsages.Select(t => new TagUsageForApiContract(t, languagePreference)).ToArray();
}

if (fields.HasFlag(ReleaseEventOptionalFields.Venue) && rel.Venue != null)
if (fields.HasFlag(ReleaseEventOptionalFields.Venue) && rel.Venue is not null)
{
Venue = new VenueForApiContract(rel.Venue, languagePreference, VenueOptionalFields.None);
}
Expand All @@ -89,6 +95,7 @@ public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference la
WebLinks = rel.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray();
}
}
#nullable disable

/// <summary>
/// Comma-separated list of all other names that aren't the display name.
Expand Down Expand Up @@ -118,7 +125,7 @@ public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference la
[DataMember]
public DateTime? EndDate { get; init; }

public bool HasVenueOrVenueName => Venue != null || !string.IsNullOrEmpty(VenueName);
public bool HasVenueOrVenueName => Venue is not null || !string.IsNullOrEmpty(VenueName);

[DataMember]
public int Id { get; set; }
Expand Down
Loading