small up
This commit is contained in:
parent
629d86229b
commit
5c7498b3ec
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using api.Data;
|
||||
using api.Dtos;
|
||||
using api.Models;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace api.Controllers
|
||||
{
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class EventLocsController : ControllerBase
|
||||
{
|
||||
private readonly DataContext context;
|
||||
private readonly IEventLocsRepository _repo;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly RoleManager<Role> _roleManager;
|
||||
private readonly UserManager<User> _userManager;
|
||||
public EventLocsController(DataContext context,IEventLocsRepository repo, IMapper mapper,RoleManager<Role> roleManager,UserManager<User> UserManager)
|
||||
{
|
||||
this.context = context;
|
||||
_mapper = mapper;
|
||||
_roleManager = roleManager;
|
||||
_userManager = UserManager;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
// GET api/EventLocs
|
||||
// GET all EventLocs
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetEventLocs()
|
||||
{
|
||||
var Teams = await _repo.GetEventLocs();
|
||||
return Ok(Teams);
|
||||
}
|
||||
|
||||
// GET api/EventLocs/[id]
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetEventLoc(int id)
|
||||
{
|
||||
var Teams = await _repo.GetEventLoc(id);
|
||||
return Ok(Teams);
|
||||
}
|
||||
|
||||
// GET api/EventLocs/[id]
|
||||
[HttpGet("e/{id}")]
|
||||
public async Task<IActionResult> GetEventLocEvent(int id)
|
||||
{
|
||||
var Teams = await _repo.GetEventLocEvent(id);
|
||||
return Ok(Teams);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using api.Data;
|
||||
using api.Dtos;
|
||||
using api.Models;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace api.Controllers
|
||||
{
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class EventLocsVisitedController : ControllerBase
|
||||
{
|
||||
private readonly DataContext context;
|
||||
private readonly IEventLocsVisitedRepository _repo;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly RoleManager<Role> _roleManager;
|
||||
private readonly UserManager<User> _userManager;
|
||||
public EventLocsVisitedController(DataContext context,IEventLocsVisitedRepository repo, IMapper mapper,RoleManager<Role> roleManager,UserManager<User> UserManager)
|
||||
{
|
||||
this.context = context;
|
||||
_mapper = mapper;
|
||||
_roleManager = roleManager;
|
||||
_userManager = UserManager;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
// GET api/EventLocsVisited
|
||||
// GET all EventLocsVisited
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetEventLocsVisited()
|
||||
{
|
||||
var Locs = await _repo.GetEventLocsVisited();
|
||||
return Ok(Locs);
|
||||
}
|
||||
|
||||
// GET api/EventLocsVisited/t/[id]
|
||||
//All locs visited by team id
|
||||
[HttpGet("t/{id}")]
|
||||
public async Task<IActionResult> GetEventLocsVisitedTeam(int id)
|
||||
{
|
||||
var Locs = await _repo.GetEventLocsVisitedTeam(id);
|
||||
return Ok(Locs);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -20,11 +20,11 @@ namespace api.Controllers
|
|||
public class TeamsController : ControllerBase
|
||||
{
|
||||
private readonly DataContext context;
|
||||
private readonly IUsersRepository _repo;
|
||||
private readonly ITeamsRepository _repo;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly RoleManager<Role> _roleManager;
|
||||
private readonly UserManager<User> _userManager;
|
||||
public TeamsController(DataContext context,IUsersRepository repo, IMapper mapper,RoleManager<Role> roleManager,UserManager<User> UserManager)
|
||||
public TeamsController(DataContext context,ITeamsRepository repo, IMapper mapper,RoleManager<Role> roleManager,UserManager<User> UserManager)
|
||||
{
|
||||
this.context = context;
|
||||
_mapper = mapper;
|
||||
|
@ -38,7 +38,7 @@ namespace api.Controllers
|
|||
[HttpGet]
|
||||
public async Task<IActionResult> GetTeams()
|
||||
{
|
||||
var Teams = await context.Teams.ToArrayAsync();
|
||||
var Teams = await _repo.GetTeams();
|
||||
return Ok(Teams);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace api.Controllers
|
|||
[HttpGet("e/{id}")]
|
||||
public async Task<IActionResult> GetTeamsEvent(int id)
|
||||
{
|
||||
var Teams = await context.Teams.FirstOrDefaultAsync(e=>e.EventId == id);
|
||||
var Teams = await _repo.GetEventTeam(id);
|
||||
return Ok(Teams);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using api.Models;
|
||||
using api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace api.Data
|
||||
{
|
||||
public class EventLocsRepository : IEventLocsRepository
|
||||
{
|
||||
public EventLocsRepository(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public DataContext _context { get; }
|
||||
|
||||
public async Task<EventLoc> GetEventLoc(int id)
|
||||
{
|
||||
var rEventLocs = await _context.EventLocs.FirstOrDefaultAsync(e=>e.Id == id);
|
||||
|
||||
return rEventLocs;
|
||||
}
|
||||
|
||||
public async Task<EventLoc> GetEventLocEvent(int id)
|
||||
{
|
||||
var rEventLocs = await _context.EventLocs.FirstOrDefaultAsync(e=>e.EventId == id);
|
||||
|
||||
return rEventLocs;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<EventLoc>> GetEventLocs()
|
||||
{
|
||||
var rEventLocs = await _context.EventLocs.ToListAsync();
|
||||
|
||||
return rEventLocs;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using api.Models;
|
||||
using api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace api.Data
|
||||
{
|
||||
public class EventLocsVisitedRepository : IEventLocsVisitedRepository
|
||||
{
|
||||
public EventLocsVisitedRepository(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public DataContext _context { get; }
|
||||
|
||||
public async Task<IEnumerable<EventLocVisited>> GetEventLocsVisited()
|
||||
{
|
||||
var rEventLocsVisitedList = await _context.EventLocsVisited.ToListAsync();
|
||||
|
||||
return rEventLocsVisitedList;
|
||||
}
|
||||
|
||||
public Task<IEnumerable<EventLocVisited>> GetEventLocsVisitedTeam(int id)
|
||||
{
|
||||
List<EventLocVisited> allLocs = _context.EventLocsVisited.ToList();
|
||||
allLocs.ForEach(i=>Console.Write("{0}\t", i));
|
||||
Console.WriteLine("teste");
|
||||
List<EventLocVisited> rList = new List<EventLocVisited>();
|
||||
for(var i=0;i<allLocs.Count;i++){
|
||||
if(allLocs[i].Team.Id == id){
|
||||
rList.Add(allLocs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return rList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using api.Models;
|
||||
|
||||
namespace api.Data
|
||||
{
|
||||
public interface IEventLocsRepository
|
||||
{
|
||||
|
||||
Task<IEnumerable<EventLoc>> GetEventLocs();
|
||||
Task<EventLoc> GetEventLoc(int id);
|
||||
Task<EventLoc> GetEventLocEvent(int id);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using api.Models;
|
||||
|
||||
namespace api.Data
|
||||
{
|
||||
public interface IEventLocsVisitedRepository
|
||||
{
|
||||
|
||||
Task<IEnumerable<EventLocVisited>> GetEventLocsVisited();
|
||||
Task<IEnumerable<EventLocVisited>> GetEventLocsVisitedTeam(int id);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using api.Models;
|
||||
|
||||
namespace api.Data
|
||||
{
|
||||
public interface ITeamsRepository
|
||||
{
|
||||
|
||||
Task<IEnumerable<Team>> GetTeams();
|
||||
Task<Team> GetEventTeam(int id);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using api.Models;
|
||||
using api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace api.Data
|
||||
{
|
||||
public class TeamsRepository : ITeamsRepository
|
||||
{
|
||||
public TeamsRepository(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public DataContext _context { get; }
|
||||
|
||||
public async Task<Team> GetEventTeam(int id)
|
||||
{
|
||||
var rTeam = await _context.Teams.FirstOrDefaultAsync(e=>e.EventId == id);
|
||||
|
||||
return rTeam;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Team>> GetTeams()
|
||||
{
|
||||
var rTeams = await _context.Teams.ToListAsync();
|
||||
|
||||
return rTeams;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace api.Models
|
|||
public class EventLocVisited
|
||||
{
|
||||
public int Id{get;set;} //id
|
||||
public Team Team{get;set;} //teamQRID
|
||||
public Team Team{get;set;} //team
|
||||
public EventLoc Location{get;set;} //location
|
||||
public DateTime timestamp{get;set;} //time
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ namespace api
|
|||
services.AddAutoMapper();
|
||||
services.AddScoped<IUsersRepository, UsersRepository>();
|
||||
services.AddScoped<IEventsRepository, EventsRepository>();
|
||||
services.AddScoped<ITeamsRepository, TeamsRepository>();
|
||||
services.AddScoped<IEventLocsRepository, EventLocsRepository>();
|
||||
services.AddScoped<IEventLocsVisitedRepository, EventLocsVisitedRepository>();
|
||||
|
||||
//define a connection string indicada em appsettings.json
|
||||
services.AddDbContext<DataContext>(x=>x.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue