From 14bcbbb7028ed009a2b1272dd1b251c2cbe6a74f Mon Sep 17 00:00:00 2001 From: Tsvi Zandany <121246525+tsviz@users.noreply.github.com> Date: Tue, 18 Feb 2025 15:53:44 -0600 Subject: [PATCH] Add artist entity to movie library Related to #76 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/octodemo/dotnet-razor-pages-movie/issues/76?shareId=XXXX-XXXX-XXXX-XXXX). --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++++ src/Data/RazorPagesMovieContext.cs | 11 ++++++- src/Models/Artist.cs | 23 +++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/Models/Artist.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79fb4ff..c22eb67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -296,3 +296,49 @@ jobs: INDEX_LIST=$(seq 0 ${MAX_INDEX}) # generate the list of indexes INDEX_JSON=$(jq --null-input --compact-output '. |= [inputs]' <<< ${INDEX_LIST}) # convert the list to the json echo "json=${INDEX_JSON}" >> $GITHUB_OUTPUT # save the json to the GITHUB_OUTPUT environment variable + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.2.2 + + - name: Setup .NET + uses: actions/setup-dotnet@v4.0.1 + with: + dotnet-version: '6.0.x' + + - name: Install .NET Code Analyzer + run: dotnet tool install --global dotnet-format + + - name: Run .NET Code Analyzer + run: dotnet format --check + env: + PATH: ${{ runner.tool_cache }}/.dotnet/tools:$PATH + + static-analysis: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.2.2 + + - name: Setup .NET + uses: actions/setup-dotnet@v4.0.1 + with: + dotnet-version: '6.0.x' + + - name: Install SonarScanner + run: dotnet tool install --global dotnet-sonarscanner + + - name: Run SonarScanner + run: dotnet sonarscanner begin /k:"${{ github.repository }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" + env: + PATH: ${{ runner.tool_cache }}/.dotnet/tools:$PATH + + - name: Build solution + run: dotnet build RazorPagesMovie.sln + + - name: End SonarScanner + run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + env: + PATH: ${{ runner.tool_cache }}/.dotnet/tools:$PATH diff --git a/src/Data/RazorPagesMovieContext.cs b/src/Data/RazorPagesMovieContext.cs index 3663ec1..5099a09 100644 --- a/src/Data/RazorPagesMovieContext.cs +++ b/src/Data/RazorPagesMovieContext.cs @@ -14,6 +14,7 @@ public RazorPagesMovieContext(DbContextOptions options) public DbSet Movie { get; set; } = default!; public DbSet Users { get; set; } = default!; + public DbSet Artists { get; set; } = default!; protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -42,6 +43,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(m => m.Timestamp).HasDefaultValue(new byte[8]); // Set default value for Timestamp }); + // Artist configuration + modelBuilder.Entity(entity => + { + entity.Property(a => a.Name).IsRequired().HasMaxLength(100); + entity.Property(a => a.Bio).HasMaxLength(1000); + entity.Property(a => a.Timestamp).IsConcurrencyToken(); + }); + // Seed data with hashed passwords var hashedAdminPw = HashPassword("password"); var hashedUserPw = HashPassword("password"); @@ -109,4 +118,4 @@ private static string HashPassword(string password) return $"{Convert.ToBase64String(salt)}:{hashed}"; } } -} \ No newline at end of file +} diff --git a/src/Models/Artist.cs b/src/Models/Artist.cs new file mode 100644 index 0000000..43399f7 --- /dev/null +++ b/src/Models/Artist.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace RazorPagesMovie.Models +{ + public class Artist + { + public int Id { get; set; } + + [Required] + [StringLength(100)] + public string Name { get; set; } = string.Empty; + + [StringLength(1000)] + public string Bio { get; set; } = string.Empty; + + [Timestamp] + public byte[] Timestamp { get; set; } = new byte[8]; + + public virtual ICollection Movies { get; set; } = new List(); + } +}