diff --git a/src/SlownikPolonijny.Dal.Mongo/MongoEntryAuditor.cs b/src/SlownikPolonijny.Dal.Mongo/MongoEntryAuditor.cs index 3311cd6..aeb695c 100644 --- a/src/SlownikPolonijny.Dal.Mongo/MongoEntryAuditor.cs +++ b/src/SlownikPolonijny.Dal.Mongo/MongoEntryAuditor.cs @@ -220,7 +220,14 @@ public void CheckLinks(Entry entry, List 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); } } } diff --git a/src/SlownikPolonijny.Dal/IEntryAuditor.cs b/src/SlownikPolonijny.Dal/IEntryAuditor.cs index bdba7db..cc774d4 100644 --- a/src/SlownikPolonijny.Dal/IEntryAuditor.cs +++ b/src/SlownikPolonijny.Dal/IEntryAuditor.cs @@ -8,12 +8,18 @@ public interface IEntryAuditor IList PerformEntryAudit(Entry entry); } +public class AutoFixStrategy +{ + public string Name { get; set; } + public Dictionary Parameters { get; init; } = new(); +} + public interface IAuditIssue { string Description { get; } bool CanAutoFix { get; } - void AutoFix (); + IList Fixes { get; } } public class GenericAuditIssue : IAuditIssue @@ -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 Fixes { get; init; } = new List(); public override string ToString() { diff --git a/src/SlownikPolonijny.Web/Controllers/AdminController.cs b/src/SlownikPolonijny.Web/Controllers/AdminController.cs index c23aec8..cb3eea5 100644 --- a/src/SlownikPolonijny.Web/Controllers/AdminController.cs +++ b/src/SlownikPolonijny.Web/Controllers/AdminController.cs @@ -146,6 +146,38 @@ public async Task Remove(string id) return Json(r); } + [Route("/admin/add-link/{from}/{to}")] + [HttpPost] + public async Task 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) {