This repository has been archived by the owner on Oct 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UI to manage and share custom contracts
- Loading branch information
1 parent
860b934
commit b17ebfa
Showing
15 changed files
with
536 additions
and
12 deletions.
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ obj | |
*.user | ||
|
||
# Server | ||
/Src/HM5.Server/Contracts | ||
/Src/HM5.Server/Logs | ||
|
||
# Other | ||
|
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,75 @@ | ||
using HM5.Server.Controllers.Hitman; | ||
using HM5.Server.Interfaces; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace HM5.Server.Controllers | ||
{ | ||
[Route("contracts")] | ||
public class ContractsController : Controller | ||
{ | ||
private readonly IContractsService _contractsService; | ||
|
||
public ContractsController(IContractsService contractsService) | ||
{ | ||
_contractsService = contractsService; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View("~/Views/Contracts.cshtml"); | ||
} | ||
|
||
[HttpGet("all")] | ||
public IActionResult GetContracts() | ||
{ | ||
const int pageSize = 1000; | ||
|
||
var contracts = _contractsService.GetContracts(new HitmanController.SearchForContracts2Request | ||
{ | ||
LevelIndex = -1, | ||
CheckpointId = -1, | ||
Difficulty = -1, | ||
ContractId = string.Empty, | ||
StartIndex = 0, | ||
Range = pageSize | ||
}); | ||
|
||
return Json(contracts.Select(x => new | ||
{ | ||
x.Id, | ||
Name = x.DisplayId, | ||
x.Description, | ||
Level = _contractsService.GetLevelName(x), | ||
Targets = x.Targets.Targets | ||
.Select(y => y.Name) | ||
.ToList(), | ||
Difficulty = _contractsService.GetDifficultyName(x), | ||
Score = x.UserScore | ||
})); | ||
} | ||
|
||
[HttpGet("share/{contractId}")] | ||
public IActionResult GetShareLink(string contractId) | ||
{ | ||
var contractLink = _contractsService.GetShareableContractLink(contractId); | ||
|
||
return Json($"http://localhost/contracts/create/{contractLink}"); | ||
} | ||
|
||
[HttpGet("create/{compressedBase64Contract}")] | ||
public IActionResult CreateContract(string compressedBase64Contract) | ||
{ | ||
_contractsService.CreateContract(compressedBase64Contract); | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
|
||
[HttpGet("delete/{contractId}")] | ||
public IActionResult DeleteContract(string contractId) | ||
{ | ||
_contractsService.RemoveContract(contractId); | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
} | ||
} |
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,17 @@ | ||
using HM5.Server.Controllers.Hitman; | ||
using HM5.Server.Models; | ||
|
||
namespace HM5.Server.Interfaces | ||
{ | ||
public interface IContractsService | ||
{ | ||
void RebuildCache(); | ||
void CreateContract(HitmanController.UploadContractRequest request); | ||
void CreateContract(string compressedBase64Contract); | ||
void RemoveContract(string contractId); | ||
IEnumerable<Contract> GetContracts(HitmanController.SearchForContracts2Request request); | ||
string GetShareableContractLink(string contractId); | ||
string GetLevelName(Contract contract); | ||
string GetDifficultyName(Contract contract); | ||
} | ||
} |
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
Oops, something went wrong.