Skip to content

Commit

Permalink
.net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Logerfo committed Nov 15, 2023
1 parent 407a58d commit 6dd0f89
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.101'
dotnet-version: '8.0.x'
- name: Build
run: dotnet build src/VSPoll.API.sln
- name: Test
Expand Down
1 change: 1 addition & 0 deletions .editorconfig → src/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
dotnet_remove_unnecessary_suppression_exclusions = category: ReSharper
###############################
# Core EditorConfig Options #
###############################
Expand Down
9 changes: 1 addition & 8 deletions src/VSPoll.API.UnitTest/Utils/MathUtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ public void NormalizePercentages_Changes()
19.161676646706585m,
22.75449101796407m,
}.ToList();
var expected = new[]
{
19,
21,
19,
18,
23,
};
int[] expected = [19, 21, 19, 18, 23];

var options = percentages.Select(percentage => new PollOption { Percentage = percentage }).ToList();
MathUtils.NormalizePercentages(options);
Expand Down
2 changes: 1 addition & 1 deletion src/VSPoll.API.UnitTest/VSPoll.API.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7</TargetFramework>
<TargetFramework>net8</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
12 changes: 1 addition & 11 deletions src/VSPoll.API/Controllers/OptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@ namespace VSPoll.API.Controllers;
#pragma warning disable IDE0079
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract")]
#pragma warning restore IDE0079
public class OptionController : Controller
public class OptionController(IPollService pollService, IOptionService optionService, IUserService userService) : ControllerBase
{
private readonly IPollService pollService;
private readonly IOptionService optionService;
private readonly IUserService userService;
public OptionController(IPollService pollService, IOptionService optionService, IUserService userService)
{
this.pollService = pollService;
this.optionService = optionService;
this.userService = userService;
}

/// <summary>
/// Gets the voters of an option
/// </summary>
Expand Down
12 changes: 1 addition & 11 deletions src/VSPoll.API/Controllers/PollController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@ namespace VSPoll.API.Controllers;
#pragma warning disable IDE0079
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract")]
#pragma warning restore IDE0079
public class PollController : Controller
public class PollController(IPollService pollService, IOptionService optionService, IUserService userService) : ControllerBase
{
private readonly IPollService pollService;
private readonly IOptionService optionService;
private readonly IUserService userService;
public PollController(IPollService pollService, IOptionService optionService, IUserService userService)
{
this.pollService = pollService;
this.optionService = optionService;
this.userService = userService;
}

/// <summary>
/// Gets data from a poll
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/VSPoll.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src
COPY ["VSPoll.API.csproj", "VSPoll.API/"]
RUN dotnet restore "VSPoll.API/VSPoll.API.csproj"
Expand Down
4 changes: 1 addition & 3 deletions src/VSPoll.API/Persistence/Contexts/PollContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace VSPoll.API.Persistence.Contexts;

public class PollContext : DbContext
public class PollContext(DbContextOptions<PollContext> contextOptions) : DbContext(contextOptions)
{
public DbSet<Poll> Polls { get; set; } = null!;
public DbSet<PollOption> PollOptions { get; set; } = null!;
Expand All @@ -12,6 +12,4 @@ public class PollContext : DbContext

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<PollVote>().HasKey(vote => new { vote.OptionId, vote.UserId });

public PollContext(DbContextOptions<PollContext> contextOptions) : base(contextOptions) { }
}
5 changes: 1 addition & 4 deletions src/VSPoll.API/Persistence/Repositories/OptionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

namespace VSPoll.API.Persistence.Repositories;

public class OptionRepository : IOptionRepository
public class OptionRepository(PollContext context) : IOptionRepository
{
private readonly PollContext context;
public OptionRepository(PollContext context) => this.context = context;

public Task<bool> CheckIfOptionExists(Guid id)
=> context.PollOptions.AnyAsync(option => option.Id == id);

Expand Down
5 changes: 1 addition & 4 deletions src/VSPoll.API/Persistence/Repositories/PollRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

namespace VSPoll.API.Persistence.Repositories;

public class PollRepository : IPollRepository
public class PollRepository(PollContext context) : IPollRepository
{
private readonly PollContext context;
public PollRepository(PollContext context) => this.context = context;

public Task<bool> CheckIfPollExists(Guid id)
=> context.Polls.AnyAsync(poll => poll.Id == id);

Expand Down
5 changes: 1 addition & 4 deletions src/VSPoll.API/Persistence/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

namespace VSPoll.API.Persistence.Repositories;

public class UserRepository : IUserRepository
public class UserRepository(PollContext context) : IUserRepository
{
private readonly PollContext context;
public UserRepository(PollContext context) => this.context = context;

public async Task AddOrUpdateUserAsync(User user)
{
if (await context.Users.AnyAsync(u => u.Id == user.Id))
Expand Down
6 changes: 1 addition & 5 deletions src/VSPoll.API/Services/OptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

namespace VSPoll.API.Services;

public class OptionService : IOptionService
public class OptionService(IOptionRepository optionRepository) : IOptionService
{
private readonly IOptionRepository optionRepository;
public OptionService(IOptionRepository optionRepository)
=> this.optionRepository = optionRepository;

public Task<bool> CheckIfOptionExistsAsync(Guid id)
=> optionRepository.CheckIfOptionExists(id);

Expand Down
10 changes: 1 addition & 9 deletions src/VSPoll.API/Services/PollService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@

namespace VSPoll.API.Services;

public class PollService : IPollService
public class PollService(IPollRepository pollRepository, IOptionRepository optionRepository) : IPollService
{
private readonly IPollRepository pollRepository;
private readonly IOptionRepository optionRepository;
public PollService(IPollRepository pollRepository, IOptionRepository optionRepository)
{
this.pollRepository = pollRepository;
this.optionRepository = optionRepository;
}

public Task<bool> CheckIfPollExistsAsync(Guid id)
=> pollRepository.CheckIfPollExists(id);

Expand Down
12 changes: 2 additions & 10 deletions src/VSPoll.API/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@

namespace VSPoll.API.Services;

public class UserService : IUserService
public class UserService(IUserRepository userRepository, IConfiguration configuration) : IUserService
{
private readonly IUserRepository userRepository;
private readonly IConfiguration configuration;
public UserService(IUserRepository userRepository, IConfiguration configuration)
{
this.userRepository = userRepository;
this.configuration = configuration;
}

public bool Authenticate(Authentication authentication, [NotNullWhen(false)] out string? error)
{
var dataCheck = $"auth_date={authentication.AuthDate}\nfirst_name={authentication.FirstName}\nid={authentication.Id}";
Expand All @@ -32,7 +24,7 @@ public bool Authenticate(Authentication authentication, [NotNullWhen(false)] out
if (authentication.Username is not null)
dataCheck += $"\nusername={authentication.Username}";

var token = configuration.GetSection("Secrets").GetValue<string>("BotToken");
var token = configuration.GetSection("Secrets").GetValue<string>("BotToken")!;
var secretKey = SHA256.HashData(Encoding.UTF8.GetBytes(token));
using HMACSHA256 hmac = new(secretKey);
var testHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(dataCheck));
Expand Down
2 changes: 1 addition & 1 deletion src/VSPoll.API/VSPoll.API.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7</TargetFramework>
<TargetFramework>net8</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down

0 comments on commit 6dd0f89

Please sign in to comment.