feat : add login api method
This commit is contained in:
32
Controllers/Fubon.cs
Normal file
32
Controllers/Fubon.cs
Normal file
@@ -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<FubonSdkController> _logger;
|
||||
|
||||
public FubonSdkController(ILogger<FubonSdkController> 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;
|
||||
}
|
||||
}
|
@@ -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<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> 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();
|
||||
}
|
||||
}
|
7
Models/LoginRequest.cs
Normal file
7
Models/LoginRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace fubon_api.Models;
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
public string Id {get;set;}
|
||||
public string Password {get;set;}
|
||||
}
|
@@ -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<FubonSDK>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@@ -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; }
|
||||
}
|
Reference in New Issue
Block a user