Skip to content

Commit

Permalink
amend robot: finish archives
Browse files Browse the repository at this point in the history
  • Loading branch information
darakeon committed Jul 3, 2024
1 parent 722b6a6 commit eda2536
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
11 changes: 11 additions & 0 deletions core/BusinessLogic/Repositories/DataObjects/ArchiveLineStati.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using DFM.Entities;
using DFM.Entities.Enums;

namespace DFM.BusinessLogic.Repositories.DataObjects
{
internal class ArchiveLineStati
{
public Archive Archive { get; set; }
public ImportStatus LineStati { get; set; }
}
}
16 changes: 15 additions & 1 deletion core/BusinessLogic/Repositories/LineRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
using DFM.Entities;
using System.Collections.Generic;
using DFM.BusinessLogic.Repositories.DataObjects;
using DFM.Entities;
using DFM.Entities.Enums;

namespace DFM.BusinessLogic.Repositories;

internal class LineRepository : Repo<Line>
{
public IList<ArchiveLineStati> GetArchivesPending()
{
return NewQuery()
.Where(l => l.Status != ImportStatus.Pending)
.LeftJoin(l => l.Archive)
.Where(l => l.Archive.Status == ImportStatus.Pending)
.TransformResult<ArchiveLineStati>()
.GroupBy(l => l.Archive, als => als.Archive)
.Max(l => l.Status, als => als.LineStati)
.List;
}
}
16 changes: 15 additions & 1 deletion core/BusinessLogic/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,21 @@ private Category getCategoryOrThrow(String name, User user)

public void FinishArchives()
{
throw new NotImplementedException();
if (!parent.Current.IsRobot)
throw Error.Uninvited.Throw();

var archivesLineStati = repos.Line.GetArchivesPending();

foreach (var archiveLineStati in archivesLineStati)
{
var archive = archiveLineStati.Archive;
archive.Status = archiveLineStati.LineStati;

inTransaction("FinishArchives", () =>
{
repos.Archive.SaveOrUpdate(archive);
});
}
}
}
}
6 changes: 5 additions & 1 deletion core/Tests/BusinessLogic/Steps/_D.RobotStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,11 @@ public void ThenTheLinesWillBeDequeued()
[Given(@"robot made move from imported")]
public void GivenRobotMadeMoveFromImported()
{
robotRunMakeMoves();
try
{
robotRunMakeMoves();
}
catch (AggregateException) { }
}

[When(@"finish imported archives")]
Expand Down

0 comments on commit eda2536

Please sign in to comment.