aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api
diff options
context:
space:
mode:
authorJelena Petrovic <jelenapetrovic.7119@gmail.com>2022-12-12 23:14:50 +0100
committerJelena Petrovic <jelenapetrovic.7119@gmail.com>2022-12-12 23:14:50 +0100
commit93b54b306853c50852a7999b7383603bc138e294 (patch)
tree9e1c76c2ba20ae2bafcb69867f343c8dba52a6a2 /Backend/Api
parent835b5a865bc9ad713ce9b861ca1c05b36842900e (diff)
Uklonjena mogucnost slanja poruka samo preko korisnickog imena i dodata provera da li postoji korisnik kome se salje poruka #83
Diffstat (limited to 'Backend/Api')
-rw-r--r--Backend/Api/Api/Services/MessageService.cs7
1 files changed, 6 insertions, 1 deletions
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<Message> _messages;
+ private readonly IUserService _userService;
private readonly IJwtService _jwtService;
private IConfiguration _configuration;
private readonly IHubContext<ChatHub> _chatHub;
- public MessageService(IDatabaseConnection settings, IMongoClient mongoClient, IJwtService jwtService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration,IHubContext<ChatHub> chatHub)
+ public MessageService(IDatabaseConnection settings, IMongoClient mongoClient, IUserService userService, IJwtService jwtService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration,IHubContext<ChatHub> chatHub)
{
var database = mongoClient.GetDatabase(settings.DatabaseName);
_messages = database.GetCollection<Message>(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;