using System; using System.Collections.Generic; using System.Security.Claims; using OnlineAssessment.Common; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OnlineAssessment.Data.EFCore; using OnlineAssessment.Domain.Models; using OnlineAssessment.Domain.ViewModels; namespace OnlineAssessment.V1.Controllers { [Authorize] [ApiVersion("1.0")] [Route("v{version:apiVersion}/[controller]")] public class NotificationController : BaseController { EFCoreUserGroupRepository _repository; string responseMessage = string.Empty; public NotificationController(EFCoreUserGroupRepository repository) : base(repository) { _repository = repository; } /// /// Attch users to the user group /// /// [HttpPost("{user_group_id}/Message")] [Authorize(Roles = "Admin")] public async System.Threading.Tasks.Task Message() { IActionResult returnResponse; // The topic name can be optionally prefixed with "/topics/". var topic = "practiceKea"; // See documentation on defining a message payload. var message = new FirebaseAdmin.Messaging.Message() { Data = new Dictionary() { { "score", "850" }, { "time", "2:45" }, }, Topic = topic, Notification = new FirebaseAdmin.Messaging.Notification { Title = "Message Title", Body = "Message Body" }, }; // Send a message to the devices subscribed to the provided topic. string response = await FirebaseAdmin.Messaging.FirebaseMessaging.DefaultInstance.SendAsync(message); // Response is a message ID string. Console.WriteLine("Successfully sent message: " + response); returnResponse = Ok(ReturnResponse.GetSuccessStatus(response)); return returnResponse; } } }