Skip to content

Commit

Permalink
Upload image to volume (#11)
Browse files Browse the repository at this point in the history
* FIrst draft of image handling

* Fix service

* Fix tests

* upload file and switch event from thumbnail to url

* Resize and check image size

* FIx tests and cdn file dropping

* fix last test

* fix Dockerfile CI
  • Loading branch information
MysticFragilist authored Mar 1, 2024
1 parent 92120c7 commit 4b548bd
Show file tree
Hide file tree
Showing 24 changed files with 828 additions and 95 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY core/api.core.csproj ./core/
COPY emails/api.emails.csproj ./emails/
COPY files/api.files.csproj ./files/
COPY tests/api.tests.csproj ./tests/
COPY Hello.sln ./
RUN dotnet restore
Expand Down
8 changes: 7 additions & 1 deletion Hello.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api.core", "core\api.core.c
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api.tests", "tests\api.tests.csproj", "{9080AC9C-A5FC-4FB3-9F4E-724ECD591996}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api.emails", "emails\api.emails.csproj", "{62B49CA5-5A75-4E7B-8467-4ECDEE02CD49}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api.emails", "emails\api.emails.csproj", "{62B49CA5-5A75-4E7B-8467-4ECDEE02CD49}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api.files", "files\api.files.csproj", "{F2425268-5799-42FF-9778-5A1BB7B9DE31}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{62B49CA5-5A75-4E7B-8467-4ECDEE02CD49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62B49CA5-5A75-4E7B-8467-4ECDEE02CD49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62B49CA5-5A75-4E7B-8467-4ECDEE02CD49}.Release|Any CPU.Build.0 = Release|Any CPU
{F2425268-5799-42FF-9778-5A1BB7B9DE31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2425268-5799-42FF-9778-5A1BB7B9DE31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2425268-5799-42FF-9778-5A1BB7B9DE31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2425268-5799-42FF-9778-5A1BB7B9DE31}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions core/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ASPNETCORE_ENVIRONMENT=Development
CONNECTION_STRING=User ID=postgres;Password=test123;Host=host.docker.internal;Port=5432;Database=ps;
SUPABASE_PROJECT_ID=
SUPABASE_SECRET_KEY=
SUPABASE_ANON_KEY=

EMAIL_SERVER=smtp.gmail.com
EMAIL_PORT=587
Expand All @@ -16,3 +17,7 @@ EMAIL_FROM=
EMAIL_TO_IF_DEBUG=

REDIS_CONNECTION_STRING=host.docker.internal:6379,password=eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81,abortConnect=False,resolvedns=1

HOST_DIR=
CONTAINER_DIR=/app/volume
CDN_URL=http://localhost:6464
3 changes: 2 additions & 1 deletion core/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ public class EventsController(ILogger<EventsController> logger, IEventService ev
public ActionResult<IEnumerable<EventResponseDTO>> GetEvents(
[FromQuery] DateTime? startDate,
[FromQuery] DateTime? endDate,
[FromQuery] Guid? organizerId,
[FromQuery] IEnumerable<string>? activityAreas,
[FromQuery] IEnumerable<Guid>? tags,
[FromQuery] PaginationRequest pagination)
{
logger.LogInformation("Getting events");
var validFilter = new PaginationRequest(pagination.PageNumber, pagination.PageSize);

var events = eventService.GetEvents(startDate, endDate, activityAreas, tags, null, State.Published);
var events = eventService.GetEvents(startDate, endDate, activityAreas, tags, organizerId, State.Published);
var totalRecords = events.Count();
var paginatedRes = events
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
Expand Down
36 changes: 0 additions & 36 deletions core/Controllers/MailTestController.cs

This file was deleted.

6 changes: 2 additions & 4 deletions core/Controllers/OrganizerEventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using api.core.data.entities;
using api.core.Data.Entities;
using api.core.Data.Requests;
using api.core.Data.Exceptions;

namespace api.core.Controllers;

Expand Down Expand Up @@ -46,7 +44,7 @@ public IActionResult MyEvents(
}

[HttpPost]
public IActionResult AddEvent([FromBody] EventRequestDTO dto)
public IActionResult AddEvent([FromForm] EventCreationRequestDTO dto)
{
logger.LogInformation($"Adding new event");

Expand All @@ -69,7 +67,7 @@ public IActionResult DeleteEvent(Guid id)
}

[HttpPatch("{id}")]
public IActionResult UpdateEvent(Guid id, [FromBody] EventRequestDTO dto)
public IActionResult UpdateEvent(Guid id, [FromForm] EventUpdateRequestDTO dto)
{
var userId = JwtUtils.GetUserIdFromAuthHeader(HttpContext.Request.Headers["Authorization"]!);
return eventService.UpdateEvent(userId, id, dto) ? Ok() : BadRequest();
Expand Down
25 changes: 25 additions & 0 deletions core/Controllers/TestController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using api.core.Data.Requests;
using api.emails.Models;
using api.emails.Services.Abstractions;

using Microsoft.AspNetCore.Mvc;


namespace api.core.controllers;

[ApiController]
[Route("api/test")]
public class TestController(IEmailService service, IConfiguration configuration) : ControllerBase
{

[HttpPost("login")]
public async Task<IActionResult> Login([FromBody] LoginRequestDTO req, CancellationToken ct)
{
var projectId = configuration.GetValue<string>("SUPABASE_PROJECT_ID");
var anonKey = configuration.GetValue<string>("SUPABASE_ANON_KEY");

var client = new Supabase.Client($"https://{projectId}.supabase.co", anonKey);
var response = await client.Auth.SignInWithPassword(req.Email, req.Password);
return Ok(response);
}
}
2 changes: 1 addition & 1 deletion core/Data/Entities/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class Publication

public string Content { get; set; } = null!;

public string ImageUrl { get; set; } = null!;
public string? ImageUrl { get; set; }

public State State { get; set; }

Expand Down
18 changes: 12 additions & 6 deletions core/Data/Requests/EventRequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ namespace api.core.Data.requests;

public class EventRequestDTO
{
public Guid Id { get; set; }

public string Title { get; set; } = null!;

public string Content { get; set; } = null!;

public string ImageUrl { get; set; } = null!;

public State State { get; set; }

public DateTime PublicationDate { get; set; }

public DateTime EventStartDate { get; set; }
Expand All @@ -23,3 +17,15 @@ public class EventRequestDTO

public virtual ICollection<Guid> Tags { get; set; } = new List<Guid>();
}


public class EventCreationRequestDTO : EventRequestDTO
{
public IFormFile Image { get; set; }
}

public class EventUpdateRequestDTO : EventRequestDTO
{
public IFormFile? Image { get; set; }
}

7 changes: 7 additions & 0 deletions core/Data/Requests/LoginRequestDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace api.core.Data.Requests;

public class LoginRequestDTO
{
public required string Email { get; set; }
public required string Password { get; set; }
}
4 changes: 3 additions & 1 deletion core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ../core/api.core.csproj ./core/
COPY ../emails/api.emails.csproj ./emails/
COPY ../files/api.files.csproj ./files/
COPY ../tests/api.tests.csproj ./tests/
COPY ../Hello.sln ./
RUN dotnet restore
Expand All @@ -24,4 +25,5 @@ RUN dotnet publish -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS runtime
WORKDIR /app
COPY --chown=app --from=publish /app/publish .
ENTRYPOINT ["dotnet", "api.core.dll"]
RUN mkdir -p /app/volume # create volume directory to store images
ENTRYPOINT ["dotnet", "api.core.dll"]
3 changes: 3 additions & 0 deletions core/Extensions/DependencyInjectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using api.core.Services;
using api.emails.Services;
using api.emails.Services.Abstractions;
using api.files.Services;
using api.files.Services.Abstractions;

namespace api.core.Extensions;

Expand All @@ -25,6 +27,7 @@ public static IServiceCollection AddDependencyInjection(this IServiceCollection
services.AddTransient<IUserService, UserService>();
services.AddTransient<IEventService, EventService>();
services.AddTransient<IEmailService, EmailService>();
services.AddTransient<IFileShareService, FileShareService>();

return services;
}
Expand Down
Loading

0 comments on commit 4b548bd

Please sign in to comment.