From 1ccc5d6ad366fb361ebc6674b9c1a4c40c96fe25 Mon Sep 17 00:00:00 2001 From: ZMiguel Alves Date: Thu, 14 Mar 2019 16:51:48 +0000 Subject: [PATCH 1/3] Auto stash before merge of "zmiguel" and "origin/master" --- api/Data/DataContext.cs | 2 ++ api/Models/Chromos.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 api/Models/Chromos.cs diff --git a/api/Data/DataContext.cs b/api/Data/DataContext.cs index e6ac56e1..4e095ae8 100755 --- a/api/Data/DataContext.cs +++ b/api/Data/DataContext.cs @@ -21,6 +21,8 @@ namespace api.Data public DbSet EventLocs {get;set;} public DbSet EventLocsVisited {get;set;} + + public DbSet Chromos {get;set;} public DbSetLogs{get;set;} diff --git a/api/Models/Chromos.cs b/api/Models/Chromos.cs new file mode 100644 index 00000000..8f5fd8e5 --- /dev/null +++ b/api/Models/Chromos.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace api.Models + +{ + public class Cromos + { + public int Id{get;set;} //id + public String QRCode{get;set;} //QR + public String Nome{get;set;} //Nome + public String DescPub{get;set;} //descrição geral nao visto + public String DescVis{get;set;} //descrição visto + + } +} \ No newline at end of file From 3bedefafb7d6be831fb957844525511fdb0c68ef Mon Sep 17 00:00:00 2001 From: ZMiguel Alves Date: Thu, 14 Mar 2019 16:52:49 +0000 Subject: [PATCH 2/3] cromos dbset --- api/Data/DataContext.cs | 2 +- api/Models/{Chromos.cs => Cromos.cs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename api/Models/{Chromos.cs => Cromos.cs} (100%) diff --git a/api/Data/DataContext.cs b/api/Data/DataContext.cs index 4e095ae8..17668f27 100755 --- a/api/Data/DataContext.cs +++ b/api/Data/DataContext.cs @@ -22,7 +22,7 @@ namespace api.Data public DbSet EventLocsVisited {get;set;} - public DbSet Chromos {get;set;} + public DbSet Chromos {get;set;} public DbSetLogs{get;set;} diff --git a/api/Models/Chromos.cs b/api/Models/Cromos.cs similarity index 100% rename from api/Models/Chromos.cs rename to api/Models/Cromos.cs From 89d8bb558500f824b8dc7264fcc3e6bae7516c6b Mon Sep 17 00:00:00 2001 From: ZMiguel Alves Date: Thu, 14 Mar 2019 18:10:59 +0000 Subject: [PATCH 3/3] Cromos e QR Scan --- api/Controllers/CromosController.cs | 55 +++++++++++++++++++++++ api/Controllers/ScanController.cs | 68 +++++++++++++++++++++++++++++ api/Data/DataContext.cs | 2 +- api/Dtos/QRToScan.cs | 16 +++++++ api/Dtos/ScanReturn.cs | 16 +++++++ api/Dtos/UserForListDto.cs | 3 -- api/Models/Cromos.cs | 12 ++--- api/Models/User.cs | 2 + 8 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 api/Controllers/CromosController.cs create mode 100644 api/Controllers/ScanController.cs create mode 100644 api/Dtos/QRToScan.cs create mode 100644 api/Dtos/ScanReturn.cs diff --git a/api/Controllers/CromosController.cs b/api/Controllers/CromosController.cs new file mode 100644 index 00000000..29211657 --- /dev/null +++ b/api/Controllers/CromosController.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 CromosController : ControllerBase + { + private readonly DataContext context; + private readonly IMapper _mapper; + public CromosController(DataContext context, IMapper mapper) + { + this.context = context; + _mapper = mapper; + } + + // GET api/cromos/QR + // GET cromos do user QR + [HttpGet] + public async Task> GetCromos(string QR) + { + var usr = await context.Users.Include(a=>a.cromos).FirstOrDefaultAsync(u=>u.QRcode == QR); + var allCromos = await context.Cromos.ToListAsync(); + + List rList = new List(); + + allCromos.ForEach(delegate(Cromos c){ + usr.cromos.ForEach(delegate(int cid){ + if(c.Id == cid){ //user tem o cromo + Cromos toAdd = new Cromos{Id = c.Id,Nome=c.Nome,DescMostrar=c.DescUnlocked,QRCode=c.QRCode,img=c.img}; + rList.Add(toAdd); + }else{ //user NAO tem o cromo + Cromos toAdd = new Cromos{Id = c.Id,Nome=c.Nome,DescMostrar=c.DescLocked,QRCode=c.QRCode,img=c.img}; + rList.Add(toAdd); + } + }); + }); + return rList; + } + + } +} diff --git a/api/Controllers/ScanController.cs b/api/Controllers/ScanController.cs new file mode 100644 index 00000000..6f486c70 --- /dev/null +++ b/api/Controllers/ScanController.cs @@ -0,0 +1,68 @@ +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 ScanController : ControllerBase + { + private readonly DataContext context; + private readonly IMapper _mapper; + public ScanController(DataContext context, IMapper mapper) + { + this.context = context; + _mapper = mapper; + } + + // PSOT api/scan + // POST scan de QR code + [HttpPost] + public async Task doScan(QRToScan ScanData) + { + User usr = await context.Users.Include(a=>a.cromos).FirstOrDefaultAsync(b=>b.QRcode == ScanData.UserQR); + var allUsers = await context.Users.ToListAsync(); + var allCromos = await context.Cromos.ToListAsync(); + + var userAProcurar = await context.Users.FirstOrDefaultAsync(c=>c.QRcode == ScanData.ScanQR); + + ScanReturn toReturn = new ScanReturn(); + + if(userAProcurar != null){ + _mapper.Map(toReturn.user,userAProcurar); + toReturn.tipo=1; + return toReturn; + }else{ + allCromos.ForEach(delegate(Cromos c){ + if(c.QRCode == ScanData.ScanQR){ + toReturn.tipo=0; + usr.cromos.Add(c.Id); + context.Users.Update(usr); + context.SaveChanges(); + + toReturn.resp = "Cromo Adicionado!"; + } + }); + + return toReturn; + } + + toReturn.tipo = -1; + + return toReturn; + } + + } +} diff --git a/api/Data/DataContext.cs b/api/Data/DataContext.cs index 17668f27..fbe73eb6 100755 --- a/api/Data/DataContext.cs +++ b/api/Data/DataContext.cs @@ -22,7 +22,7 @@ namespace api.Data public DbSet EventLocsVisited {get;set;} - public DbSet Chromos {get;set;} + public DbSet Cromos {get;set;} public DbSetLogs{get;set;} diff --git a/api/Dtos/QRToScan.cs b/api/Dtos/QRToScan.cs new file mode 100644 index 00000000..e9381fa0 --- /dev/null +++ b/api/Dtos/QRToScan.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using api.Models; + +namespace api.Dtos +{ + public class QRToScan + { + [Required] + public string UserQR{get;set;} //QR do User que ler + + [Required] + public string ScanQR{get;set;} //QR a analisar + } +} \ No newline at end of file diff --git a/api/Dtos/ScanReturn.cs b/api/Dtos/ScanReturn.cs new file mode 100644 index 00000000..cba5acef --- /dev/null +++ b/api/Dtos/ScanReturn.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using api.Models; + +namespace api.Dtos +{ + public class ScanReturn + { + public int tipo{get;set;} //tipo de retorno, 0 = cromo // 1 = user + + public UserForListDto user{get;set;} //user + + public string resp{get;set;} //reposta + } +} \ No newline at end of file diff --git a/api/Dtos/UserForListDto.cs b/api/Dtos/UserForListDto.cs index 538f90f4..91d0d304 100755 --- a/api/Dtos/UserForListDto.cs +++ b/api/Dtos/UserForListDto.cs @@ -18,8 +18,5 @@ namespace api.Dtos public string ProfileIcon {get;set;} public string About{get;set;} public string PhotoUrl{get;set;} - - - } } \ No newline at end of file diff --git a/api/Models/Cromos.cs b/api/Models/Cromos.cs index 8f5fd8e5..6848e8c9 100644 --- a/api/Models/Cromos.cs +++ b/api/Models/Cromos.cs @@ -6,11 +6,13 @@ namespace api.Models { public class Cromos { - public int Id{get;set;} //id - public String QRCode{get;set;} //QR - public String Nome{get;set;} //Nome - public String DescPub{get;set;} //descrição geral nao visto - public String DescVis{get;set;} //descrição visto + public int Id{get;set;} //id + public String QRCode{get;set;} //QR + public String Nome{get;set;} //Nome + public String DescLocked{get;set;} //descrição nao visto + public String DescUnlocked{get;set;}//descrição visto + public String DescMostrar{get;set;} //descrição a mostrar + public Photo img {get;set;} //imagem } } \ No newline at end of file diff --git a/api/Models/User.cs b/api/Models/User.cs index 56acc712..b798efb9 100755 --- a/api/Models/User.cs +++ b/api/Models/User.cs @@ -20,6 +20,8 @@ namespace api.Models [ForeignKey("teamID")] public Team team{get;set;} + + public List cromos {get;set;} } } \ No newline at end of file