ADD neue seite für firmen admins auf der sie die produkteinträge einzeln löschen können
This commit is contained in:
13
backend/src/main/java/de/strichliste/dto/TallyEntryDto.java
Normal file
13
backend/src/main/java/de/strichliste/dto/TallyEntryDto.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package de.strichliste.dto;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public record TallyEntryDto(
|
||||
Long id,
|
||||
Long employeeId,
|
||||
String employeeFirstName,
|
||||
String employeeLastName,
|
||||
String productName,
|
||||
int priceCents,
|
||||
LocalDateTime createdAt
|
||||
) {}
|
||||
@@ -187,6 +187,53 @@ public class CompanyAdminResource {
|
||||
return Response.ok(line).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/entries")
|
||||
public Response getTallyEntries(@QueryParam("token") String token, @QueryParam("month") String month) {
|
||||
AccessLink link = AccessLink.findByToken(token).orElse(null);
|
||||
if (link == null || link.company == null) {
|
||||
return Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
|
||||
String monthKey = month != null ? month : LocalDateTime.now().format(MONTH_FORMAT);
|
||||
|
||||
List<TallyEntry> entries = TallyEntry.find(
|
||||
"SELECT t FROM TallyEntry t JOIN FETCH t.employee JOIN FETCH t.product " +
|
||||
"WHERE t.employee.company.id = ?1 AND t.monthKey = ?2 ORDER BY t.createdAt DESC",
|
||||
link.company.id, monthKey).list();
|
||||
|
||||
List<TallyEntryDto> dtos = entries.stream()
|
||||
.map(t -> new TallyEntryDto(
|
||||
t.id,
|
||||
t.employee.id,
|
||||
t.employee.firstName,
|
||||
t.employee.lastName,
|
||||
t.product.name,
|
||||
t.priceCentsAtBooking,
|
||||
t.createdAt))
|
||||
.toList();
|
||||
|
||||
return Response.ok(dtos).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/entries/{id}")
|
||||
@Transactional
|
||||
public Response deleteTallyEntry(@QueryParam("token") String token, @PathParam("id") Long id) {
|
||||
AccessLink link = AccessLink.findByToken(token).orElse(null);
|
||||
if (link == null || link.company == null) {
|
||||
return Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
|
||||
TallyEntry entry = TallyEntry.findById(id);
|
||||
if (entry == null || !entry.employee.company.id.equals(link.company.id)) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
entry.delete();
|
||||
return Response.noContent().build();
|
||||
}
|
||||
|
||||
static MonthlyReportDto buildCompanyReport(Long companyId, String monthKey) {
|
||||
Company company = Company.findById(companyId);
|
||||
List<Employee> employees = Employee.findAllByCompany(companyId);
|
||||
|
||||
Reference in New Issue
Block a user