public Post Transform(ResponsePost x) { var updated = DateTimes.UnixTimeStampToDateTime(x.CreatedUtc); var possibleMediaPreviewUrl = GetMediaPreviewUrl(x); return(new Post { Id = ids.IdFromUrl(x.Url), Author = x.Author.Truncate(100), Content = x.Selftext, Score = x.Score, Controversiality = null, Gilded = x.Gilded, Title = x.Title.Truncate(200), Subreddit = ids.ExtractSubredditIdFromUrl(x.Url) ?? string.Empty, PublishedMonthPrecision = updated.MonthPrecision(), PublishedWeekPrecision = updated.DayOfWeekPrecision(), PublishedDayPrecision = updated.DayPrecision(), PublishedHourPrecision = updated.HourPrecision(), PublishedMinutePrecision = updated.MinutePrecision(), PublishedTimestamp = updated, IngestedTimestamp = DateTime.UtcNow, Url = x.Url, MediaPreviewUrl = possibleMediaPreviewUrl, }); }
public async Task <IActionResult> GetDataBDTestAsync() { try { _logger.LogInformation("Iniciando Proceso para recuperar datos Test de la BD"); var test = await _testService.GetDataBDTestAsync(); if (test == null) { _logger.LogWarning("No se encontraron datos."); } //throw new Exception("Error controlado"); return(Ok(test)); } catch (Exception err) { _logger.LogError(err, "Error inesperado"); var responsePost = new ResponsePost() { Messages = new Message[] { new Message() { Type = TypeMessage.error.ToString(), Description = err.Message } }, }; return(StatusCode(500, responsePost)); //throw new BussinesException(err.Message); } }
public void GetMediaPreviewUrl_smaller_media() { var thread = new ResponsePost() { Media = new Media() { Oembed = new Oembed() { ThumbnailUrl = "http://foo.com", ThumbnailHeight = 3, ThumbnailWidth = 3 } }, Preview = new Preview() { Images = new List <Image>() { new Image() { Source = new Source() { Url = "http://bar.com", Height = 4, Width = 4 } } } } }; Assert.AreEqual("http://foo.com", ThreadResponsePostTransformer.GetMediaPreviewUrl(thread)); }
public async Task <IActionResult> CreateAsync([FromBody] PostRequestCreate postRequestCreate) { var post = new Post { Id = postRequestCreate.Id, Name = postRequestCreate.Name }; if (string.IsNullOrEmpty(post.Id)) { post.Id = Guid.NewGuid().ToString(); } post = await _PostService.PostCreateAsync(post); var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUrl = baseUrl + "/" + ApiRoutes.Posts.Get.Replace("{postId}", post.Id); var responsePost = new ResponsePost { Id = post.Id, Name = post.Name }; return(Created(locationUrl, responsePost)); }
public PreInscripcionRepository(IConeccion coneccion, IOptions <PaginationOptions> options) { _coneccion = coneccion; _paginationOptions = options.Value; responseGet = new ResponseGet(); responseGetPagination = new ResponseGetPagination(); responsePost = new ResponsePost(); }
public IActionResult OnPost() { if (ModelState.IsValid) { SearchResponse = _searchLogic.SearchPosts(SearchParam); } return(Page()); }
public void GetMediaPreviewUrl_no_preview() { var thread = new ResponsePost() { Media = new Media() { Oembed = new Oembed() { ThumbnailUrl = "http://foo.com", ThumbnailHeight = 2, ThumbnailWidth = 2 } } }; Assert.AreEqual("http://foo.com", ThreadResponsePostTransformer.GetMediaPreviewUrl(thread)); }
public void GetMediaPreviewUrl_nulls_and_empties() { Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(null), "Null thread object"); var thread = new ResponsePost(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Empty thread object with null properties"); // thread.media.oembed.thumbnail_url path thread.Media = new Media(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only media property set, but media property is set to empty media object"); thread.Media.Oembed = new Oembed(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only media property set and oembed property set to empty Oembed2 object (no url set)"); thread = new ResponsePost(); // thread.preview.images[0].source.url path thread.Preview = new Preview(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only preview property set, but preview property is set to empty preview object"); thread.Preview.Images = new List <Image>(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only preview property set and images property set to empty list of Images"); thread.Preview.Images.Add(null); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only preview property set and images property set with a single null element added to list of Images"); thread.Preview.Images[0] = new Image(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only preview property set and images property set with a single empty image element added to list"); thread.Preview.Images[0].Source = new Source(); Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "Thread object with only preview property set and images property set with a single image element added with an empty source property"); thread = new ResponsePost() { Media = new Media() { Oembed = new Oembed() }, Preview = new Preview() { Images = new List <Image>() { new Image() { Source = new Source() } } } }; Assert.IsNull(ThreadResponsePostTransformer.GetMediaPreviewUrl(thread), "All items but urls set; must still return null"); }
public async Task <IActionResult> GetDataBDPaginationTestAsync([FromQuery] TestGetQueryFilter testQueryFilter) { try { _logger.LogInformation("Iniciando Proceso para recuperar datos Test de la BD"); var test = await _testService.GetDataBDTestPaginationAsync(testQueryFilter); if (test == null) { _logger.LogWarning("No se encontraron datos."); } var pagination = new Pagination { TotalRegistros = test.Paginations.TotalRegistros, TamanoDePagina = test.Paginations.TamanoDePagina, PaginaActual = test.Paginations.PaginaActual, TotalPaginas = test.Paginations.TotalPaginas, TienePaginaAnterior = test.Paginations.TienePaginaAnterior, TienePaginaSiguiente = test.Paginations.TienePaginaSiguiente }; var response = new ApiResponse <IEnumerable <object> >(test.Paginations) { Pagination = pagination, Messages = test.Messages }; return(StatusCode((int)test.StatusCode, response)); } catch (Exception err) { _logger.LogError(err, "Error inesperado"); var responsePost = new ResponsePost() { Messages = new Message[] { new Message() { Type = TypeMessage.error.ToString(), Description = err.Message } }, }; return(StatusCode(500, responsePost)); //throw new BussinesException(err.Message); } }
public async Task <IActionResult> AddPreInscripcion([FromBody] PreInscripcionQueryFilter preInscripcionQueryFilter) { try { var preInscripcion = await _preInscripcionService.InsPreInscripcion(preInscripcionQueryFilter); return(StatusCode((int)preInscripcion.StatusCode, preInscripcion)); } catch (Exception err) { _logger.LogError(err, "Error inesperado"); var responsePost = new ResponsePost() { Messages = new Message[] { new Message() { Type = TypeMessage.error.ToString(), Description = err.Message } }, }; return(StatusCode(500, responsePost)); } }
public async Task <IActionResult> PostPersona(TestInsQueryFilter testInsQueryFilter) { try { var per = await _testService.InsTestAsync(testInsQueryFilter); return(StatusCode((int)per.StatusCode, per)); } catch (Exception err) { _logger.LogError(err, "Error inesperado"); var responsePost = new ResponsePost() { Messages = new Message[] { new Message() { Type = TypeMessage.error.ToString(), Description = err.Message } }, }; return(StatusCode(500, responsePost)); } }
/// <summary> /// There are many media URLs we may want to return for this preview URL and this method is a simple abstraction for us to swap out which we prefer /// without making the Process method more complex than it has to be. /// </summary> /// <param name="thread"></param> /// <returns></returns> internal static string GetMediaPreviewUrl(ResponsePost thread) { /* * there are at least two paths we can follow for this: * 1: we can use thread.media.oembed.thumbnail_url. The problem is this "thumbnail" can be any resolution - including my example, which was 480x270 * 2: we can use thread.preview.images[0].source.url. This url can also be any resolution - including my example, which was 1366x766 * * We can also return whichever exists first. However, they may also be super large, which is super wasteful when we're just going to have to put height and width restrictions * on their display anyway. * * Maybe instead we should try to get both, and if both exist, attempt to return the smallest. */ var oembed = thread?.Media?.Oembed; var source = ( thread?.Preview?.Images != null && thread?.Preview?.Images.Count > 0 ) ? thread.Preview.Images[0]?.Source : null; if (oembed?.ThumbnailUrl == null || source?.Url == null) { return(oembed?.ThumbnailUrl ?? source?.Url); // could return null if both are null } // at this point, both of these should be valid. // so, it's POSSIBLE that aspect ratio between the two images could change. it shouldn't, as they are supposed to just be resized versions, but let's just say they do // take the total area of the image as the value to judge on smallness, then return the corresponding image url. if (source.Height * source.Width < oembed.ThumbnailHeight * oembed.ThumbnailWidth) { return(source.Url); } else { return(oembed.ThumbnailUrl); } }
public void GetMediaPreviewUrl_no_media() { var thread = new ResponsePost() { Preview = new Preview() { Images = new List <Image>() { new Image() { Source = new Source() { Url = "http://foo.com", Height = 2, Width = 2 } } } } }; Assert.AreEqual("http://foo.com", ThreadResponsePostTransformer.GetMediaPreviewUrl(thread)); }