This commit is contained in:
2026-03-31 15:12:48 +02:00
parent 6eb940c37c
commit 84a044bcb1
10 changed files with 152 additions and 14 deletions

View File

@@ -1,3 +1,3 @@
package de.strichliste.dto;
public record CompanyDto(Long id, String name, boolean active) {}
public record CompanyDto(Long id, String name, boolean active, boolean hasLogo) {}

View File

@@ -22,6 +22,12 @@ public class Company extends PanacheEntityBase {
@Column(name = "created_at", nullable = false, updatable = false)
public LocalDateTime createdAt = LocalDateTime.now();
@Column(name = "logo")
public byte[] logo;
@Column(name = "logo_content_type", length = 50)
public String logoContentType;
@OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
public List<Employee> employees;

View File

@@ -5,10 +5,12 @@ import de.strichliste.entity.*;
import de.strichliste.filter.AuthFilter.Secured;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.RestForm;
import org.jboss.resteasy.reactive.multipart.FileUpload;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -96,6 +98,47 @@ public class CompanyAdminResource {
return Response.ok(new EmployeeDto(employee.id, employee.company.id, employee.firstName, employee.lastName, employee.active)).build();
}
@POST
@Path("/logo")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Transactional
public Response uploadLogo(@QueryParam("token") String token, @RestForm("file") FileUpload file) throws IOException {
AccessLink link = AccessLink.findByToken(token).orElse(null);
if (link == null || link.company == null) {
return Response.status(Response.Status.FORBIDDEN).build();
}
Company company = Company.findById(link.company.id);
if (company == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
company.logo = Files.readAllBytes(file.uploadedFile());
company.logoContentType = file.contentType();
return Response.ok().build();
}
@DELETE
@Path("/logo")
@Transactional
public Response deleteLogo(@QueryParam("token") String token) {
AccessLink link = AccessLink.findByToken(token).orElse(null);
if (link == null || link.company == null) {
return Response.status(Response.Status.FORBIDDEN).build();
}
Company company = Company.findById(link.company.id);
if (company == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
company.logo = null;
company.logoContentType = null;
return Response.ok().build();
}
@GET
@Path("/report")
public Response getMonthlyReport(@QueryParam("token") String token, @QueryParam("month") String month) {

View File

@@ -29,7 +29,7 @@ public class ProviderAdminResource {
return Company.findAll().list().stream()
.map(obj -> {
Company c = (Company) obj;
return new CompanyDto(c.id, c.name, c.active);
return new CompanyDto(c.id, c.name, c.active, c.logo != null);
})
.toList();
}
@@ -42,7 +42,7 @@ public class ProviderAdminResource {
company.name = request.name();
company.persist();
return Response.status(Response.Status.CREATED)
.entity(new CompanyDto(company.id, company.name, company.active))
.entity(new CompanyDto(company.id, company.name, company.active, company.logo != null))
.build();
}
@@ -55,7 +55,7 @@ public class ProviderAdminResource {
return Response.status(Response.Status.NOT_FOUND).build();
}
company.name = request.name();
return Response.ok(new CompanyDto(company.id, company.name, company.active)).build();
return Response.ok(new CompanyDto(company.id, company.name, company.active, company.logo != null)).build();
}
@PUT
@@ -67,7 +67,7 @@ public class ProviderAdminResource {
return Response.status(Response.Status.NOT_FOUND).build();
}
company.active = !company.active;
return Response.ok(new CompanyDto(company.id, company.name, company.active)).build();
return Response.ok(new CompanyDto(company.id, company.name, company.active, company.logo != null)).build();
}
// --- Products ---

View File

@@ -21,7 +21,7 @@ public class PublicResource {
@Path("/companies")
public List<CompanyDto> getActiveCompanies() {
return Company.findAllActive().stream()
.map(c -> new CompanyDto(c.id, c.name, c.active))
.map(c -> new CompanyDto(c.id, c.name, c.active, c.logo != null))
.toList();
}
@@ -62,6 +62,18 @@ public class PublicResource {
return Response.status(Response.Status.CREATED).build();
}
@GET
@Path("/companies/{id}/logo")
@Produces("*/*")
public Response getCompanyLogo(@PathParam("id") Long companyId) {
Company company = Company.findById(companyId);
if (company == null || company.logo == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
String contentType = company.logoContentType != null ? company.logoContentType : "image/png";
return Response.ok(company.logo, contentType).build();
}
@GET
@Path("/tally/monthly/{employeeId}")
public List<MonthlyTallyDto> getMonthlyTally(

View File

@@ -0,0 +1,2 @@
ALTER TABLE company ADD COLUMN logo MEDIUMBLOB;
ALTER TABLE company ADD COLUMN logo_content_type VARCHAR(50);