From b963eb842fce019a3ce139b798ce429dbade693c Mon Sep 17 00:00:00 2001 From: MH Hung Date: Thu, 31 Jul 2025 16:02:53 +0800 Subject: [PATCH] feat : add login api method --- Controllers/Fubon.cs | 32 ++++++++++++++++++++++++ Controllers/WeatherForecastController.cs | 32 ------------------------ Models/LoginRequest.cs | 7 ++++++ Program.cs | 5 ++++ WeatherForecast.cs | 12 --------- 5 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 Controllers/Fubon.cs delete mode 100644 Controllers/WeatherForecastController.cs create mode 100644 Models/LoginRequest.cs delete mode 100644 WeatherForecast.cs diff --git a/Controllers/Fubon.cs b/Controllers/Fubon.cs new file mode 100644 index 0000000..32f8814 --- /dev/null +++ b/Controllers/Fubon.cs @@ -0,0 +1,32 @@ +using fubon_api.Models; +using FubonNeo.Sdk; +using Microsoft.AspNetCore.Mvc; + +namespace fubon_api.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class FubonSdkController : ControllerBase +{ + private readonly FubonSDK _sdk; + private readonly ILogger _logger; + + public FubonSdkController(ILogger logger, FubonSDK sdk) + { + _sdk = sdk; + _logger = logger; + } + + [HttpPost("Login")] + public LoginResponse Login([FromBody] LoginRequest request) + { + if (request == null) + { + throw new ArgumentException("Invalid login request."); + } + + var result = _sdk.Login(request.Id, request.Password,"Your Cert Path","Your Cert Password"); + + return result; + } +} \ No newline at end of file diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs deleted file mode 100644 index 9f5c759..0000000 --- a/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace fubon_api.Controllers; - -[ApiController] -[Route("[controller]")] -public class WeatherForecastController : ControllerBase -{ - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } -} \ No newline at end of file diff --git a/Models/LoginRequest.cs b/Models/LoginRequest.cs new file mode 100644 index 0000000..f6cbbbb --- /dev/null +++ b/Models/LoginRequest.cs @@ -0,0 +1,7 @@ +namespace fubon_api.Models; + +public class LoginRequest +{ + public string Id {get;set;} + public string Password {get;set;} +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 8264bac..62f751c 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,6 @@ +using fubon_api.Controllers; +using FubonNeo.Sdk; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,6 +10,8 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddSingleton(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/WeatherForecast.cs b/WeatherForecast.cs deleted file mode 100644 index 1379a97..0000000 --- a/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace fubon_api; - -public class WeatherForecast -{ - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } -} \ No newline at end of file