Skip to content
Snippets Groups Projects
Commit 9fd19484 authored by esantangelo's avatar esantangelo
Browse files

add mongodb settings and message entity

parent 171024d9
No related branches found
No related tags found
1 merge request!3Feature/send message
......@@ -14,6 +14,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Tsi1.Api.Infrastructure;
......@@ -21,6 +22,7 @@ using Tsi1.BusinessLayer.Helpers;
using Tsi1.BusinessLayer.Interfaces;
using Tsi1.BusinessLayer.Services;
using Tsi1.DataLayer;
using Tsi1.DataLayer.MongoDbConfiguration;
namespace Tsi1.Api
{
......@@ -39,6 +41,13 @@ namespace Tsi1.Api
services.AddControllers();
services.AddDbContext<Tsi1Context>(x => x.UseNpgsql(Configuration.GetConnectionString("PostgreSql")));
services.Configure<ITsi1DatabaseSettings>(
Configuration.GetSection(nameof(Tsi1DatabaseSettings)));
services.AddSingleton<Tsi1DatabaseSettings>(sp =>
sp.GetRequiredService<IOptions<Tsi1DatabaseSettings>>().Value);
services.AddScoped<IUserService, UserService>();
services.AddScoped<IUserTypeService, UserTypeService>();
services.AddScoped<ICourseService, CourseService>();
......
......@@ -2,6 +2,11 @@
"ConnectionStrings": {
"PostgreSql": "Host=localhost;Database=tsi1;Username=postgres;Password=111111"
},
"Tsi1DatabaseSettings": {
"Tsi1CollectionName": "Messages",
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "Tsi1Db"
},
"jwtTokenConfig": {
"secret": "1234567890123456789",
"issuer": "https://localhost:44363",
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class MessageCreateDto
{
public int SenderId { get; set; }
public int ReceiverId { get; set; }
public string Content { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class MessagePreviewDto
{
public string Id { get; set; }
public int SenderId { get; set; }
public int ReceiverId { get; set; }
public string Content { get; set; }
public string Date { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Tsi1.BusinessLayer.Helpers;
namespace Tsi1.BusinessLayer.Interfaces
{
public interface IMessageService
{
Task<ServiceResult<List<ForumPreviewDto>>> GetForums(int courseId);
Task<ServiceResult<Forum>> Create(ForumCreateDto newForum);
Task<ServiceResult<Forum>> Delete(int forumId);
Task<ServiceResult<>>
List<Message> Get();
Message Get(string id);
Message Create(Message message);
void Update(string id, Message messageIn);
void Remove(Message messageIn);
void Remove(string id);
}
}
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.DataLayer.Entities
{
public class Message
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public int SenderId { get; set; }
public int ReceiverId { get; set; }
public string Content { get; set; }
public string Date { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.DataLayer.MongoDbConfiguration
{
public class Tsi1DatabaseSettings : ITsi1DatabaseSettings
{
public string Tsi1CollectionName { get; set; }
public string ConnectionString { get; set; }
public string DatabaseName { get; set; }
}
public interface ITsi1DatabaseSettings
{
public string Tsi1CollectionName { get; set; }
public string ConnectionString { get; set; }
public string DatabaseName { get; set; }
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment