Skip to content

Commit

Permalink
robot: handle archives and lines on wiping
Browse files Browse the repository at this point in the history
  • Loading branch information
darakeon committed Jul 3, 2024
1 parent 6235cfc commit a9f52aa
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/BusinessLogic/Repositories/Mappings/LineMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public void Override(AutoMapping<Line> mapping)
.UniqueKey("Line_NumberArchive");

mapping.HasMany(l => l.DetailList)
.Cascade.SaveUpdate();
.Cascade.AllDeleteOrphan()
.Not.LazyLoad();

mapping.Map(l => l.In)
.Column("In_");
Expand Down
7 changes: 7 additions & 0 deletions core/BusinessLogic/Repositories/WipeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public void Execute(User user, DateTime date, RemovalReason reason)
wipeAll(repos.Account, a => a.User, u => u.ID == user.ID);
wipeAll(repos.Category, c => c.User, u => u.ID == user.ID);

var archives = repos.Archive.Where(a => a.User.ID == user.ID);
foreach (var archive in archives)
{
wipeAll(repos.Line, m => m.Archive, a => a.ID == archive.ID);
}
wipeAll(repos.Archive, c => c.User, u => u.ID == user.ID);

wipeAll(repos.Tips, a => a.User, u => u.ID == user.ID);

repos.User.Delete(user);
Expand Down
6 changes: 5 additions & 1 deletion core/Entities/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
using Keon.Util.DB;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DFM.Entities;

public class Line : IEntityLong
{
public Line()
{
DetailList = new List<Detail>();
}

public virtual Int64 ID { get; set; }

public virtual Int16 Position { get; set; }
Expand Down
70 changes: 66 additions & 4 deletions core/Tests/BusinessLogic/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public Builder(Repos repos, Action<Action> inTransaction, String code)
{nameof(Detail), detailFor},
{nameof(Summary), summaryFor},
{nameof(Schedule), scheduleFor},

{nameof(Archive), archiveFor},
{nameof(Line), lineFor},
};
}

Expand Down Expand Up @@ -176,28 +179,49 @@ private Move moveFor(User user, String suffix)
return move;
}

private void detailFor(Int32 count, Move move)
private void detailFor(Int32 count, IEntityLong parent)
{
for (var d = 0; d < count; d++)
{
var detail = new Detail
{
Guid = Guid.NewGuid(),
Move = move,
Description = $"Detail {d+1}",
Amount = 3,
ValueCents = 9,
};

Action<Detail> addToParent;

if (parent is Move move)
{
detail.Move = move;
addToParent = move.DetailList.Add;
}
else if (parent is Schedule schedule)
{
detail.Schedule = schedule;
addToParent = schedule.DetailList.Add;
}
else if (parent is Line line)
{
detail.Line = line;
addToParent = line.DetailList.Add;
}
else
{
throw new NotImplementedException();
}

repos.Detail.SaveOrUpdate(detail);
move.DetailList.Add(detail);
addToParent(detail);
}
}

private Detail detailFor(User user)
{
var move = moveFor(user, "detail");

return move.DetailList[0];
}

Expand All @@ -224,6 +248,8 @@ private Schedule scheduleFor(User user)
User = user,
};

detailFor(3, schedule);

return repos.Schedule.SaveOrUpdate(schedule);
}

Expand All @@ -242,5 +268,41 @@ private Summary summaryFor(User user)
return repos.Summary.GetAll()
.FirstOrDefault(s => s.User().ID == user.ID);
}

private Archive archiveFor(User user)
{
var archive = new Archive
{
Filename = $"File {code}",
LineList = new List<Line>(),
Status = ImportStatus.Pending,
User = user,
};

return repos.Archive.SaveOrUpdate(archive);
}

private Line lineFor(User user)
{
var archive = archiveFor(user);

var line = new Line
{
Description = $"Schedule {code}",
Date = new DateTime(1986, 3, 27),
Category = "Category",
Nature = MoveNature.Transfer,
In = "Account In",
Out = "Account Out",
Value = 27,
Status = ImportStatus.Pending,
Archive = archive,
Position = 1,
};

detailFor(3, line);

return repos.Line.SaveOrUpdate(line);
}
}
}
2 changes: 2 additions & 0 deletions core/Tests/BusinessLogic/G.Robot/g.WipeUsers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ Scenario: Gg60. Wipe complete user
| Detail |
| Summary |
| Schedule |
| Archive |
| Line |
And data wipe was asked
When robot user login
And call wipe users
Expand Down

0 comments on commit a9f52aa

Please sign in to comment.