public static User BuildUser() { return(new User() { Id = ParseUserId.GetUserId(CreateAuthHeader().Request.Headers), Email = "*****@*****.**", Name = "xunit" }); }
public void ItShouldExtractUserIdFromAuthToken() { var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["authorization"] = $"Bearer {Utilities.Token}"; string userId = ParseUserId.GetUserId(httpContext.Request.Headers); Assert.Equal("JEFe2Smd7lOtw4OEBe2vovG8OzH2", userId); }
public async Task HandleShipmentEventAsync(MFulfillment_ShipmentEvent eventData) { using var log = BeginFunction(nameof(FulfillmentEventMicroService), nameof(HandleShipmentEventAsync), eventData); try { using var ctx = CreateQuiltContext(); switch (eventData.EventType) { case MFulfillment_ShipmentEventTypes.Process: { var fulfillableIds = new HashSet <long>(); foreach (var shipmentRequestId in eventData.ShipmentRequestIds) { var mShipmentRequest = await FullfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId).ConfigureAwait(false); foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems) { var mFulfillable = await FullfillmentMicroService.GetFulfillableByItemAsync(mShipmentRequestItem.FulfillableItemId).ConfigureAwait(false); var fulfillableId = mFulfillable.FulfillableId; if (fulfillableIds.Contains(fulfillableId)) { _ = fulfillableIds.Add(fulfillableId); if (TryParseOrderId.FromFulfillableReference(mFulfillable.FulfillableReference, out var orderId)) { var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false); var userId = ParseUserId.FromOrdererReference(mOrder.OrdererReference); var participantReference = CreateParticipantReference.FromUserId(userId); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference).ConfigureAwait(false); var topicReference = CreateTopicReference.FromOrderId(orderId); var topicId = await CommunicationMicroService.AllocateTopicAsync(topicReference, null).ConfigureAwait(false); await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId).ConfigureAwait(false); } } } } } break; } await Task.CompletedTask.ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <ActionResult <object> > GeneratePlanner(GeneratePlannerInput reqBody) { string userId = ParseUserId.GetUserId(Request.Headers); /* the client will select a list of mealtypes that they want in their planner */ List <string> mealTypes = reqBody.input.mealTypes.ToList(); List <Recipe> allRecipes = (from recipe in _context.Recipes where recipe.Owner == userId where mealTypes.Contains(recipe.MealType) select recipe).ToList(); // this will shuffle the recipes List <Recipe> shuffledRecipes = allRecipes.OrderBy(r => Guid.NewGuid()).ToList(); DateTime startDate = DateTime.Parse(reqBody.input._gte); DateTime endDate = DateTime.Parse(reqBody.input._lte).AddDays(-1); /* delete existing planners for the given time because we are over writing it */ _context.RemoveRange( _context.Planners .Where(p => DateTime.Compare(p.Date, startDate) > 0) .Where(p => DateTime.Compare(p.Date, endDate) < 0) ); List <Planner> newPlanners = BuildPlannerForTheWeek( mealTypes, shuffledRecipes, userId, startDate ); await _context.Planners.AddRangeAsync(newPlanners); await _context.SaveChangesAsync(); var returningIds = newPlanners.Select(p => new { id = p.RecipeId }).ToList(); return(Ok(returningIds)); }
public async Task <ActionResult <object> > ScrapeRecipe(ScraperInput scraperInput) { string url = scraperInput.input.url; try { Recipe recipe = await Scraper.RunScraper(url); string userId = ParseUserId.GetUserId(Request.Headers); recipe.Owner = userId; // insert ot db _context.Recipes.Add(recipe); await _context.SaveChangesAsync(); return(Ok(new { id = recipe.Id })); } catch (System.OperationCanceledException e) { return(BadRequest(e.Message)); } }
public async Task <object> PostRecipe(InsertRecipeInput recipeInputRaw) { var userId = ParseUserId.GetUserId(Request.Headers); var recipeInput = recipeInputRaw.input; // parse the ingredient text and map it List <RecipeIngredient> recipeIngredients = new(); if (recipeInput.ingredients is not null) { recipeIngredients = (await Task.WhenAll(recipeInput.ingredients .Select(Parser.RunParser))) .ToList(); } // map everything to their proper location for db write Recipe recipe = new() { Directions = recipeInput.directions, Owner = userId, Img = recipeInput.img, TotalTime = recipeInput.total_time, Yields = recipeInput.yields, Cuisine = recipeInput.cuisine, MealType = recipeInput.meal_type, Title = recipeInput.title, RecipeIngredients = recipeIngredients }; _context.Recipes.Add(recipe); await _context.SaveChangesAsync(); return(new { id = recipe.Id }); } }
protected void OnNotificationCreated(QuiltContext ctx, Notification dbNotification) { var dbNotificationType = ctx.NotificationTypes.Find(dbNotification.NotificationTypeCode); var formatter = new NotificationEmailFormatter(dbNotificationType.Subject); var dbParticipant = ctx.Participants.Where(r => r.ParticipantId == dbNotification.ParticipantId).Single(); var participantUserId = ParseUserId.FromParticipantReference(dbParticipant.ParticipantReference); var dbAspNetUser = ctx.AspNetUsers.Where(r => r.Id == participantUserId).Single(); var dbEmailRequest = new EmailRequest() { EmailRequestStatusCode = EmailRequestStatusCodes.Posted, SenderEmail = Constants.DoNotReplyEmail, SenderEmailName = Constants.DoNotReplyEmailName, RecipientEmail = dbAspNetUser.Email, RecipientEmailName = dbAspNetUser.EmailName(), RecipientParticipant = dbNotification.Participant, Subject = formatter.GetSubject(), BodyText = formatter.GetText(), BodyHtml = formatter.GetHtml(), BodyTypeCode = EmailBodyTypes.Notification, CreateDateTimeUtc = Locale.GetUtcNow(), EmailRequestStatusDateTimeUtc = Locale.GetUtcNow(), }; _ = ctx.EmailRequests.Add(dbEmailRequest); var dbNotificationEmailRequest = new NotificationEmailRequest() { Notification = dbNotification, EmailRequest = dbEmailRequest }; _ = ctx.NotificationEmailRequests.Add(dbNotificationEmailRequest); }