From 93b54b306853c50852a7999b7383603bc138e294 Mon Sep 17 00:00:00 2001 From: Jelena Petrovic Date: Mon, 12 Dec 2022 23:14:50 +0100 Subject: Uklonjena mogucnost slanja poruka samo preko korisnickog imena i dodata provera da li postoji korisnik kome se salje poruka #83 --- Backend/Api/Api/Services/MessageService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Backend') diff --git a/Backend/Api/Api/Services/MessageService.cs b/Backend/Api/Api/Services/MessageService.cs index 9cc818b..71df70c 100644 --- a/Backend/Api/Api/Services/MessageService.cs +++ b/Backend/Api/Api/Services/MessageService.cs @@ -10,13 +10,15 @@ namespace Api.Services { private readonly IHttpContextAccessor _httpContext; private readonly IMongoCollection _messages; + private readonly IUserService _userService; private readonly IJwtService _jwtService; private IConfiguration _configuration; private readonly IHubContext _chatHub; - public MessageService(IDatabaseConnection settings, IMongoClient mongoClient, IJwtService jwtService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration,IHubContext chatHub) + public MessageService(IDatabaseConnection settings, IMongoClient mongoClient, IUserService userService, IJwtService jwtService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration,IHubContext chatHub) { var database = mongoClient.GetDatabase(settings.DatabaseName); _messages = database.GetCollection(settings.MessageCollectionname); + _userService = userService; _jwtService = jwtService; _httpContext = httpContextAccessor; _configuration = configuration; @@ -29,6 +31,9 @@ namespace Api.Services var senderId = _httpContext.HttpContext.User.FindFirstValue("id").ToString(); if (senderId == null) return null; + var receiverCheck =await _userService.GetSelfUserData(msg.receiverId); + if (receiverCheck == null) + return null; var tempMsg = new Message(); tempMsg._id = ""; tempMsg.receiverId = msg.receiverId; -- cgit v1.2.3