Commit 1b8064fe authored by cann-alberto's avatar cann-alberto
Browse files

Added GET profiles

parent 26554026
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();
}
......@@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.29.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
......
namespace MMM_Server.Models
{
public class MMMDatabaseSettings
{
public string ConnectionString { get; set; } = null!;
public string DatabaseName { get; set; } = null!;
public string ProfilesCollectionName { get; set; } = null!;
}
}
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace MMM_Server.Models;
public class Profile
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public decimal Age { get; set; }
public string Nationality{ get; set; } = null!;
public string Email { get; set; } = null!;
}
using MMM_Server.Models;
using MMM_Server.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.Configure<MMMDatabaseSettings>(builder.Configuration.GetSection("ProfileDatabase"));
builder.Services.AddSingleton<ProfileService>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
......
using MMM_Server.Models;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
namespace MMM_Server.Services;
public class ProfileService
{
private readonly IMongoCollection<Profile> _profilesCollection;
public ProfileService(
IOptions<MMMDatabaseSettings> profileDatabaseSettings)
{
var mongoClient = new MongoClient(
profileDatabaseSettings.Value.ConnectionString);
var mongoDatabase = mongoClient.GetDatabase(
profileDatabaseSettings.Value.DatabaseName);
_profilesCollection = mongoDatabase.GetCollection<Profile>(
profileDatabaseSettings.Value.ProfilesCollectionName);
}
public async Task<List<Profile>> GetAsync() =>
await _profilesCollection.Find(_ => true).ToListAsync();
}
{
"ProfileDatabase": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "MMM",
"ProfilesCollectionName": "Profiles"
},
"Logging": {
"LogLevel": {
"Default": "Information",
......
......@@ -8,13 +8,46 @@
".NETCoreApp,Version=v8.0": {
"MMM-Server/1.0.0": {
"dependencies": {
"MongoDB.Driver": "2.29.0",
"Swashbuckle.AspNetCore": "6.4.0"
},
"runtime": {
"MMM-Server.dll": {}
}
},
"AWSSDK.Core/3.7.100.14": {
"runtime": {
"lib/netcoreapp3.1/AWSSDK.Core.dll": {
"assemblyVersion": "3.3.0.0",
"fileVersion": "3.7.100.14"
}
}
},
"AWSSDK.SecurityToken/3.7.100.14": {
"dependencies": {
"AWSSDK.Core": "3.7.100.14"
},
"runtime": {
"lib/netcoreapp3.1/AWSSDK.SecurityToken.dll": {
"assemblyVersion": "3.3.0.0",
"fileVersion": "3.7.100.14"
}
}
},
"DnsClient/1.6.1": {
"dependencies": {
"Microsoft.Win32.Registry": "5.0.0"
},
"runtime": {
"lib/net5.0/DnsClient.dll": {
"assemblyVersion": "1.6.1.0",
"fileVersion": "1.6.1.0"
}
}
},
"Microsoft.Extensions.ApiDescription.Server/6.0.5": {},
"Microsoft.Extensions.Logging.Abstractions/2.0.0": {},
"Microsoft.NETCore.Platforms/5.0.0": {},
"Microsoft.OpenApi/1.2.3": {
"runtime": {
"lib/netstandard2.0/Microsoft.OpenApi.dll": {
......@@ -23,6 +56,98 @@
}
}
},
"Microsoft.Win32.Registry/5.0.0": {
"dependencies": {
"System.Security.AccessControl": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"MongoDB.Bson/2.29.0": {
"dependencies": {
"System.Memory": "4.5.5",
"System.Runtime.CompilerServices.Unsafe": "5.0.0"
},
"runtime": {
"lib/netstandard2.1/MongoDB.Bson.dll": {
"assemblyVersion": "2.29.0.0",
"fileVersion": "2.29.0.0"
}
}
},
"MongoDB.Driver/2.29.0": {
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "2.0.0",
"MongoDB.Bson": "2.29.0",
"MongoDB.Driver.Core": "2.29.0",
"MongoDB.Libmongocrypt": "1.12.0"
},
"runtime": {
"lib/netstandard2.1/MongoDB.Driver.dll": {
"assemblyVersion": "2.29.0.0",
"fileVersion": "2.29.0.0"
}
}
},
"MongoDB.Driver.Core/2.29.0": {
"dependencies": {
"AWSSDK.SecurityToken": "3.7.100.14",
"DnsClient": "1.6.1",
"Microsoft.Extensions.Logging.Abstractions": "2.0.0",
"MongoDB.Bson": "2.29.0",
"MongoDB.Libmongocrypt": "1.12.0",
"SharpCompress": "0.30.1",
"Snappier": "1.0.0",
"System.Buffers": "4.5.1",
"ZstdSharp.Port": "0.7.3"
},
"runtime": {
"lib/netstandard2.1/MongoDB.Driver.Core.dll": {
"assemblyVersion": "2.29.0.0",
"fileVersion": "2.29.0.0"
}
}
},
"MongoDB.Libmongocrypt/1.12.0": {
"runtime": {
"lib/netstandard2.1/MongoDB.Libmongocrypt.dll": {
"assemblyVersion": "1.12.0.0",
"fileVersion": "1.12.0.0"
}
},
"runtimeTargets": {
"runtimes/linux/native/libmongocrypt.so": {
"rid": "linux",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/osx/native/libmongocrypt.dylib": {
"rid": "osx",
"assetType": "native",
"fileVersion": "0.0.0.0"
},
"runtimes/win/native/mongocrypt.dll": {
"rid": "win",
"assetType": "native",
"fileVersion": "0.0.0.0"
}
}
},
"SharpCompress/0.30.1": {
"runtime": {
"lib/net5.0/SharpCompress.dll": {
"assemblyVersion": "0.30.1.0",
"fileVersion": "0.30.1.0"
}
}
},
"Snappier/1.0.0": {
"runtime": {
"lib/net5.0/Snappier.dll": {
"assemblyVersion": "1.0.0.0",
"fileVersion": "1.0.0.0"
}
}
},
"Swashbuckle.AspNetCore/6.4.0": {
"dependencies": {
"Microsoft.Extensions.ApiDescription.Server": "6.0.5",
......@@ -60,6 +185,24 @@
"fileVersion": "6.4.0.0"
}
}
},
"System.Buffers/4.5.1": {},
"System.Memory/4.5.5": {},
"System.Runtime.CompilerServices.Unsafe/5.0.0": {},
"System.Security.AccessControl/5.0.0": {
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"System.Security.Principal.Windows/5.0.0": {},
"ZstdSharp.Port/0.7.3": {
"runtime": {
"lib/net7.0/ZstdSharp.dll": {
"assemblyVersion": "0.7.3.0",
"fileVersion": "0.7.3.0"
}
}
}
}
},
......@@ -69,6 +212,27 @@
"serviceable": false,
"sha512": ""
},
"AWSSDK.Core/3.7.100.14": {
"type": "package",
"serviceable": true,
"sha512": "sha512-gnEgxBlk4PFEfdPE8Lkf4+D16MZFYSaW7/o6Wwe5e035QWUkTJX0Dn4LfTCdV5QSEL/fOFxu+yCAm55eIIBgog==",
"path": "awssdk.core/3.7.100.14",
"hashPath": "awssdk.core.3.7.100.14.nupkg.sha512"
},
"AWSSDK.SecurityToken/3.7.100.14": {
"type": "package",
"serviceable": true,
"sha512": "sha512-dGCVuVo0CFUKWW85W8YENO+aREf8sCBDjvGbnNvxJuNW4Ss+brEU9ltHhq2KfZze2VUNK1/wygbPG1bmbpyXEw==",
"path": "awssdk.securitytoken/3.7.100.14",
"hashPath": "awssdk.securitytoken.3.7.100.14.nupkg.sha512"
},
"DnsClient/1.6.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-4H/f2uYJOZ+YObZjpY9ABrKZI+JNw3uizp6oMzTXwDw6F+2qIPhpRl/1t68O/6e98+vqNiYGu+lswmwdYUy3gg==",
"path": "dnsclient/1.6.1",
"hashPath": "dnsclient.1.6.1.nupkg.sha512"
},
"Microsoft.Extensions.ApiDescription.Server/6.0.5": {
"type": "package",
"serviceable": true,
......@@ -76,6 +240,20 @@
"path": "microsoft.extensions.apidescription.server/6.0.5",
"hashPath": "microsoft.extensions.apidescription.server.6.0.5.nupkg.sha512"
},
"Microsoft.Extensions.Logging.Abstractions/2.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6ZCllUYGFukkymSTx3Yr0G/ajRxoNJp7/FqSxSB4fGISST54ifBhgu4Nc0ItGi3i6DqwuNd8SUyObmiC++AO2Q==",
"path": "microsoft.extensions.logging.abstractions/2.0.0",
"hashPath": "microsoft.extensions.logging.abstractions.2.0.0.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-VyPlqzH2wavqquTcYpkIIAQ6WdenuKoFN0BdYBbCWsclXacSOHNQn66Gt4z5NBqEYW0FAPm5rlvki9ZiCij5xQ==",
"path": "microsoft.netcore.platforms/5.0.0",
"hashPath": "microsoft.netcore.platforms.5.0.0.nupkg.sha512"
},
"Microsoft.OpenApi/1.2.3": {
"type": "package",
"serviceable": true,
......@@ -83,6 +261,55 @@
"path": "microsoft.openapi/1.2.3",
"hashPath": "microsoft.openapi.1.2.3.nupkg.sha512"
},
"Microsoft.Win32.Registry/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-dDoKi0PnDz31yAyETfRntsLArTlVAVzUzCIvvEDsDsucrl33Dl8pIJG06ePTJTI3tGpeyHS9Cq7Foc/s4EeKcg==",
"path": "microsoft.win32.registry/5.0.0",
"hashPath": "microsoft.win32.registry.5.0.0.nupkg.sha512"
},
"MongoDB.Bson/2.29.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-wz8UtxdjnknHRJuMatTRr2QMlh7k9457BRfaDQxl+OiKV01vMzm1K0/jTvQJqORV5eba6HrCAzMJzj7nnt5cag==",
"path": "mongodb.bson/2.29.0",
"hashPath": "mongodb.bson.2.29.0.nupkg.sha512"
},
"MongoDB.Driver/2.29.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-1IfTnHX8G2SsXIHDz80OVSmcdL95vzzWXGGucR45k7+TUOcWVhiqYcc13ckRXl4NVxn4UTRrrKl+92xvjwWrRA==",
"path": "mongodb.driver/2.29.0",
"hashPath": "mongodb.driver.2.29.0.nupkg.sha512"
},
"MongoDB.Driver.Core/2.29.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-3M7gdmuLEay4Wc/q4zm/oA5KT4E62SsRBiq3prpT3tGEPkfstr3N3fYRbzYNu8TJgeyS0q5OPe4zI4yi6/GemQ==",
"path": "mongodb.driver.core/2.29.0",
"hashPath": "mongodb.driver.core.2.29.0.nupkg.sha512"
},
"MongoDB.Libmongocrypt/1.12.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-B1X51jrtNacKvxKoaqWeknYeJfQS5aWf6BmVLT5JZerz3AUXFzv8edPskJYqBc3kLy1J2PWzMqqsnyb9g8FtcA==",
"path": "mongodb.libmongocrypt/1.12.0",
"hashPath": "mongodb.libmongocrypt.1.12.0.nupkg.sha512"
},
"SharpCompress/0.30.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-XqD4TpfyYGa7QTPzaGlMVbcecKnXy4YmYLDWrU+JIj7IuRNl7DH2END+Ll7ekWIY8o3dAMWLFDE1xdhfIWD1nw==",
"path": "sharpcompress/0.30.1",
"hashPath": "sharpcompress.0.30.1.nupkg.sha512"
},
"Snappier/1.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-rFtK2KEI9hIe8gtx3a0YDXdHOpedIf9wYCEYtBEmtlyiWVX3XlCNV03JrmmAi/Cdfn7dxK+k0sjjcLv4fpHnqA==",
"path": "snappier/1.0.0",
"hashPath": "snappier.1.0.0.nupkg.sha512"
},
"Swashbuckle.AspNetCore/6.4.0": {
"type": "package",
"serviceable": true,
......@@ -110,6 +337,48 @@
"sha512": "sha512-1Hh3atb3pi8c+v7n4/3N80Jj8RvLOXgWxzix6w3OZhB7zBGRwsy7FWr4e3hwgPweSBpwfElqj4V4nkjYabH9nQ==",
"path": "swashbuckle.aspnetcore.swaggerui/6.4.0",
"hashPath": "swashbuckle.aspnetcore.swaggerui.6.4.0.nupkg.sha512"
},
"System.Buffers/4.5.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==",
"path": "system.buffers/4.5.1",
"hashPath": "system.buffers.4.5.1.nupkg.sha512"
},
"System.Memory/4.5.5": {
"type": "package",
"serviceable": true,
"sha512": "sha512-XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==",
"path": "system.memory/4.5.5",
"hashPath": "system.memory.4.5.5.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ZD9TMpsmYJLrxbbmdvhwt9YEgG5WntEnZ/d1eH8JBX9LBp+Ju8BSBhUGbZMNVHHomWo2KVImJhTDl2hIgw/6MA==",
"path": "system.runtime.compilerservices.unsafe/5.0.0",
"hashPath": "system.runtime.compilerservices.unsafe.5.0.0.nupkg.sha512"
},
"System.Security.AccessControl/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-dagJ1mHZO3Ani8GH0PHpPEe/oYO+rVdbQjvjJkBRNQkX4t0r1iaeGn8+/ybkSLEan3/slM0t59SVdHzuHf2jmw==",
"path": "system.security.accesscontrol/5.0.0",
"hashPath": "system.security.accesscontrol.5.0.0.nupkg.sha512"
},
"System.Security.Principal.Windows/5.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-t0MGLukB5WAVU9bO3MGzvlGnyJPgUlcwerXn1kzBRjwLKixT96XV0Uza41W49gVd8zEMFu9vQEFlv0IOrytICA==",
"path": "system.security.principal.windows/5.0.0",
"hashPath": "system.security.principal.windows.5.0.0.nupkg.sha512"
},
"ZstdSharp.Port/0.7.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-U9Ix4l4cl58Kzz1rJzj5hoVTjmbx1qGMwzAcbv1j/d3NzrFaESIurQyg+ow4mivCgkE3S413y+U9k4WdnEIkRA==",
"path": "zstdsharp.port/0.7.3",
"hashPath": "zstdsharp.port.0.7.3.nupkg.sha512"
}
}
}
\ 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