From 24fdc69a44d0376c1e002a17a76a637cb52c795a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A8=81=E5=8B=9D=20=E5=BC=B5?= Date: Wed, 14 Feb 2024 22:08:27 +0800 Subject: [PATCH] T --- .../Parking_spaces_total_tableController.cs | 5 +- .../Controllers/Yuntech_camController.cs | 140 ++++++++++++++++++ .../Yuntech_cam_total_tableController.cs | 140 ++++++++++++++++++ WebApi_data_value/Models/Yuntech_cam.cs | 9 ++ .../Models/Yuntech_cam_total_table.cs | 9 ++ WebApi_data_value/Services/SqlContext.cs | 8 + WebApi_data_value/WebApi_data_value.csproj | 2 +- 7 files changed, 310 insertions(+), 3 deletions(-) create mode 100644 WebApi_data_value/Controllers/Yuntech_camController.cs create mode 100644 WebApi_data_value/Controllers/Yuntech_cam_total_tableController.cs create mode 100644 WebApi_data_value/Models/Yuntech_cam.cs create mode 100644 WebApi_data_value/Models/Yuntech_cam_total_table.cs diff --git a/WebApi_data_value/Controllers/Parking_spaces_total_tableController.cs b/WebApi_data_value/Controllers/Parking_spaces_total_tableController.cs index ec2fd59..3bc11e4 100644 --- a/WebApi_data_value/Controllers/Parking_spaces_total_tableController.cs +++ b/WebApi_data_value/Controllers/Parking_spaces_total_tableController.cs @@ -23,7 +23,7 @@ namespace WebApi_data_value.Controllers { _context = context; } - + [AllowAnonymous] #region 獲取停車場所有資料 // GET: api/Parking_spaces_total_table /// @@ -39,7 +39,8 @@ namespace WebApi_data_value.Controllers return await _context.parking_spaces_total_table.ToListAsync(); } #endregion - + + [AllowAnonymous] #region 獲取停車場單一資料 // GET: api/Parking_spaces_total_table/5 /// diff --git a/WebApi_data_value/Controllers/Yuntech_camController.cs b/WebApi_data_value/Controllers/Yuntech_camController.cs new file mode 100644 index 0000000..d2db25d --- /dev/null +++ b/WebApi_data_value/Controllers/Yuntech_camController.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using WebApi_data_value.Models; +using WebApi_data_value.Authorization; +using WebApi_data_value.Services; + +namespace WebApi_data_value.Controllers +{ + [Route("api/[controller]")] + [ApiController] + [Authorize] + public class Yuntech_camController : ControllerBase + { + private readonly SqlContext _context; + + public Yuntech_camController(SqlContext context) + { + _context = context; + } + + // GET: api/Yuntech_cam + [HttpGet] + public async Task>> Getyuntech_cam() + { + if (_context.yuntech_cam == null) + { + return NotFound(); + } + return await _context.yuntech_cam.ToListAsync(); + } + + // GET: api/Yuntech_cam/5 + [HttpGet("{id}")] + public async Task> GetYuntech_cam(string id) + { + if (_context.yuntech_cam == null) + { + return NotFound(); + } + var yuntech_cam = await _context.yuntech_cam.FindAsync(id); + + if (yuntech_cam == null) + { + return NotFound(); + } + + return yuntech_cam; + } + + // PUT: api/Yuntech_cam/5 + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPut("{id}")] + public async Task PutYuntech_cam(string id, Yuntech_cam yuntech_cam) + { + if (id != yuntech_cam.ip) + { + return BadRequest(); + } + + _context.Entry(yuntech_cam).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!Yuntech_camExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Yuntech_cam + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPost] + public async Task> PostYuntech_cam(Yuntech_cam yuntech_cam) + { + if (_context.yuntech_cam == null) + { + return Problem("Entity set 'SqlContext.yuntech_cam' is null."); + } + _context.yuntech_cam.Add(yuntech_cam); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (Yuntech_camExists(yuntech_cam.ip)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtAction("GetYuntech_cam", new { id = yuntech_cam.ip }, yuntech_cam); + } + + // DELETE: api/Yuntech_cam/5 + [HttpDelete("{id}")] + public async Task DeleteYuntech_cam(string id) + { + if (_context.yuntech_cam == null) + { + return NotFound(); + } + var yuntech_cam = await _context.yuntech_cam.FindAsync(id); + if (yuntech_cam == null) + { + return NotFound(); + } + + _context.yuntech_cam.Remove(yuntech_cam); + await _context.SaveChangesAsync(); + + return NoContent(); + } + + private bool Yuntech_camExists(string id) + { + return (_context.yuntech_cam?.Any(e => e.ip == id)).GetValueOrDefault(); + } + } +} diff --git a/WebApi_data_value/Controllers/Yuntech_cam_total_tableController.cs b/WebApi_data_value/Controllers/Yuntech_cam_total_tableController.cs new file mode 100644 index 0000000..68a5ba6 --- /dev/null +++ b/WebApi_data_value/Controllers/Yuntech_cam_total_tableController.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using WebApi_data_value.Models; +using WebApi_data_value.Authorization; +using WebApi_data_value.Services; + +namespace WebApi_data_value.Controllers +{ + [Route("api/[controller]")] + [ApiController] + [Authorize] + public class Yuntech_cam_total_tableController : ControllerBase + { + private readonly SqlContext _context; + + public Yuntech_cam_total_tableController(SqlContext context) + { + _context = context; + } + + // GET: api/Yuntech_cam_total_table + [HttpGet] + public async Task>> Getyuntech_cam_total_table() + { + if (_context.yuntech_cam_total_table == null) + { + return NotFound(); + } + return await _context.yuntech_cam_total_table.ToListAsync(); + } + + // GET: api/Yuntech_cam_total_table/5 + [HttpGet("{id}")] + public async Task> GetYuntech_cam_total_table(string id) + { + if (_context.yuntech_cam_total_table == null) + { + return NotFound(); + } + var yuntech_cam_total_table = await _context.yuntech_cam_total_table.FindAsync(id); + + if (yuntech_cam_total_table == null) + { + return NotFound(); + } + + return yuntech_cam_total_table; + } + + // PUT: api/Yuntech_cam_total_table/5 + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPut("{id}")] + public async Task PutYuntech_cam_total_table(string id, Yuntech_cam_total_table yuntech_cam_total_table) + { + if (id != yuntech_cam_total_table.location_name) + { + return BadRequest(); + } + + _context.Entry(yuntech_cam_total_table).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!Yuntech_cam_total_tableExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Yuntech_cam_total_table + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPost] + public async Task> PostYuntech_cam_total_table(Yuntech_cam_total_table yuntech_cam_total_table) + { + if (_context.yuntech_cam_total_table == null) + { + return Problem("Entity set 'SqlContext.yuntech_cam_total_table' is null."); + } + _context.yuntech_cam_total_table.Add(yuntech_cam_total_table); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (Yuntech_cam_total_tableExists(yuntech_cam_total_table.location_name)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtAction("GetYuntech_cam_total_table", new { id = yuntech_cam_total_table.location_name }, yuntech_cam_total_table); + } + + // DELETE: api/Yuntech_cam_total_table/5 + [HttpDelete("{id}")] + public async Task DeleteYuntech_cam_total_table(string id) + { + if (_context.yuntech_cam_total_table == null) + { + return NotFound(); + } + var yuntech_cam_total_table = await _context.yuntech_cam_total_table.FindAsync(id); + if (yuntech_cam_total_table == null) + { + return NotFound(); + } + + _context.yuntech_cam_total_table.Remove(yuntech_cam_total_table); + await _context.SaveChangesAsync(); + + return NoContent(); + } + + private bool Yuntech_cam_total_tableExists(string id) + { + return (_context.yuntech_cam_total_table?.Any(e => e.location_name == id)).GetValueOrDefault(); + } + } +} diff --git a/WebApi_data_value/Models/Yuntech_cam.cs b/WebApi_data_value/Models/Yuntech_cam.cs new file mode 100644 index 0000000..675c413 --- /dev/null +++ b/WebApi_data_value/Models/Yuntech_cam.cs @@ -0,0 +1,9 @@ +namespace WebApi_data_value.Models +{ + public class Yuntech_cam + { + public string? location_name { get; set; } + public string? ip { get; set; } + public string? url { get; set; } + } +} diff --git a/WebApi_data_value/Models/Yuntech_cam_total_table.cs b/WebApi_data_value/Models/Yuntech_cam_total_table.cs new file mode 100644 index 0000000..4da5310 --- /dev/null +++ b/WebApi_data_value/Models/Yuntech_cam_total_table.cs @@ -0,0 +1,9 @@ +namespace WebApi_data_value.Models +{ + public class Yuntech_cam_total_table + { + public string? location_name { get; set; } + public string? longitude { get; set; } + public string? latitude { get; set; } + } +} diff --git a/WebApi_data_value/Services/SqlContext.cs b/WebApi_data_value/Services/SqlContext.cs index 02367f4..14ec38c 100644 --- a/WebApi_data_value/Services/SqlContext.cs +++ b/WebApi_data_value/Services/SqlContext.cs @@ -49,6 +49,11 @@ namespace WebApi_data_value.Services //大門口 public DbSet yuntech_in_car_table { get; set; } = null!; + //雲科校內相機 + public DbSet yuntech_cam_total_table { get; set; } = null!; + public DbSet yuntech_cam { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder builder) { @@ -75,6 +80,9 @@ namespace WebApi_data_value.Services builder.Entity().HasKey(o => new { o.algorithm_serial_num }); //Primary Key builder.Entity().HasKey(o => new { o.in_time }); //Primary Key + + builder.Entity().HasKey(o => new { o.location_name }); //Primary Key + builder.Entity().HasKey(o => new { o.ip }); //Primary Key } diff --git a/WebApi_data_value/WebApi_data_value.csproj b/WebApi_data_value/WebApi_data_value.csproj index 7a29b7d..a685b69 100644 --- a/WebApi_data_value/WebApi_data_value.csproj +++ b/WebApi_data_value/WebApi_data_value.csproj @@ -24,7 +24,7 @@ - + all