-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from rubenriseld/develop
Develop
- Loading branch information
Showing
33 changed files
with
1,872 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.