-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using StarWarsKb.Back.Model; | ||
|
||
namespace StarWarsKb.Back.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class ConfigController : Controller | ||
{ | ||
private readonly IClearService _clearService; | ||
private readonly IUpdateService _updateService; | ||
|
||
public ConfigController(IClearService clearService, IUpdateService updateService) | ||
{ | ||
_clearService = clearService; | ||
_updateService = updateService; | ||
} | ||
|
||
[HttpGet] | ||
[Route("[action]")] | ||
public string Clear() | ||
{ | ||
_clearService.ClearDB(); | ||
return "Success"; | ||
} | ||
|
||
[HttpGet] | ||
[Route("[action]")] | ||
public string Update() | ||
{ | ||
_updateService.CreateData(); | ||
return "Success!"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using StarWarsKb.Infrastructure.Model; | ||
|
||
namespace StarWarsKb.Back.Model | ||
{ | ||
public class ClearService : IClearService | ||
{ | ||
private readonly IBaseRepository<Character> _characterRepository; | ||
private readonly IBaseRepository<Planet> _planetRepository; | ||
private readonly IBaseRepository<Starship> _starshipRepository; | ||
private readonly IUnitOfWork _unitOfWork; | ||
|
||
public ClearService(IUnitOfWork unitOfWork, | ||
IBaseRepository<Character> characterRepository, | ||
IBaseRepository<Planet> planetRepository, | ||
IBaseRepository<Starship> starshipRepository) | ||
{ | ||
_characterRepository = characterRepository; | ||
_unitOfWork = unitOfWork; | ||
_planetRepository = planetRepository; | ||
_starshipRepository = starshipRepository; | ||
} | ||
|
||
public void ClearDB() | ||
{ | ||
_characterRepository.DeleteAll(); | ||
_planetRepository.DeleteAll(); | ||
_starshipRepository.DeleteAll(); | ||
_unitOfWork.SaveChanges(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace StarWarsKb.Back.Model | ||
{ | ||
public interface IClearService | ||
{ | ||
void ClearDB(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using StarWarsKb.Front.Models; | ||
|
||
namespace StarWarsKb.Front.Controllers | ||
{ | ||
public class SettingsController : Controller | ||
{ | ||
private readonly IBackEndCaller _backEndCaller; | ||
|
||
public SettingsController(IBackEndCaller backEndCaller) | ||
{ | ||
_backEndCaller = backEndCaller; | ||
} | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Clear() | ||
{ | ||
var t = _backEndCaller.Clear(); | ||
//t.Wait(60000); | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Update() | ||
{ | ||
var t = _backEndCaller.Update(); | ||
//t.Wait(60000); | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Threading.Tasks; | ||
using StarWarsKb.Infrastructure.Services; | ||
|
||
namespace StarWarsKb.Front.Models | ||
{ | ||
public class BackEndCaller : IBackEndCaller | ||
{ | ||
private readonly IHttpReader _httpReader; | ||
private readonly IParamService _paramService; | ||
|
||
public BackEndCaller(IHttpReader httpReader, IParamService paramService) | ||
{ | ||
_httpReader = httpReader; | ||
_paramService = paramService; | ||
} | ||
|
||
public async Task<string> Update() | ||
{ | ||
return await CallBackEnd(@"/Config/Update/"); | ||
} | ||
|
||
private async Task<string> CallBackEnd(string address) | ||
{ | ||
var url = _paramService.GetParam("SWKB-back-address") + address; | ||
var str = await _httpReader.GetJsonStringByUrl(url); | ||
|
||
if (str == _httpReader.ErrorMessage) | ||
{ | ||
return await new Task<string>(() => "Failed"); | ||
} | ||
|
||
return str; | ||
} | ||
|
||
public async Task<string> Clear() | ||
{ | ||
return await CallBackEnd(@"/Config/Clear/"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace StarWarsKb.Front.Models | ||
{ | ||
public interface IBackEndCaller | ||
{ | ||
Task<string> Update(); | ||
Task<string> Clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
} | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>title</title> | ||
</head> | ||
<body> | ||
<div class="container px-4 py-5" id="hanging-icons"> | ||
<h2 class="pb-2 border-bottom">Star Wars Knowledge Base settings</h2> | ||
<div class="row g-4 py-5 row-cols-1 row-cols-lg-3"> | ||
<div class="col d-flex align-items-start"> | ||
<div class="icon-square bg-light text-dark flex-shrink-0 me-3"> | ||
<svg class="bi" width="1em" height="1em"><use xlink:href="#toggles2"/></svg> | ||
</div> | ||
<div> | ||
<h2>Clear database</h2> | ||
<p>Click this button to clear database</p> | ||
<a class="btn btn-primary" asp-area="" asp-controller="Settings" asp-action="Clear"> | ||
May the Force be with you | ||
</a> | ||
</div> | ||
</div> | ||
<div class="col d-flex align-items-start"> | ||
<div class="icon-square bg-light text-dark flex-shrink-0 me-3"> | ||
<svg class="bi" width="1em" height="1em"><use xlink:href="#cpu-fill"/></svg> | ||
</div> | ||
<div> | ||
<h2>Update database</h2> | ||
<p>Click this button to update database</p> | ||
<a class="btn btn-primary" asp-area="" asp-controller="Settings" asp-action="Update"> | ||
May the Force be with you | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters