Commit c4e1e131 authored by cann-alberto's avatar cann-alberto
Browse files

Register controller added POSt request for users, personal profiles, devises and personae

parent 494d83a8
......@@ -6,26 +6,59 @@ using Microsoft.AspNetCore.Mvc;
namespace MMM_Server.Controllers;
[ApiController]
[Route("api/[controller]/profiles")]
[Route("api/[controller]")]
public class RegistrationController : ControllerBase
{
private readonly PersonalProfileService _personalProfilesService;
public RegistrationController(PersonalProfileService profilesService) =>
private readonly UserService _usersService;
private readonly PersonaService _personaeService;
private readonly DeviceService _devicesService;
public RegistrationController(PersonalProfileService profilesService, UserService usersService, PersonaService personaeService, DeviceService devicesService)
{
_personalProfilesService = profilesService;
_usersService = usersService;
_personaeService = personaeService;
_devicesService = devicesService;
}
[HttpGet]
public async Task<List<PersonalProfile>> Get() =>
await _personalProfilesService.GetAsync();
[HttpPost]
[HttpPost("profiles")]
public async Task<IActionResult> Post(PersonalProfile newPersonalProfile)
{
await _personalProfilesService.CreateAsync(newPersonalProfile);
return CreatedAtAction(nameof(Get), new { id = newPersonalProfile.Id }, newPersonalProfile);
}
[HttpPost ("users")]
public async Task<IActionResult> Post(User newUser)
{
await _usersService.CreateAsync(newUser);
return CreatedAtAction(nameof(Get), new { id = newUser.Id }, newUser);
}
[HttpPost("personae")]
public async Task<IActionResult> Post(Persona newPersona)
{
await _personaeService.CreateAsync(newPersona);
return CreatedAtAction(nameof(Get), new { id = newPersona.Id }, newPersona);
}
[HttpPost("devices")]
public async Task<IActionResult> Post(Device newDevice)
{
await _devicesService.CreateAsync(newDevice);
return CreatedAtAction(nameof(Get), new { id = newDevice.Id }, newDevice);
}
}
......
......@@ -9,6 +9,9 @@
public string ProfilesCollectionName { get; set; } = null!;
public string UsersCollectionName { get; set; } = null!;
public string PersonaeCollectionName { get; set; } = null!;
public string DevicesCollectionName { get; set; } = null!;
}
}
......@@ -4,8 +4,11 @@ using MMM_Server.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.Configure<MMMDatabaseSettings>(builder.Configuration.GetSection("ProfileDatabase"));
builder.Services.Configure<MMMDatabaseSettings>(builder.Configuration.GetSection("MMMDatabase"));
builder.Services.AddSingleton<PersonalProfileService>();
builder.Services.AddSingleton<UserService>();
builder.Services.AddSingleton<DeviceService>();
builder.Services.AddSingleton<PersonaService>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
......
using MMM_Server.Models;
using Microsoft.Extensions.Options;
namespace MMM_Server.Services;
public class DeviceService : MongoDbService<Device>
{
public DeviceService(IOptions<MMMDatabaseSettings> deviceDatabaseSettings)
: base(deviceDatabaseSettings, deviceDatabaseSettings.Value.DevicesCollectionName)
{
}
}
\ No newline at end of file
using MMM_Server.Models;
using Microsoft.Extensions.Options;
namespace MMM_Server.Services;
public class PersonaService : MongoDbService<Persona>
{
public PersonaService(IOptions<MMMDatabaseSettings> personaDatabaseSettings)
: base(personaDatabaseSettings, personaDatabaseSettings.Value.PersonaeCollectionName)
{
}
}
\ No newline at end of file
using MMM_Server.Models;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
namespace MMM_Server.Services;
......
using MMM_Server.Models;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
namespace MMM_Server.Services;
......
{
"ProfileDatabase": {
"MMMDatabase": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "MMM",
"ProfilesCollectionName": "PersonalProfiles",
......
{
"ProfileDatabase": {
"MMMDatabase": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "MMM",
"ProfilesCollectionName": "PersonalProfiles",
......
......@@ -2,7 +2,7 @@
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Get",
"RelativePath": "api/Registration/profiles",
"RelativePath": "api/Registration",
"HttpMethod": "GET",
"IsController": true,
"Order": 0,
......@@ -19,6 +19,38 @@
}
]
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Post",
"RelativePath": "api/Registration/devices",
"HttpMethod": "POST",
"IsController": true,
"Order": 0,
"Parameters": [
{
"Name": "newDevice",
"Type": "MMM_Server.Models.Device",
"IsRequired": true
}
],
"ReturnTypes": []
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Post",
"RelativePath": "api/Registration/personae",
"HttpMethod": "POST",
"IsController": true,
"Order": 0,
"Parameters": [
{
"Name": "newPersona",
"Type": "MMM_Server.Models.Persona",
"IsRequired": true
}
],
"ReturnTypes": []
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Post",
......@@ -34,5 +66,21 @@
}
],
"ReturnTypes": []
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Post",
"RelativePath": "api/Registration/users",
"HttpMethod": "POST",
"IsController": true,
"Order": 0,
"Parameters": [
{
"Name": "newUser",
"Type": "MMM_Server.Models.User",
"IsRequired": true
}
],
"ReturnTypes": []
}
]
\ No newline at end of file
......@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MMM-Server")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+75e98a7308933539e2f1211349c223a96e759e80")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+494d83a8a248169be02a140cbfc122a4168507cb")]
[assembly: System.Reflection.AssemblyProductAttribute("MMM-Server")]
[assembly: System.Reflection.AssemblyTitleAttribute("MMM-Server")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
......
0586c5593d3bb6f0e04431341b6db6648e2c89725d17c8715a947f802fd0bd6b
a5a45e3eb4a787a70139b3a2d5cee14db5d3c93c617d79b86591828da1cedfca
f3090db165d798249403588c92253ba1b37bb26d044967bdc45fa549cad6d92e
aa811ef7ce8ed7c4d62f9a804aa4cc250ac1e503e22063603dfe895f46dd5647
{"documents":{"C:\\Users\\lab2a\\Documents\\Visual Studio 2022\\Projects\\MPAI-MMM\\MMM-Server\\*":"https://raw.githubusercontent.com/cann-alberto/MPAI-MMM/75e98a7308933539e2f1211349c223a96e759e80/*"}}
\ No newline at end of file
{"documents":{"C:\\Users\\lab2a\\Documents\\Visual Studio 2022\\Projects\\MPAI-MMM\\MMM-Server\\*":"https://raw.githubusercontent.com/cann-alberto/MPAI-MMM/494d83a8a248169be02a140cbfc122a4168507cb/*"}}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment