Skip to content

Commit

Permalink
Merge pull request #5 from rubenriseld/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rubenriseld authored Apr 5, 2024
2 parents 2af0214 + 4e19e45 commit 40539d7
Show file tree
Hide file tree
Showing 33 changed files with 1,872 additions and 71 deletions.
33 changes: 0 additions & 33 deletions Gallery.API/Controllers/WeatherForecastController.cs

This file was deleted.

19 changes: 19 additions & 0 deletions Gallery.API/DTOs/ImageCollectionDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Gallery.API.DTOs;

public class CreateImageCollectionDTO
{
public required string Name { get; set; }
public string? Description { get; set; }
}
public class ReadImageCollectionDTO
{
public required string ImageCollectionId { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public List<ReadImageDTO> Images { get; set; } = [];
}
public class UpdateImageCollectionDTO
{
public required string Name { get; set; }
public string? Description { get; set; }
}
24 changes: 24 additions & 0 deletions Gallery.API/DTOs/ImageDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Gallery.API.DTOs;

public record CreateImageDTO
{
public required string Uri { get; set; }
}
public record ReadImageDTO
{
public required string ImageId { get; set; }
public required string Uri { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? ImageCollectionId { get; set; }
public string? ImageCollectionName { get; set; }
public List<ReadTagDTO> Tags { get; set; } = [];
}

public record UpdateImageDTO
{
public required string Title { get; set; }
public string? Description { get; set; }
public string? ImageCollectionId { get; set; }
public string[] TagIds { get; set; } = [];
}
7 changes: 7 additions & 0 deletions Gallery.API/DTOs/LoginDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Gallery.API.DTOs;

public class LoginDTO
{
public required string Email { get; init; }
public required string Password { get; init; }
}
15 changes: 15 additions & 0 deletions Gallery.API/DTOs/TagDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Gallery.API.DTOs;

public record CreateTagDTO
{
public required string Name { get; set; }
}
public record ReadTagDTO
{
public required string TagId { get; set; }
public required string Name { get; set; }
}
public record UpdateTagDTO
{
public required string Name { get; set; }
}
39 changes: 39 additions & 0 deletions Gallery.API/Endpoints/AuthEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Gallery.API.DTOs;
using Microsoft.AspNetCore.Identity;

namespace Gallery.API.Endpoints;

public static class AuthEndpoints
{
public static void MapAuthEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("api/auth");

group.MapPost("/logout", Logout).RequireAuthorization();

group.MapPost("/login", Login);

//ONLY USED FOR CREATING ACCOUNT IN TESTING
//group.MapPost("/register", Register);

}
public static async Task<IResult> Register(UserManager<IdentityUser> userManager, LoginDTO login)
{
var user = new IdentityUser(login.Email);
user.Email = login.Email;
await userManager.CreateAsync(user, login.Password);

return Results.Created();
}
public static async Task<IResult> Login(SignInManager<IdentityUser> signInManager, LoginDTO login)
{
signInManager.AuthenticationScheme = IdentityConstants.ApplicationScheme;
await signInManager.PasswordSignInAsync(login.Email, login.Password, true, lockoutOnFailure: true);
return Results.Ok();
}
public static async Task<IResult> Logout(SignInManager<IdentityUser> signInManager)
{
await signInManager.SignOutAsync().ConfigureAwait(false);
return Results.NoContent();
}
}
45 changes: 45 additions & 0 deletions Gallery.API/Endpoints/ImageCollectionEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Gallery.API.DTOs;
using Gallery.API.Interfaces;

namespace Gallery.API.Endpoints;

public static class ImageCollectionEndpoints
{
public static void MapImageCollectionEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("api/imageCollections").RequireAuthorization();


group.MapPost("", CreateImageCollection);

group.MapGet("", GetAllImageCollections);

group.MapGet("{imageCollectionId}", GetImageCollectionById).AllowAnonymous();

group.MapPut("{imageCollectionId}", UpdateImageCollection);

group.MapDelete("{imageCollectionId}", DeleteImageCollection);

}
public static async Task<IResult> CreateImageCollection(CreateImageCollectionDTO createImageCollectionDto, IImageCollectionService imageCollectionService)
{
return Results.Created("api/imageCollections", await imageCollectionService.CreateImageCollection(createImageCollectionDto));
}
public static async Task<IResult> GetAllImageCollections(IImageCollectionService imageCollectionService)
{
return Results.Ok(await imageCollectionService.GetAllImageCollections());
}
public static async Task<IResult> GetImageCollectionById(IImageCollectionService imageCollectionService, string imageCollectionId)
{
return Results.Ok(await imageCollectionService.GetImageCollectionById(imageCollectionId));
}
public static async Task<IResult> UpdateImageCollection(IImageCollectionService imageCollectionService, string imageCollectionId, UpdateImageCollectionDTO updateImageCollectionDto)
{
return Results.Ok(await imageCollectionService.UpdateImageCollection(imageCollectionId, updateImageCollectionDto));
}
public static async Task<IResult> DeleteImageCollection(IImageCollectionService imageCollectionService, string imageCollectionId)
{
await imageCollectionService.DeleteImageCollection(imageCollectionId);
return Results.NoContent();
}
}
39 changes: 39 additions & 0 deletions Gallery.API/Endpoints/ImageEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Gallery.API.DTOs;
using Gallery.API.Interfaces;

namespace Gallery.API.Endpoints;

public static class ImageEndpoints
{
public static void MapImageEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("api/images").RequireAuthorization();


group.MapPost("", UploadImages).DisableAntiforgery();

group.MapGet("", GetAllImages);

group.MapPut("{imageId}", UpdateImage);

group.MapDelete("{imageId}", DeleteImage);

}
public static async Task<IResult> UploadImages(IFormFileCollection images, IImageService imageService)
{
return Results.Created("api/images", await imageService.UploadImages(images));
}
public static async Task<IResult> GetAllImages(IImageService imageService)
{
return Results.Ok(await imageService.GetAllImages());
}
public static async Task<IResult> UpdateImage(IImageService imageService, string imageId, UpdateImageDTO updateImageDto)
{
return Results.Ok(await imageService.UpdateImage(imageId, updateImageDto));
}
public static async Task<IResult> DeleteImage(IImageService imageService, string imageId)
{
await imageService.DeleteImage(imageId);
return Results.NoContent();
}
}
39 changes: 39 additions & 0 deletions Gallery.API/Endpoints/TagEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Gallery.API.DTOs;
using Gallery.API.Interfaces;

namespace Gallery.API.Endpoints;

public static class TagEndpoints
{
public static void MapTagEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("api/tags").RequireAuthorization();


group.MapPost("", CreateTag);

group.MapGet("", GetAllTags);

group.MapPut("{tagId}", UpdateTag);

group.MapDelete("{tagId}", DeleteTag);

}
public static async Task<IResult> CreateTag(CreateTagDTO createTagDto, ITagService tagService)
{
return Results.Created("api/tags", await tagService.CreateTag(createTagDto));
}
public static async Task<IResult> GetAllTags(ITagService tagService)
{
return Results.Ok(await tagService.GetAllTags());
}
public static async Task<IResult> UpdateTag(ITagService tagService, string tagId, UpdateTagDTO updateTagDto)
{
return Results.Ok(await tagService.UpdateTag(tagId, updateTagDto));
}
public static async Task<IResult> DeleteTag(ITagService tagService, string tagId)
{
await tagService.DeleteTag(tagId);
return Results.NoContent();
}
}
23 changes: 19 additions & 4 deletions Gallery.API/Gallery.API.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<InvariantGlobalization>false</InvariantGlobalization>
<UserSecretsId>6497fcdc-1766-4ccb-885d-8b432e1e2be4</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<ProjectReference Include="..\Gallery.Database\Gallery.Database.csproj" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions Gallery.API/Gallery.API.http

This file was deleted.

12 changes: 12 additions & 0 deletions Gallery.API/Interfaces/IImageCollectionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Gallery.API.DTOs;

namespace Gallery.API.Interfaces;

public interface IImageCollectionService
{
Task<ReadImageCollectionDTO> CreateImageCollection(CreateImageCollectionDTO createImageCollectionDto);
Task DeleteImageCollection(string imageCollectionId);
Task<List<ReadImageCollectionDTO>> GetAllImageCollections();
Task<ReadImageCollectionDTO> GetImageCollectionById(string imageCollectionId);
Task<ReadImageCollectionDTO> UpdateImageCollection(string imageCollectionId, UpdateImageCollectionDTO updateImageCollectionDto);
}
11 changes: 11 additions & 0 deletions Gallery.API/Interfaces/IImageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Gallery.API.DTOs;

namespace Gallery.API.Interfaces;

public interface IImageService
{
Task<List<ReadImageDTO>> UploadImages(IFormFileCollection images);
Task<List<ReadImageDTO>> GetAllImages();
Task<ReadImageDTO> UpdateImage(string imageId, UpdateImageDTO updateImageDto);
Task DeleteImage(string imageId);
}
11 changes: 11 additions & 0 deletions Gallery.API/Interfaces/ITagService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Gallery.API.DTOs;

namespace Gallery.API.Interfaces;

public interface ITagService
{
Task<List<ReadTagDTO>> GetAllTags();
Task<ReadTagDTO> CreateTag(CreateTagDTO createTagDto);
Task<ReadTagDTO> UpdateTag(string tagId, UpdateTagDTO updateTagDto);
Task DeleteTag(string tagId);
}
Loading

0 comments on commit 40539d7

Please sign in to comment.