Skip to content

Commit

Permalink
Merge pull request #38 from SpotifaiI/main
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
tdayko authored May 2, 2024
2 parents e88cdaf + fe2cb7f commit c15a54d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
4 changes: 2 additions & 2 deletions src/HigiaServer.API/Endpoints/TaskEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Security.Authentication;
using System.Security.Claims;
using AutoMapper;
using HigiaServer.Application.Contracts.Requests;
using HigiaServer.Application.Contracts.Responses;
using HigiaServer.Application.Errors;
using HigiaServer.Application.Repositories;
using HigiaServer.Domain.Enums;
using Microsoft.AspNetCore.Http.HttpResults;

namespace HigiaServer.API.Endpoints;

Expand Down Expand Up @@ -63,6 +61,7 @@ public static IEndpointRouteBuilder AddTaskEndpoint(this IEndpointRouteBuilder a
return x;
});

// delete task
authEndpoint.MapDelete("/{taskId:guid}", HandleDeleteTask)
.WithName("Delete task by id")
.WithOpenApi(x =>
Expand All @@ -71,6 +70,7 @@ public static IEndpointRouteBuilder AddTaskEndpoint(this IEndpointRouteBuilder a
return x;
});

// remove collaborator from task
authEndpoint.MapPatch("/{taskId:guid}/{collaboratorId:guid}", HandleRemoveCollaboratorToTask)
.WithName("Remove collaborator to task")
.WithOpenApi(x =>
Expand Down
41 changes: 19 additions & 22 deletions src/HigiaServer.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,27 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddInfra(builder.Configuration);

builder.Services.AddAuthorization(options =>
builder.Services.AddAuthorizationBuilder()
.AddPolicy("admin", policy => policy.RequireRole("admin"))
.AddPolicy("collaborator", policy => policy.RequireRole("collaborator"));

builder.Services.AddAuthentication(x =>
{
options.AddPolicy("admin", policy => policy.RequireRole("admin"));
options.AddPolicy("collaborator", policy => policy.RequireRole("collaborator"));
});
builder
.Services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(x =>
{
var key = Encoding.ASCII.GetBytes(
builder.Configuration.GetValue<string>("JwtSettings:SecretKey")!
);
x.TokenValidationParameters = new TokenValidationParameters
{
var key = Encoding.ASCII.GetBytes(
builder.Configuration.GetValue<string>("JwtSettings:SecretKey")!
);
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
});
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
});

var app = builder.Build();

Expand Down
2 changes: 1 addition & 1 deletion src/HigiaServer.Domain/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace HigiaServer.Domain.Entities;

public class User(bool isAdmin, string name, string email, string password, string? number)
public class User(bool isAdmin, string name, string email, string password, string? number = null)
{
public Guid Id { get; init; } = Guid.NewGuid();
public string Name { get; private set; } = name;
Expand Down
10 changes: 9 additions & 1 deletion src/HigiaServer.Infra/DbContext/HigiaServerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ public class HigiaServerContext : Microsoft.EntityFrameworkCore.DbContext
public DbSet<User> Users { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseInMemoryDatabase(databaseName: "HigiaServerDb");

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
optionsBuilder.UseInMemoryDatabase(databaseName: "HigiaServerDb");
modelBuilder.Entity<User>().HasData(new User(
isAdmin: true,
name: "admin",
email: "[email protected]",
password: "adminadmin"
));
}
}

0 comments on commit c15a54d

Please sign in to comment.