Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ProjectBackup/C#/WebApplication/Controllers/CustomerController.cs
2022-09-04 12:45:01 +02:00

66 lines
2.0 KiB
C#

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using WebApplication.Logic;
using WebApplication.Modules;
namespace WebApplication.Controllers {
[Route("api/customers")]
public class CustomerController : ControllerBase {
private readonly ICustomerLogic _logic;
public CustomerController(ICustomerLogic logic) {
_logic = logic;
}
[HttpPost]
public ILogicResult<Customer> AddCustomer([FromBody] CustomerEditor editor) {
return _logic.AddCustomer(editor);
}
[HttpDelete]
[Route("{id}")]
public ILogicResult RemoveCustomer(string id) {
return _logic.RemoveCustomer(id, GetSessionKey());
}
[HttpPut]
[Route("{id}")]
public ILogicResult EditCustomer(string id, [FromBody] CustomerEditor editor) {
return _logic.EditCustomer(id, editor, GetSessionKey());
}
[HttpGet]
[Route("{id}")]
public ILogicResult<Customer> GetCustomer(string id) {
return _logic.GetCustomer(id, GetSessionKey());
}
[HttpGet]
public ILogicResult<IEnumerable<Customer>> GetCustomers() {
return _logic.GetCustomers();
}
[HttpPost]
[Route("register")]
public ILogicResult<Session> Register([FromBody] CustomerEditor editor) {
Customer customer = _logic.AddCustomer(editor).Data;
return _logic.CreateCustomerSession(customer.Guid);
}
[HttpGet]
[Route("{id}/logout")]
public ILogicResult Logout(string id) {
return _logic.DeleteCustomerSession(id, GetSessionKey());
}
[HttpPut]
[Route("login")]
public ILogicResult<Session> Login([FromBody] CustomerLogin login) {
return _logic.Login(login);
}
private string GetSessionKey() {
return HttpContext.Request.Headers["Authorization"];
}
}
}