From 5c7498b3ec118db06c720f5f17262a2008652c25 Mon Sep 17 00:00:00 2001 From: ZMiguel Alves Date: Wed, 6 Mar 2019 19:17:36 +0000 Subject: [PATCH] small up --- api/Controllers/EventLocsController.cs | 61 ++++++++++++++++++ api/Controllers/EventLocsVisitedController.cs | 55 ++++++++++++++++ api/Controllers/TeamsController.cs | 8 +-- api/Data/EventLocsRepository.cs | 41 ++++++++++++ api/Data/EventLocsVisitedRepository.cs | 42 ++++++++++++ api/Data/IEventLocsRepository.cs | 16 +++++ api/Data/IEventLocsVisitedRepository.cs | 16 +++++ api/Data/ITeamsRepository.cs | 15 +++++ api/Data/TeamsReposiroty.cs | 34 ++++++++++ api/Models/EventLocVisited.cs | 2 +- api/Startup.cs | 3 + api/obj/Debug/netcoreapp2.1/api.assets.cache | Bin 133820 -> 133820 bytes 12 files changed, 288 insertions(+), 5 deletions(-) create mode 100644 api/Controllers/EventLocsController.cs create mode 100644 api/Controllers/EventLocsVisitedController.cs create mode 100644 api/Data/EventLocsRepository.cs create mode 100644 api/Data/EventLocsVisitedRepository.cs create mode 100644 api/Data/IEventLocsRepository.cs create mode 100644 api/Data/IEventLocsVisitedRepository.cs create mode 100644 api/Data/ITeamsRepository.cs create mode 100644 api/Data/TeamsReposiroty.cs diff --git a/api/Controllers/EventLocsController.cs b/api/Controllers/EventLocsController.cs new file mode 100644 index 00000000..57d5052c --- /dev/null +++ b/api/Controllers/EventLocsController.cs @@ -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 _roleManager; + private readonly UserManager _userManager; + public EventLocsController(DataContext context,IEventLocsRepository repo, IMapper mapper,RoleManager roleManager,UserManager UserManager) + { + this.context = context; + _mapper = mapper; + _roleManager = roleManager; + _userManager = UserManager; + _repo = repo; + } + + // GET api/EventLocs + // GET all EventLocs + [HttpGet] + public async Task GetEventLocs() + { + var Teams = await _repo.GetEventLocs(); + return Ok(Teams); + } + + // GET api/EventLocs/[id] + [HttpGet("{id}")] + public async Task GetEventLoc(int id) + { + var Teams = await _repo.GetEventLoc(id); + return Ok(Teams); + } + + // GET api/EventLocs/[id] + [HttpGet("e/{id}")] + public async Task GetEventLocEvent(int id) + { + var Teams = await _repo.GetEventLocEvent(id); + return Ok(Teams); + } + } +} diff --git a/api/Controllers/EventLocsVisitedController.cs b/api/Controllers/EventLocsVisitedController.cs new file mode 100644 index 00000000..4ddff028 --- /dev/null +++ b/api/Controllers/EventLocsVisitedController.cs @@ -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 _roleManager; + private readonly UserManager _userManager; + public EventLocsVisitedController(DataContext context,IEventLocsVisitedRepository repo, IMapper mapper,RoleManager roleManager,UserManager UserManager) + { + this.context = context; + _mapper = mapper; + _roleManager = roleManager; + _userManager = UserManager; + _repo = repo; + } + + // GET api/EventLocsVisited + // GET all EventLocsVisited + [HttpGet] + public async Task 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 GetEventLocsVisitedTeam(int id) + { + var Locs = await _repo.GetEventLocsVisitedTeam(id); + return Ok(Locs); + } + + } +} diff --git a/api/Controllers/TeamsController.cs b/api/Controllers/TeamsController.cs index e3851d0b..9a59f3aa 100644 --- a/api/Controllers/TeamsController.cs +++ b/api/Controllers/TeamsController.cs @@ -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 _roleManager; private readonly UserManager _userManager; - public TeamsController(DataContext context,IUsersRepository repo, IMapper mapper,RoleManager roleManager,UserManager UserManager) + public TeamsController(DataContext context,ITeamsRepository repo, IMapper mapper,RoleManager roleManager,UserManager UserManager) { this.context = context; _mapper = mapper; @@ -38,7 +38,7 @@ namespace api.Controllers [HttpGet] public async Task 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 GetTeamsEvent(int id) { - var Teams = await context.Teams.FirstOrDefaultAsync(e=>e.EventId == id); + var Teams = await _repo.GetEventTeam(id); return Ok(Teams); } } diff --git a/api/Data/EventLocsRepository.cs b/api/Data/EventLocsRepository.cs new file mode 100644 index 00000000..629cc7d3 --- /dev/null +++ b/api/Data/EventLocsRepository.cs @@ -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 GetEventLoc(int id) + { + var rEventLocs = await _context.EventLocs.FirstOrDefaultAsync(e=>e.Id == id); + + return rEventLocs; + } + + public async Task GetEventLocEvent(int id) + { + var rEventLocs = await _context.EventLocs.FirstOrDefaultAsync(e=>e.EventId == id); + + return rEventLocs; + } + + public async Task> GetEventLocs() + { + var rEventLocs = await _context.EventLocs.ToListAsync(); + + return rEventLocs; + } + + } +} \ No newline at end of file diff --git a/api/Data/EventLocsVisitedRepository.cs b/api/Data/EventLocsVisitedRepository.cs new file mode 100644 index 00000000..29fe0198 --- /dev/null +++ b/api/Data/EventLocsVisitedRepository.cs @@ -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> GetEventLocsVisited() + { + var rEventLocsVisitedList = await _context.EventLocsVisited.ToListAsync(); + + return rEventLocsVisitedList; + } + + public Task> GetEventLocsVisitedTeam(int id) + { + List allLocs = _context.EventLocsVisited.ToList(); + allLocs.ForEach(i=>Console.Write("{0}\t", i)); + Console.WriteLine("teste"); + List rList = new List(); + for(var i=0;i> GetEventLocs(); + Task GetEventLoc(int id); + Task GetEventLocEvent(int id); + + + } +} \ No newline at end of file diff --git a/api/Data/IEventLocsVisitedRepository.cs b/api/Data/IEventLocsVisitedRepository.cs new file mode 100644 index 00000000..68d9e611 --- /dev/null +++ b/api/Data/IEventLocsVisitedRepository.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using api.Models; + +namespace api.Data +{ + public interface IEventLocsVisitedRepository + { + + Task> GetEventLocsVisited(); + Task> GetEventLocsVisitedTeam(int id); + + + } +} \ No newline at end of file diff --git a/api/Data/ITeamsRepository.cs b/api/Data/ITeamsRepository.cs new file mode 100644 index 00000000..9a9c03fd --- /dev/null +++ b/api/Data/ITeamsRepository.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using api.Models; + +namespace api.Data +{ + public interface ITeamsRepository + { + + Task> GetTeams(); + Task GetEventTeam(int id); + + + } +} \ No newline at end of file diff --git a/api/Data/TeamsReposiroty.cs b/api/Data/TeamsReposiroty.cs new file mode 100644 index 00000000..d42d91b5 --- /dev/null +++ b/api/Data/TeamsReposiroty.cs @@ -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 GetEventTeam(int id) + { + var rTeam = await _context.Teams.FirstOrDefaultAsync(e=>e.EventId == id); + + return rTeam; + } + + public async Task> GetTeams() + { + var rTeams = await _context.Teams.ToListAsync(); + + return rTeams; + } + + } +} \ No newline at end of file diff --git a/api/Models/EventLocVisited.cs b/api/Models/EventLocVisited.cs index 3cb2b045..28fb9870 100755 --- a/api/Models/EventLocVisited.cs +++ b/api/Models/EventLocVisited.cs @@ -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 } diff --git a/api/Startup.cs b/api/Startup.cs index 913485cf..9098d755 100755 --- a/api/Startup.cs +++ b/api/Startup.cs @@ -46,6 +46,9 @@ namespace api services.AddAutoMapper(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); //define a connection string indicada em appsettings.json services.AddDbContext(x=>x.UseMySql(Configuration.GetConnectionString("DefaultConnection"))); diff --git a/api/obj/Debug/netcoreapp2.1/api.assets.cache b/api/obj/Debug/netcoreapp2.1/api.assets.cache index 5e8a8b3185bcbdacd1934bcab5c58d0f3ec13a5e..e445080c4a5d97600d8c6fc8c69d2dc856b3c451 100755 GIT binary patch delta 71 zcmV-N0J#6Wl?c3*2rW=cM?nGr000~;PWI~S0f}RK*r#b2Tx|*xG&gSbJ5NEK3+%rF dk^?l_0RRM-@JInWlMpKefoz3r0kv!bPzsH)7=i!* delta 71 zcmV-N0J#6Wl?c3*2rW=cM?nGr004EO3y`Zq5y}_NkoM1$<|x@vN!etcoE2jI|C7b% dX7V)J0RRM-@JInWlMpKefoz3r0kv!bPzpAJ9hm?C