Commit 245a8502 authored by cann-alberto's avatar cann-alberto
Browse files

Registration package : users, persona and device models

parent bf2df72b
using MMM_Server.Models;
using MMM_Server.Services;
using Microsoft.AspNetCore.Mvc;
namespace MMM_Server.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ProfilesController: ControllerBase
{
private readonly ProfileService _profilesService;
public ProfilesController(ProfileService profilesService) =>
_profilesService = profilesService;
[HttpGet]
public async Task<List<Profile>> Get() =>
await _profilesService.GetAsync();
}
using MMM_Server.Models; using MMM_Server.Models;
using MMM_Server.Services; using MMM_Server.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MMM_Server.Models.Utils;
namespace MMM_Server.Controllers; namespace MMM_Server.Controllers;
...@@ -9,68 +10,22 @@ namespace MMM_Server.Controllers; ...@@ -9,68 +10,22 @@ namespace MMM_Server.Controllers;
public class RegistrationController : ControllerBase public class RegistrationController : ControllerBase
{ {
private readonly ProfileService _profilesService; private readonly PersonalProfileService _personalProfilesService;
public RegistrationController(ProfileService profilesService) => public RegistrationController(PersonalProfileService profilesService) =>
_profilesService = profilesService; _personalProfilesService = profilesService;
[HttpGet] [HttpGet]
public async Task<List<Profile>> Get() => public async Task<List<PersonalProfile>> Get() =>
await _profilesService.GetAsync(); await _personalProfilesService.GetAsync();
[HttpGet("{id:length(24)}")]
public async Task<ActionResult<Profile>> Get(string id)
{
var book = await _profilesService.GetAsync(id);
if (book is null)
{
return NotFound();
}
return book;
}
[HttpPost] [HttpPost]
public async Task<IActionResult> Post(Profile newProfile) public async Task<IActionResult> Post(PersonalProfile newPersonalProfile)
{ {
await _profilesService.CreateAsync(newProfile); await _personalProfilesService.CreateAsync(newPersonalProfile);
return CreatedAtAction(nameof(Get), new { id = newProfile.Id }, newProfile); return CreatedAtAction(nameof(Get), new { id = newPersonalProfile.Id }, newPersonalProfile);
} }
[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Profile updatedProfile)
{
var profile = await _profilesService.GetAsync(id);
if (profile is null)
{
return NotFound();
}
updatedProfile.Id = profile.Id;
await _profilesService.UpdateAsync(id, updatedProfile);
return NoContent();
}
[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
var profile = await _profilesService.GetAsync(id);
if (profile is null)
{
return NotFound();
}
await _profilesService.RemoveAsync(id);
return NoContent();
}
} }
......
namespace MMM_Server.Controllers
{
public class RightController
{
}
}
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace MMM_Server.Models
{
public class Device
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
}
}
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace MMM_Server.Models
{
public class Persona
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string Model { get; set; } = null!;
}
}
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace MMM_Server.Models
{
public class PersonalProfile
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string Header { get; set; } = null!;
public string MInstanceID { get; set; } = null!;
public string HumanID { get; set; } = null!;
public string PersonalProfileID { get; set; } = null!;
public PersonalProfileData PersonalProfileData { get; set; } = null!;
public string DescrMetadata { get; set; } = null!;
}
}
...@@ -4,12 +4,8 @@ using MongoDB.Bson.Serialization.Attributes; ...@@ -4,12 +4,8 @@ using MongoDB.Bson.Serialization.Attributes;
namespace MMM_Server.Models; namespace MMM_Server.Models;
public class Profile public class PersonalProfileData
{ {
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string FirstName { get; set; } = null!; public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!; public string LastName { get; set; } = null!;
......
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace MMM_Server.Models
{
public class User
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
}
}
namespace MMM_Server.Models.Utils
{
public class RegistrationInfo
{
public PersonalProfileData newProfile { get; set; } = null!;
public User newUser { get; set; } = null!;
public Device newdevice { get; set; } = null!;
public Persona newPersona { get; set; } = null!;
}
}
...@@ -5,7 +5,7 @@ var builder = WebApplication.CreateBuilder(args); ...@@ -5,7 +5,7 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.Configure<MMMDatabaseSettings>(builder.Configuration.GetSection("ProfileDatabase")); builder.Services.Configure<MMMDatabaseSettings>(builder.Configuration.GetSection("ProfileDatabase"));
builder.Services.AddSingleton<ProfileService>(); builder.Services.AddSingleton<PersonalProfileService>();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
......
...@@ -4,10 +4,10 @@ using MongoDB.Driver; ...@@ -4,10 +4,10 @@ using MongoDB.Driver;
namespace MMM_Server.Services; namespace MMM_Server.Services;
public class ProfileService public class PersonalProfileService
{ {
private readonly IMongoCollection<Profile> _profilesCollection; private readonly IMongoCollection<PersonalProfile> _profilesCollection;
public ProfileService( public PersonalProfileService(
IOptions<MMMDatabaseSettings> profileDatabaseSettings) IOptions<MMMDatabaseSettings> profileDatabaseSettings)
{ {
var mongoClient = new MongoClient( var mongoClient = new MongoClient(
...@@ -16,23 +16,27 @@ public class ProfileService ...@@ -16,23 +16,27 @@ public class ProfileService
var mongoDatabase = mongoClient.GetDatabase( var mongoDatabase = mongoClient.GetDatabase(
profileDatabaseSettings.Value.DatabaseName); profileDatabaseSettings.Value.DatabaseName);
_profilesCollection = mongoDatabase.GetCollection<Profile>( _profilesCollection = mongoDatabase.GetCollection<PersonalProfile>(
profileDatabaseSettings.Value.ProfilesCollectionName); profileDatabaseSettings.Value.ProfilesCollectionName);
} }
public async Task<List<Profile>> GetAsync() => public async Task<List<PersonalProfile>> GetAsync() =>
await _profilesCollection.Find(_ => true).ToListAsync(); await _profilesCollection.Find(_ => true).ToListAsync();
public async Task<Profile?> GetAsync(string id) => public async Task CreateAsync(PersonalProfile newProfile) =>
await _profilesCollection.InsertOneAsync(newProfile);
/*
public async Task<PersonalProfileData?> GetAsync(string id) =>
await _profilesCollection.Find(x => x.Id == id).FirstOrDefaultAsync(); await _profilesCollection.Find(x => x.Id == id).FirstOrDefaultAsync();
public async Task CreateAsync(Profile newBook) =>
await _profilesCollection.InsertOneAsync(newBook);
public async Task UpdateAsync(string id, Profile updatedBook) => public async Task UpdateAsync(string id, PersonalProfileData updatedProfile) =>
await _profilesCollection.ReplaceOneAsync(x => x.Id == id, updatedBook); await _profilesCollection.ReplaceOneAsync(x => x.Id == id, updatedProfile);
public async Task RemoveAsync(string id) => public async Task RemoveAsync(string id) =>
await _profilesCollection.DeleteOneAsync(x => x.Id == id); await _profilesCollection.DeleteOneAsync(x => x.Id == id);
*/
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"ProfileDatabase": { "ProfileDatabase": {
"ConnectionString": "mongodb://localhost:27017", "ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "MMM", "DatabaseName": "MMM",
"ProfilesCollectionName": "Profiles" "ProfilesCollectionName": "PersonalProfiles"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"ProfileDatabase": { "ProfileDatabase": {
"ConnectionString": "mongodb://localhost:27017", "ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "MMM", "DatabaseName": "MMM",
"ProfilesCollectionName": "Profiles" "ProfilesCollectionName": "PersonalProfiles"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
......
[ [
{
"ContainingType": "MMM_Server.Controllers.ProfilesController",
"Method": "Get",
"RelativePath": "api/Profiles",
"HttpMethod": "GET",
"IsController": true,
"Order": 0,
"Parameters": [],
"ReturnTypes": [
{
"Type": "System.Collections.Generic.List\u00601[[MMM_Server.Models.Profile, MMM-Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]",
"MediaTypes": [
"text/plain",
"application/json",
"text/json"
],
"StatusCode": 200
}
]
},
{ {
"ContainingType": "MMM_Server.Controllers.RegistrationController", "ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Get", "Method": "Get",
...@@ -29,7 +9,7 @@ ...@@ -29,7 +9,7 @@
"Parameters": [], "Parameters": [],
"ReturnTypes": [ "ReturnTypes": [
{ {
"Type": "System.Collections.Generic.List\u00601[[MMM_Server.Models.Profile, MMM-Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]", "Type": "System.Collections.Generic.List\u00601[[MMM_Server.Models.PersonalProfile, MMM-Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]",
"MediaTypes": [ "MediaTypes": [
"text/plain", "text/plain",
"application/json", "application/json",
...@@ -48,71 +28,8 @@ ...@@ -48,71 +28,8 @@
"Order": 0, "Order": 0,
"Parameters": [ "Parameters": [
{ {
"Name": "newProfile", "Name": "newPersonalProfile",
"Type": "MMM_Server.Models.Profile", "Type": "MMM_Server.Models.PersonalProfile",
"IsRequired": true
}
],
"ReturnTypes": []
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Get",
"RelativePath": "api/Registration/profiles/{id}",
"HttpMethod": "GET",
"IsController": true,
"Order": 0,
"Parameters": [
{
"Name": "id",
"Type": "System.String",
"IsRequired": true
}
],
"ReturnTypes": [
{
"Type": "MMM_Server.Models.Profile",
"MediaTypes": [
"text/plain",
"application/json",
"text/json"
],
"StatusCode": 200
}
]
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Update",
"RelativePath": "api/Registration/profiles/{id}",
"HttpMethod": "PUT",
"IsController": true,
"Order": 0,
"Parameters": [
{
"Name": "id",
"Type": "System.String",
"IsRequired": true
},
{
"Name": "updatedProfile",
"Type": "MMM_Server.Models.Profile",
"IsRequired": true
}
],
"ReturnTypes": []
},
{
"ContainingType": "MMM_Server.Controllers.RegistrationController",
"Method": "Delete",
"RelativePath": "api/Registration/profiles/{id}",
"HttpMethod": "DELETE",
"IsController": true,
"Order": 0,
"Parameters": [
{
"Name": "id",
"Type": "System.String",
"IsRequired": true "IsRequired": true
} }
], ],
......
...@@ -14,7 +14,7 @@ using System.Reflection; ...@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MMM-Server")] [assembly: System.Reflection.AssemblyCompanyAttribute("MMM-Server")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1b8064fe62f388c9a5eddd312865292d6affd7a4")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+74d009de2e51803bbbf37fda6d6b43394606cea7")]
[assembly: System.Reflection.AssemblyProductAttribute("MMM-Server")] [assembly: System.Reflection.AssemblyProductAttribute("MMM-Server")]
[assembly: System.Reflection.AssemblyTitleAttribute("MMM-Server")] [assembly: System.Reflection.AssemblyTitleAttribute("MMM-Server")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
......
45771de9efe7fc0804dee5922051ba0d2b4be37e04a63b840888622c0ed49947 70d2b9da71a0ca46e131854fd08d84da8f4ee332574b497bc72ddafa24b1af89
94880d7acaa4b9506f48db68bb33584a67f669b37061b9f3b5f92c272b82b128 1e31261913ed492625f0b335bd9521ed7663f28f00dd74aba93b1c1d5fd09bd3
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