Skip to content

Commit

Permalink
Added initial auto back linking support (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsff authored Oct 24, 2023
1 parent ae3f4bf commit 198c871
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/SlownikPolonijny.Dal.Mongo/MongoEntryAuditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ public void CheckLinks(Entry entry, List<IAuditIssue> problems)
{
if (!HasBackLink(entry.Name, linkedEntry))
{
problems.Add(new GenericAuditIssue($"Jednostronny link. Hasło '{link}' nie jest spokrewnione z '{entry.Name}'"));
var fix = new AutoFixStrategy() { Name = "add-link" };
fix.Parameters["from"] = link;
fix.Parameters["to"] = entry.Name;

var issue = new GenericAuditIssue($"Jednostronny link. Hasło '{link}' nie jest spokrewnione z '{entry.Name}'");
issue.Fixes.Add(fix);

problems.Add(issue);
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/SlownikPolonijny.Dal/IEntryAuditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ public interface IEntryAuditor
IList<IAuditIssue> PerformEntryAudit(Entry entry);
}

public class AutoFixStrategy
{
public string Name { get; set; }
public Dictionary<string, string> Parameters { get; init; } = new();
}

public interface IAuditIssue
{
string Description { get; }
bool CanAutoFix { get; }

void AutoFix ();
IList<AutoFixStrategy> Fixes { get; }
}

public class GenericAuditIssue : IAuditIssue
Expand All @@ -25,11 +31,9 @@ public GenericAuditIssue(string description)

public string Description { get; init; }

public bool CanAutoFix => false;
public bool CanAutoFix => this.Fixes.Count > 0;

public void AutoFix()
{
}
public IList<AutoFixStrategy> Fixes { get; init; } = new List<AutoFixStrategy>();

public override string ToString()
{
Expand Down
32 changes: 32 additions & 0 deletions src/SlownikPolonijny.Web/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,38 @@ public async Task<IActionResult> Remove(string id)
return Json(r);
}

[Route("/admin/add-link/{from}/{to}")]
[HttpPost]
public async Task<IActionResult> AddRelatedLink(string from, string to)
{
var r = new AddEntryResultModel();

try
{
Entry entry = _repo.GetEntryById(from);
Entry toEntry = _repo.GetEntryById(to);
if (entry != null && toEntry != null)
{
var user = await this.GetCurrentUserAsync();

entry.ApprovedBy = user.UserName;
entry.SeeAlso.Add(to);
_repo.UpdateEntry(entry);
}
else
{
r.Problems.Add("Nie ma takiego hasła");
}
}
catch (System.Exception ex)
{
_logger.LogError(ex.ToString());
r.Problems.Add("Błąd bazy danych");
}

return Json(r);
}

[Route("/admin/usunieto/{id}/{name}")]
public IActionResult RemoveConfirmation(string id, string name)
{
Expand Down

0 comments on commit 198c871

Please sign in to comment.