forked from e-zoob/phone-book-boost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
190 additions
and
182 deletions.
There are no files selected for viewing
71 changes: 0 additions & 71 deletions
71
srv_qry_mongo/ContactsController/Controllers/ContactsController.cs
This file was deleted.
Oops, something went wrong.
File renamed without changes.
30 changes: 15 additions & 15 deletions
30
...tactsController/ContactsController.csproj → ...v_qry_mongo.Api/ContactsController.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" /> | ||
<PackageReference Include="MongoDB.Driver" Version="2.22.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" /> | ||
<PackageReference Include="MongoDB.Driver" Version="2.22.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using MongoDB.Bson; | ||
using MongoDB.Bson.Serialization.Attributes; | ||
|
||
namespace srv_qry_mongo.Api.Controllers | ||
{ | ||
public class Contact | ||
{ | ||
[BsonId] | ||
[BsonRepresentation(BsonType.ObjectId)] | ||
public string? Id { get; set; } | ||
|
||
[BsonElement("0")] | ||
public ContactInfo? Info { get; set; } | ||
} | ||
|
||
public class ContactInfo | ||
{ | ||
[BsonElement("name")] | ||
public string? Name { get; set; } | ||
|
||
[BsonElement("phone")] | ||
public string? Phone { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
srv_qry_mongo/srv_qry_mongo.Api/Controllers/ContactsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Options; | ||
|
||
|
||
namespace srv_qry_mongo.Api.Controllers | ||
{ | ||
[Route("api/contacts")] | ||
[ApiController] | ||
public class ContactsController : ControllerBase | ||
{ | ||
private readonly MongoDBService _mongoDBService; | ||
public ContactsController(MongoDBService mongoDBService) | ||
{ | ||
_mongoDBService = mongoDBService; | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult GetMongoContacts() | ||
{ | ||
var contacts_data = _mongoDBService.GetAllContacts(); | ||
return Ok(contacts_data); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
srv_qry_mongo/srv_qry_mongo.Api/Controllers/MongoDBService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using MongoDB.Driver; | ||
using Microsoft.Extensions.Options; | ||
|
||
|
||
namespace srv_qry_mongo.Api.Controllers | ||
{ | ||
public class MongoDBService | ||
{ | ||
private readonly IMongoCollection<Contact> _collection; | ||
|
||
public MongoDBService(IOptions<MongoDBConnect> configuration) | ||
{ | ||
string connectionString = configuration.Value.MongoDBConnection; | ||
|
||
var client = new MongoClient(connectionString); | ||
|
||
var database = client.GetDatabase("meteor"); | ||
_collection = database.GetCollection<Contact>("contacts"); | ||
} | ||
|
||
public IEnumerable<Contact> GetAllContacts() | ||
{ | ||
List<Contact> data = _collection.Find(_ => true).ToList(); | ||
return data; | ||
} | ||
|
||
} | ||
} |
62 changes: 31 additions & 31 deletions
62
srv_qry_mongo/ContactsController/Program.cs → srv_qry_mongo/srv_qry_mongo.Api/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
builder.Services.Configure<MongoDBConnect>(builder.Configuration.GetSection("ConnectionStrings")); | ||
builder.Services.AddSingleton<MongoDBConnect>(); | ||
builder.Services.AddScoped<ContactsController.Controllers.MongoDBService>(); | ||
|
||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
builder.Services.Configure<MongoDBConnect>(builder.Configuration.GetSection("ConnectionStrings")); | ||
builder.Services.AddSingleton<MongoDBConnect>(); | ||
builder.Services.AddScoped<srv_qry_mongo.Api.Controllers.MongoDBService>(); | ||
|
||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
82 changes: 41 additions & 41 deletions
82
...Controller/Properties/launchSettings.json → ..._mongo.Api/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:13421", | ||
"sslPort": 44388 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5009", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7254;http://localhost:5009", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:13421", | ||
"sslPort": 44388 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5009", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7254;http://localhost:5009", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
22 changes: 11 additions & 11 deletions
22
...tsController/appsettings.Development.json → ...ry_mongo.Api/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"MongoDBConnection": "mongodb://localhost:27017" | ||
} | ||
} | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"MongoDBConnection": "mongodb://localhost:27017" | ||
} | ||
} |
24 changes: 12 additions & 12 deletions
24
...mongo/ContactsController/appsettings.json → ..._mongo/srv_qry_mongo.Api/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"MongoDBConnection": "mongodb://localhost:27017" | ||
} | ||
} | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"MongoDBConnection": "mongodb://localhost:27017" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters