diff --git a/server/src/CPATapi.Server/CPATapi.Server.csproj b/server/src/CPATapi.Server/CPATapi.Server.csproj index 81ddb06..380696f 100644 --- a/server/src/CPATapi.Server/CPATapi.Server.csproj +++ b/server/src/CPATapi.Server/CPATapi.Server.csproj @@ -2,11 +2,12 @@ net10.0 + enable - - + + diff --git a/server/src/CPATapi.Server/Controllers/AvailabilityController.cs b/server/src/CPATapi.Server/Controllers/AvailabilityController.cs index c876800..d32ae0f 100644 --- a/server/src/CPATapi.Server/Controllers/AvailabilityController.cs +++ b/server/src/CPATapi.Server/Controllers/AvailabilityController.cs @@ -1,46 +1,39 @@ -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Dapper; using Microsoft.Data.SqlClient; -using Microsoft.Extensions.Configuration; namespace CPATapi.Server.Controllers { [Route("[controller]")] [ApiController] - public class AvailabilityController : ControllerBase + public class AvailabilityController(IConfiguration config) : ControllerBase { - private readonly IConfiguration _config; - public AvailabilityController(IConfiguration config) => _config = config; - [HttpGet, Route("users")] public async Task> GetUsers() { - await using var con = new SqlConnection(_config["Db:ConnectionStringZc"]); + await using var con = new SqlConnection(config["Db:ConnectionStringZc"]); await con.OpenAsync(); - return await con.QueryAsync(@" -SELECT DISTINCT MA_USER_NAME -FROM dbo.MA_DATEN -WHERE MA_USER_NAME IS NOT NULL AND MA_USER_AKTIV = 1 -ORDER BY MA_USER_NAME"); + return await con.QueryAsync(""" + SELECT DISTINCT MA_USER_NAME + FROM dbo.MA_DATEN + WHERE MA_USER_NAME IS NOT NULL AND MA_USER_AKTIV = 1 + ORDER BY MA_USER_NAME + """); } [HttpGet, Route("{user}")] public async Task GetAvailability(string user) { - await using var con = new SqlConnection(_config["Db:ConnectionStringZc"]); + await using var con = new SqlConnection(config["Db:ConnectionStringZc"]); await con.OpenAsync(); - var stampCount = (await con.QueryAsync(@" -SELECT * -FROM dbo.BU -INNER JOIN dbo.MA_DATEN on MA_NR = BU_MA_NR -WHERE - MA_USER_NAME = @user AND - BU_BU >= @date AND BU_BU < @tomorrow", new { user, date = DateTime.Now.Date, tomorrow = DateTime.Now.AddDays(1).Date })).Count(); + var stampCount = (await con.QueryAsync(""" + SELECT * + FROM dbo.BU + INNER JOIN dbo.MA_DATEN on MA_NR = BU_MA_NR + WHERE + MA_USER_NAME = @user AND + BU_BU >= @date AND BU_BU < @tomorrow + """, new { user, date = DateTime.Now.Date, tomorrow = DateTime.Now.AddDays(1).Date })).Count(); return new { user, loggedIn = stampCount % 2 != 0 }; } } diff --git a/server/src/CPATapi.Server/Controllers/CallerIdController.cs b/server/src/CPATapi.Server/Controllers/CallerIdController.cs index e8eb430..24ad04e 100644 --- a/server/src/CPATapi.Server/Controllers/CallerIdController.cs +++ b/server/src/CPATapi.Server/Controllers/CallerIdController.cs @@ -1,20 +1,14 @@ -using System.Threading.Tasks; using CPATapi.Server.Models; using Dapper; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.SqlClient; -using Microsoft.Extensions.Configuration; namespace CPATapi.Server.Controllers { [Route("[controller]")] [ApiController] - public class CallerIdController : ControllerBase + public class CallerIdController(IConfiguration config) : ControllerBase { - private readonly IConfiguration _config; - public CallerIdController(IConfiguration config) => _config = config; - - [HttpGet, Route("{number}")] public async Task CallerIdAsync([FromRoute] string number) { @@ -24,18 +18,19 @@ namespace CPATapi.Server.Controllers number = "%" + minMatch; } - await using var con = new SqlConnection(_config["Db:ConnectionString"]); + await using var con = new SqlConnection(config["Db:ConnectionString"]); await con.OpenAsync(); - var result = await con.QueryFirstOrDefaultAsync(@" -SELECT -TD_ID, -TD_NAME, -TD_NUMBER, -TD_NUMBER_TAPI, -TD_MEDIUM -FROM dbo.CP_TAPI_DIRECTORY -WHERE TD_NUMBER_TAPI LIKE @number", new {number}); + var result = await con.QueryFirstOrDefaultAsync(""" + SELECT + TD_ID, + TD_NAME, + TD_NUMBER, + TD_NUMBER_TAPI, + TD_MEDIUM + FROM dbo.CP_TAPI_DIRECTORY + WHERE TD_NUMBER_TAPI LIKE @number + """, new {number}); return result; } } diff --git a/server/src/CPATapi.Server/Controllers/ContactController.cs b/server/src/CPATapi.Server/Controllers/ContactController.cs index 5c4c111..79012f3 100644 --- a/server/src/CPATapi.Server/Controllers/ContactController.cs +++ b/server/src/CPATapi.Server/Controllers/ContactController.cs @@ -1,42 +1,32 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using CPATapi.Server.Models; using Dapper; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.SqlClient; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace CPATapi.Server.Controllers { [ApiController] [Route("[controller]")] - public class ContactController : ControllerBase + public class ContactController(ILogger logger, IConfiguration config) : ControllerBase { - private readonly ILogger _logger; - private readonly IConfiguration _config; - - public ContactController(ILogger logger, IConfiguration config) - { - _logger = logger; - _config = config; - } + private readonly ILogger _logger = logger; [HttpGet] public async Task> GetAsync() { - await using var con = new SqlConnection(_config["Db:ConnectionString"]); + await using var con = new SqlConnection(config["Db:ConnectionString"]); await con.OpenAsync(); - var contacts = await con.QueryAsync(@" -SELECT -TD_ID, -TD_NAME, -TD_NUMBER, -TD_NUMBER_TAPI, -TD_MEDIUM -FROM dbo.CP_TAPI_DIRECTORY"); + var contacts = await con.QueryAsync(""" + SELECT + TD_ID, + TD_NAME, + TD_NUMBER, + TD_NUMBER_TAPI, + TD_MEDIUM + FROM dbo.CP_TAPI_DIRECTORY + """); return contacts; } } diff --git a/server/src/CPATapi.Server/Controllers/SearchController.cs b/server/src/CPATapi.Server/Controllers/SearchController.cs index 4526197..9dcd629 100644 --- a/server/src/CPATapi.Server/Controllers/SearchController.cs +++ b/server/src/CPATapi.Server/Controllers/SearchController.cs @@ -1,23 +1,16 @@ -using System.Collections.Generic; -using System.Linq; using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; using CPATapi.Server.Models; using Dapper; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.SqlClient; -using Microsoft.Extensions.Configuration; namespace CPATapi.Server.Controllers { [Route("[controller]")] [ApiController] - public class SearchController : ControllerBase + public class SearchController(IConfiguration config) : ControllerBase { - private readonly IConfiguration _config; - public SearchController(IConfiguration config) => _config = config; - [HttpGet] public async Task> SearchAsync([FromQuery] string query) { @@ -33,17 +26,18 @@ namespace CPATapi.Server.Controllers return new List(); } - await using var con = new SqlConnection(_config["Db:ConnectionString"]); + await using var con = new SqlConnection(config["Db:ConnectionString"]); await con.OpenAsync(); - var sql = new StringBuilder(@" -SELECT TOP 10 -TD_ID, -TD_NAME, -TD_NUMBER, -TD_NUMBER_TAPI, -TD_MEDIUM -FROM dbo.CP_TAPI_DIRECTORY -WHERE "); + var sql = new StringBuilder(""" + SELECT TOP 10 + TD_ID, + TD_NAME, + TD_NUMBER, + TD_NUMBER_TAPI, + TD_MEDIUM + FROM dbo.CP_TAPI_DIRECTORY + WHERE + """); var first = true; var dp = new DynamicParameters(); for (var i = 1; i <= args.Length; i++) diff --git a/server/src/CPATapi.Server/Program.cs b/server/src/CPATapi.Server/Program.cs index bbc9dc4..ceb09d2 100644 --- a/server/src/CPATapi.Server/Program.cs +++ b/server/src/CPATapi.Server/Program.cs @@ -1,26 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; +var builder = WebApplication.CreateBuilder(args); -namespace CPATapi.Server +builder.Services.AddControllers(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseDeveloperExceptionPage(); } + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/server/src/CPATapi.Server/Startup.cs b/server/src/CPATapi.Server/Startup.cs deleted file mode 100644 index 3d9d506..0000000 --- a/server/src/CPATapi.Server/Startup.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace CPATapi.Server -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services - .AddControllers(); - //.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - //app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } -}