mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Dont allow duplicate photo subjects on photo, dont allow more than 4 photo subjects on photo
This commit is contained in:
parent
b15d56f6e9
commit
bd21b8f9ed
2 changed files with 39 additions and 2 deletions
|
@ -53,6 +53,11 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
photo.CreatorId = user.UserId;
|
photo.CreatorId = user.UserId;
|
||||||
photo.Creator = user;
|
photo.Creator = user;
|
||||||
|
|
||||||
|
if (photo.Subjects.Count > 4)
|
||||||
|
{
|
||||||
|
return this.BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (PhotoSubject subject in photo.Subjects)
|
foreach (PhotoSubject subject in photo.Subjects)
|
||||||
{
|
{
|
||||||
subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username);
|
subject.User = await this.database.Users.FirstOrDefaultAsync(u => u.Username == subject.Username);
|
||||||
|
@ -67,6 +72,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Check for duplicate photo subjects
|
||||||
|
List<int> subjectUserIds = new(4);
|
||||||
|
foreach (PhotoSubject subject in photo.Subjects)
|
||||||
|
{
|
||||||
|
if (subjectUserIds.Contains(subject.UserId))
|
||||||
|
{
|
||||||
|
return this.BadRequest();
|
||||||
|
}
|
||||||
|
subjectUserIds.Add(subject.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
photo.PhotoSubjectIds = photo.Subjects.Select(subject => subject.PhotoSubjectId.ToString()).ToArray();
|
photo.PhotoSubjectIds = photo.Subjects.Select(subject => subject.PhotoSubjectId.ToString()).ToArray();
|
||||||
|
|
||||||
// photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId);
|
// photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId);
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
{
|
{
|
||||||
private readonly Database database = new();
|
private readonly Database database = new();
|
||||||
public string Name() => "Cleanup Broken Photos";
|
public string Name() => "Cleanup Broken Photos";
|
||||||
public string Description() => "Deletes all photos that have missing assets.";
|
public string Description() => "Deletes all photos that have missing assets or invalid photo subjects.";
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "LoopCanBePartlyConvertedToQuery")]
|
[SuppressMessage("ReSharper", "LoopCanBePartlyConvertedToQuery")]
|
||||||
public async Task Run()
|
public async Task Run()
|
||||||
|
@ -23,6 +23,8 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
bool hashNullOrEmpty = false;
|
bool hashNullOrEmpty = false;
|
||||||
bool noHashesExist = false;
|
bool noHashesExist = false;
|
||||||
bool largeHashIsInvalidFile = false;
|
bool largeHashIsInvalidFile = false;
|
||||||
|
bool tooManyPhotoSubjects = false;
|
||||||
|
bool duplicatePhotoSubjects = false;
|
||||||
|
|
||||||
hashNullOrEmpty = string.IsNullOrEmpty
|
hashNullOrEmpty = string.IsNullOrEmpty
|
||||||
(photo.LargeHash) ||
|
(photo.LargeHash) ||
|
||||||
|
@ -50,6 +52,23 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
goto removePhoto;
|
goto removePhoto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (photo.Subjects.Count > 4)
|
||||||
|
{
|
||||||
|
tooManyPhotoSubjects = true;
|
||||||
|
goto removePhoto;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<int> subjectUserIds = new(4);
|
||||||
|
foreach (PhotoSubject subject in photo.Subjects)
|
||||||
|
{
|
||||||
|
if (subjectUserIds.Contains(subject.UserId))
|
||||||
|
{
|
||||||
|
duplicatePhotoSubjects = true;
|
||||||
|
goto removePhoto;
|
||||||
|
}
|
||||||
|
subjectUserIds.Add(subject.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
removePhoto:
|
removePhoto:
|
||||||
|
@ -59,7 +78,9 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
$"Removing photo (id: {photo.PhotoId}): " +
|
$"Removing photo (id: {photo.PhotoId}): " +
|
||||||
$"{nameof(hashNullOrEmpty)}: {hashNullOrEmpty}, " +
|
$"{nameof(hashNullOrEmpty)}: {hashNullOrEmpty}, " +
|
||||||
$"{nameof(noHashesExist)}: {noHashesExist}, " +
|
$"{nameof(noHashesExist)}: {noHashesExist}, " +
|
||||||
$"{nameof(largeHashIsInvalidFile)}: {largeHashIsInvalidFile}"
|
$"{nameof(largeHashIsInvalidFile)}: {largeHashIsInvalidFile}, " +
|
||||||
|
$"{nameof(tooManyPhotoSubjects)}: {tooManyPhotoSubjects}" +
|
||||||
|
$"{nameof(duplicatePhotoSubjects)}: {duplicatePhotoSubjects}"
|
||||||
);
|
);
|
||||||
|
|
||||||
this.database.Photos.Remove(photo);
|
this.database.Photos.Remove(photo);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue