This commit is contained in:
parent
d30b355450
commit
ec89c33656
Binary file not shown.
|
@ -18,21 +18,25 @@ namespace api.Controllers
|
|||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class CromosController : ControllerBase
|
||||
{
|
||||
{ private readonly IUsersRepository _repo;
|
||||
private readonly DataContext context;
|
||||
private readonly IMapper _mapper;
|
||||
public CromosController(DataContext context, IMapper mapper)
|
||||
public CromosController(IUsersRepository repo,DataContext context, IMapper mapper)
|
||||
{
|
||||
this.context = context;
|
||||
_mapper = mapper;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
// GET api/cromos/QR
|
||||
// GET cromos do user QR
|
||||
|
||||
[HttpGet("{QR}")]
|
||||
|
||||
public async Task<IActionResult> GetCromos(string QR)
|
||||
{
|
||||
int soma = 0;
|
||||
int somaCTF=0;
|
||||
var usr = await context.Users.FirstOrDefaultAsync(u => u.QRcode == QR);
|
||||
string[] usrCromos = usr.cromos.Substring(1).Split(",");
|
||||
Console.WriteLine(usrCromos[0]);
|
||||
|
@ -58,6 +62,9 @@ namespace api.Controllers
|
|||
continue;
|
||||
else
|
||||
{
|
||||
if(c.Id == 4 || c.Id==5 || c.Id==6 || c.Id==7 || c.Id==8 || c.Id==9 || c.Id==10 || c.Id==11 || c.Id==12 || c.Id==13 || c.Id==14 || c.Id==16){
|
||||
somaCTF += c.pontos;
|
||||
}
|
||||
soma += c.pontos;
|
||||
rList.Add(toAdd);
|
||||
found = true;
|
||||
|
@ -80,6 +87,17 @@ namespace api.Controllers
|
|||
cromosToReturn a = new cromosToReturn();
|
||||
a.cromos = rList;
|
||||
a.pontuacao = soma;
|
||||
|
||||
|
||||
var userFromRepo = await _repo.GetUser(usr.Id);
|
||||
|
||||
userFromRepo.food = somaCTF;
|
||||
userFromRepo.drinks = soma;
|
||||
|
||||
|
||||
if (await _repo.SaveAll()){}
|
||||
|
||||
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,8 @@ namespace api.Controllers
|
|||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpGet]
|
||||
|
||||
//[AllowAnonymous]
|
||||
public async Task<IActionResult> GetUsers()
|
||||
{
|
||||
var users = await _repo.GetUsers();
|
||||
|
|
|
@ -8,6 +8,8 @@ using api.Dtos;
|
|||
using Microsoft.AspNetCore.Identity;
|
||||
using api.Models;
|
||||
using System.Net.Http;
|
||||
using AutoMapper;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace api.Controllers
|
||||
{
|
||||
|
@ -15,13 +17,17 @@ namespace api.Controllers
|
|||
[Route("/")]
|
||||
public class mvcController : Controller
|
||||
{
|
||||
|
||||
private readonly IUsersRepository _repo;
|
||||
private readonly DataContext _context;
|
||||
private readonly UserManager<User> _userManager;
|
||||
|
||||
public mvcController(DataContext context, UserManager<User> userManager)
|
||||
private readonly IMapper _mapper;
|
||||
public mvcController(IUsersRepository repo, DataContext context, IMapper mapper, UserManager<User> userManager)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
_repo = repo;
|
||||
}
|
||||
[HttpGet("/cp-ia")]
|
||||
[AllowAnonymous]
|
||||
|
@ -67,6 +73,28 @@ namespace api.Controllers
|
|||
return View("Views/Landing/jogo.cshtml");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/ctf/top")]
|
||||
public async Task<IActionResult> getTop()
|
||||
{
|
||||
//para cada user calcular pontos, fazer update e devolver top 5
|
||||
|
||||
|
||||
// var users = await _repo.GetUsers();
|
||||
|
||||
// var usersToReturn = _mapper.Map<IEnumerable<UserForListDto>>(users);
|
||||
|
||||
var users = _context.Users.Select(user => new {Nome = user.fullName, Pontos = user.food }).OrderByDescending(x => x.Pontos).Take(10);;
|
||||
|
||||
|
||||
|
||||
//food = soma ctf
|
||||
|
||||
//drinks = soma geral
|
||||
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("/level1ctf")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult level1()
|
||||
|
|
|
@ -61,8 +61,8 @@
|
|||
<div class="ctf-header">
|
||||
<div class="ctf-top10">
|
||||
<h1 class="top-title">Melhores classificados CTF </h1>
|
||||
<center><h3>Revelados em breve</h3></center>
|
||||
|
||||
|
||||
<div id="content" class="table table-striped table-dark"></div>
|
||||
</div>
|
||||
|
||||
<h3 class="about-top">Estas pontuações refletem o somatório das pontuações dos níveis cumpridos.</h3>
|
||||
|
@ -327,9 +327,80 @@
|
|||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
const wrapper = document.getElementById('content');
|
||||
|
||||
|
||||
const demoData = [
|
||||
|
||||
];
|
||||
|
||||
function fetchData() {
|
||||
|
||||
var top=[];
|
||||
var i=1;
|
||||
axios.get('http://localhost:5000/ctf/top')
|
||||
.then(function (response) {
|
||||
|
||||
response.data.forEach(function(entry) {
|
||||
top.push({Num:i, Nome: entry.nome, Pontos: entry.pontos})
|
||||
i++
|
||||
});
|
||||
|
||||
populate(top)
|
||||
})
|
||||
.catch(function (error) {
|
||||
|
||||
console.log(error);
|
||||
})
|
||||
|
||||
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', fetchData, false);
|
||||
|
||||
function dom(tag, text) {
|
||||
let r = document.createElement(tag);
|
||||
if (text) r.innerText = text;
|
||||
return r;
|
||||
};
|
||||
|
||||
function append(parent, child) {
|
||||
parent.appendChild(child);
|
||||
return parent;
|
||||
};
|
||||
|
||||
function populate(json) {
|
||||
if (json.length === 0) return;
|
||||
let keys = Object.keys(json[0]);
|
||||
|
||||
let table = dom('table');
|
||||
|
||||
append(table,
|
||||
keys.map(k => dom('th', k)).reduce(append, dom('tr'))
|
||||
);
|
||||
|
||||
const makeRow = (acc, row) =>
|
||||
|
||||
append(acc,
|
||||
keys.map(k => dom('td', row[k])).reduce(append, dom('tr'))
|
||||
);
|
||||
|
||||
json.reduce(makeRow, table);
|
||||
wrapper.appendChild(table);
|
||||
};
|
||||
|
||||
</script>
|
||||
<style>
|
||||
table{
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
<!-- Scripts -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/scripts.js"></script>
|
||||
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
Loading…
Reference in New Issue