From a343fa2d7f8c27432d42c48f48370fc7b28a13e9 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Thu, 22 Jun 2023 08:04:18 -0700 Subject: [PATCH] started to update articlesTable with entities --- Newsbot.Collector.Domain/Dto/ArticleDto.cs | 23 ++++++++++++++++++- .../Interfaces/IArticlesRepository.cs | 5 ++-- makefile | 15 ++++-------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Newsbot.Collector.Domain/Dto/ArticleDto.cs b/Newsbot.Collector.Domain/Dto/ArticleDto.cs index 0532f32..7a55872 100644 --- a/Newsbot.Collector.Domain/Dto/ArticleDto.cs +++ b/Newsbot.Collector.Domain/Dto/ArticleDto.cs @@ -1,3 +1,4 @@ +using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Models; namespace Newsbot.Collector.Domain.Dto; @@ -17,7 +18,7 @@ public class ArticleDto public string? Description { get; set; } public string? AuthorName { get; set; } public string? AuthorImage { get; set; } - public static ArticleDto Convert(ArticlesModel article) + public static ArticleDto Convert(ArticlesModel article) { return new ArticleDto { @@ -36,4 +37,24 @@ public class ArticleDto AuthorImage = article.AuthorImage, }; } + + public static ArticleDto Convert(ArticlesEntity article) + { + return new ArticleDto + { + ID = article.Id, + SourceID = article.SourceId, + Tags = article.Tags.Split(','), + Title = article.Title, + Url = article.Url, + PubDate = article.PubDate, + Video = article.Video, + VideoHeight = article.VideoHeight, + VideoWidth = article.VideoWidth, + Thumbnail = article.Thumbnail, + Description = article.Description, + AuthorName = article.AuthorName, + AuthorImage = article.AuthorImage, + }; + } } \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs b/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs index c17e62c..d5b619f 100644 --- a/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs +++ b/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs @@ -1,13 +1,14 @@ +using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Models; namespace Newsbot.Collector.Domain.Interfaces; public interface IArticlesRepository : ITableRepository { - List List(int page, int count); + List List(int page, int count); List ListBySourceId(Guid id, int page = 0, int count = 25); ArticlesModel GetById(Guid ID); ArticlesModel GetByUrl(string url); - ArticlesModel New(ArticlesModel model); + ArticlesEntity New(ArticlesEntity model); void DeleteAllBySourceId(Guid sourceId); } \ No newline at end of file diff --git a/makefile b/makefile index 2341cb6..858ec2b 100644 --- a/makefile +++ b/makefile @@ -21,14 +21,9 @@ docker-run: ## Runs the docker compose docker-migrate: ## Runs the migrations stored in the Docker image docker run -it --env-file .env ghcr.io/jtom38/newsbot.collector:master /app/goose --dir "/app/migrations" up -migrate-dev: ## Apply sql migrations to dev db - goose -dir "./Newsbot.Collector.Database/Migrations" postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" up +ef-build: ## Builds migration artifact + dotnet ef migrations bundle --project "Newsbot.Collector.Database" -migrate-dev-down: ## revert sql migrations to dev db - goose -dir "./Newsbot.Collector.Database/Migrations" postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" down - -migrate-refresh: ## Rolls back all migrations - goose -dir "./Newsbot.Collector.Database/Migrations" postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" reset - -ef-bundle: ## Create a migration bundle - dotnet ef migrations bundle --project Newsbot.Collector.Database \ No newline at end of file +ef-migrate: ## Runs migrations based on the newest artifact + dotnet ef migrations bundle --project "Newsbot.Collector.Database" --force + ./efbundle --connection "Host=localhost;Username=postgres;Password=postgres;Database=postgres;sslmode=disable"