新增校內停車場名單API

This commit is contained in:
leo890808 2024-05-21 15:02:04 +08:00
parent 8fdacf40eb
commit 5d8d45fcd5
4 changed files with 227 additions and 2 deletions

View File

@ -24,6 +24,11 @@ namespace WebApi_data_value.Controllers
_context = context; _context = context;
} }
#region
/// <summary>
/// 獲取校園總車輛數值
/// </summary>
/// <returns></returns>
// GET: api/Yuntech_parking // GET: api/Yuntech_parking
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<Yuntech_parking>>> Getyuntech_parking() public async Task<ActionResult<IEnumerable<Yuntech_parking>>> Getyuntech_parking()
@ -34,7 +39,14 @@ namespace WebApi_data_value.Controllers
} }
return await _context.yuntech_parking.ToListAsync(); return await _context.yuntech_parking.ToListAsync();
} }
#endregion
#region
/// <summary>
/// 獲取單獨總車輛數據
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// GET: api/Yuntech_parking/5 // GET: api/Yuntech_parking/5
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<ActionResult<Yuntech_parking>> GetYuntech_parking(string id) public async Task<ActionResult<Yuntech_parking>> GetYuntech_parking(string id)
@ -52,7 +64,15 @@ namespace WebApi_data_value.Controllers
return yuntech_parking; return yuntech_parking;
} }
#endregion
#region
/// <summary>
/// 編輯剩餘車位數據
/// </summary>
/// <param name="id"></param>
/// <param name="yuntech_parking"></param>
/// <returns></returns>
// PUT: api/Yuntech_parking/5 // PUT: api/Yuntech_parking/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")] [HttpPut("{id}")]
@ -83,7 +103,14 @@ namespace WebApi_data_value.Controllers
return NoContent(); return NoContent();
} }
#endregion
#region
/// <summary>
/// 新增數據
/// </summary>
/// <param name="yuntech_parking"></param>
/// <returns></returns>
// POST: api/Yuntech_parking // POST: api/Yuntech_parking
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost] [HttpPost]
@ -112,7 +139,14 @@ namespace WebApi_data_value.Controllers
return CreatedAtAction("GetYuntech_parking", new { id = yuntech_parking.all_num }, yuntech_parking); return CreatedAtAction("GetYuntech_parking", new { id = yuntech_parking.all_num }, yuntech_parking);
} }
#endregion
#region
/// <summary>
/// 刪除數據
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// DELETE: api/Yuntech_parking/5 // DELETE: api/Yuntech_parking/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<IActionResult> DeleteYuntech_parking(string id) public async Task<IActionResult> DeleteYuntech_parking(string id)
@ -132,7 +166,7 @@ namespace WebApi_data_value.Controllers
return NoContent(); return NoContent();
} }
#endregion
private bool Yuntech_parkingExists(string id) private bool Yuntech_parkingExists(string id)
{ {
return (_context.yuntech_parking?.Any(e => e.all_num == id)).GetValueOrDefault(); return (_context.yuntech_parking?.Any(e => e.all_num == id)).GetValueOrDefault();

View File

@ -0,0 +1,176 @@
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 Parking_space_WebAPI.Services;
using WebApi_data_value.Models;
using Parking_space_WebAPI.Authorization;
namespace WebApi_data_value.Controllers
{
[Route("api/[controller]")]
[ApiController]
//[Authorize]
[ApiExplorerSettings(GroupName = "校園大內網")]
public class Yuntech_parking_user_listController : ControllerBase
{
private readonly SqlContext _context;
public Yuntech_parking_user_listController(SqlContext context)
{
_context = context;
}
#region 使
/// <summary>
/// 獲取校內停車使用者名單
/// </summary>
/// <returns></returns>
// GET: api/Yuntech_parking_user_list
[HttpGet]
public async Task<ActionResult<IEnumerable<Yuntech_parking_user_list>>> Getyuntech_parking_user_list()
{
if (_context.yuntech_parking_user_list == null)
{
return NotFound();
}
return await _context.yuntech_parking_user_list.ToListAsync();
}
#endregion
#region 使
/// <summary>
/// 根據車牌號碼獲取使用者資訊
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// GET: api/Yuntech_parking_user_list/5
[HttpGet("{id}")]
public async Task<ActionResult<Yuntech_parking_user_list>> GetYuntech_parking_user_list(string id)
{
if (_context.yuntech_parking_user_list == null)
{
return NotFound();
}
var yuntech_parking_user_list = await _context.yuntech_parking_user_list.FindAsync(id);
if (yuntech_parking_user_list == null)
{
return NotFound();
}
return yuntech_parking_user_list;
}
#endregion
#region 使
/// <summary>
/// 編輯校內停車場使用者名單資料
/// </summary>
/// <param name="id"></param>
/// <param name="yuntech_parking_user_list"></param>
/// <returns></returns>
// PUT: api/Yuntech_parking_user_list/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutYuntech_parking_user_list(string id, Yuntech_parking_user_list yuntech_parking_user_list)
{
if (id != yuntech_parking_user_list.user_license_plate_number)
{
return BadRequest();
}
_context.Entry(yuntech_parking_user_list).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!Yuntech_parking_user_listExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
#endregion
#region 使
/// <summary>
/// 新增校內停車場使用者名單
/// </summary>
/// <param name="yuntech_parking_user_list"></param>
/// <returns></returns>
// POST: api/Yuntech_parking_user_list
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Yuntech_parking_user_list>> PostYuntech_parking_user_list(Yuntech_parking_user_list yuntech_parking_user_list)
{
if (_context.yuntech_parking_user_list == null)
{
return Problem("Entity set 'SqlContext.yuntech_parking_user_list' is null.");
}
_context.yuntech_parking_user_list.Add(yuntech_parking_user_list);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (Yuntech_parking_user_listExists(yuntech_parking_user_list.user_license_plate_number))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetYuntech_parking_user_list", new { id = yuntech_parking_user_list.user_license_plate_number }, yuntech_parking_user_list);
}
#endregion
#region 使
/// <summary>
/// 刪除校內停車場使用者名單資料
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// DELETE: api/Yuntech_parking_user_list/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteYuntech_parking_user_list(string id)
{
if (_context.yuntech_parking_user_list == null)
{
return NotFound();
}
var yuntech_parking_user_list = await _context.yuntech_parking_user_list.FindAsync(id);
if (yuntech_parking_user_list == null)
{
return NotFound();
}
_context.yuntech_parking_user_list.Remove(yuntech_parking_user_list);
await _context.SaveChangesAsync();
return NoContent();
}
#endregion
private bool Yuntech_parking_user_listExists(string id)
{
return (_context.yuntech_parking_user_list?.Any(e => e.user_license_plate_number == id)).GetValueOrDefault();
}
}
}

View File

@ -0,0 +1,10 @@
namespace WebApi_data_value.Models
{
public class Yuntech_parking_user_list
{
public string? user_name { get; set; } = null;
public string? user_license_plate_number { get; set; }=null;
public string? user_state_check { get; set; } = null;
}
}

View File

@ -47,7 +47,7 @@ namespace Parking_space_WebAPI.Services
// 演算法 // 演算法
public DbSet<Parking_space_algorithm> parking_space_algorithm { get; set; } = null!; public DbSet<Parking_space_algorithm> parking_space_algorithm { get; set; } = null!;
//大門口 //進入車輛
public DbSet<Yuntech_in_car_table> yuntech_in_car_table { get; set; } = null!; public DbSet<Yuntech_in_car_table> yuntech_in_car_table { get; set; } = null!;
//雲科校內相機 //雲科校內相機
@ -55,6 +55,9 @@ namespace Parking_space_WebAPI.Services
public DbSet<Yuntech_cam> yuntech_cam { get; set; } = null!; public DbSet<Yuntech_cam> yuntech_cam { get; set; } = null!;
public DbSet<Yuntech_parking> yuntech_parking { get; set; } = null!; public DbSet<Yuntech_parking> yuntech_parking { get; set; } = null!;
// 雲科登記車輛名單
public DbSet<Yuntech_parking_user_list> yuntech_parking_user_list { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {
@ -86,6 +89,8 @@ namespace Parking_space_WebAPI.Services
builder.Entity<Yuntech_cam>().HasKey(o => new { o.ip }); //Primary Key builder.Entity<Yuntech_cam>().HasKey(o => new { o.ip }); //Primary Key
builder.Entity<Yuntech_parking>().HasKey(o => new { o.all_num }); //Primary Key builder.Entity<Yuntech_parking>().HasKey(o => new { o.all_num }); //Primary Key
builder.Entity<Yuntech_parking_user_list>().HasKey(o => new { o.user_license_plate_number });//Primary Key
} }