Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup code #478

Merged
merged 4 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
depends_on:
- postgres
ports:
- 8082:8080
- "8082:8080"

mailcatcher:
image: schickling/mailcatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.wisv.events.admin.controller;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.exception.normal.EventInvalidException;
import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.model.event.Event;
Expand All @@ -14,12 +13,10 @@

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ch.wisv.events.admin.controller;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.admin.Attendance;
import ch.wisv.events.core.model.event.Event;
import ch.wisv.events.core.model.ticket.Ticket;
import ch.wisv.events.core.model.ticket.TicketStatus;
import ch.wisv.events.core.repository.EventRepository;
import ch.wisv.events.core.service.customer.CustomerService;
import ch.wisv.events.core.service.event.EventService;
Expand All @@ -13,7 +11,6 @@
import java.util.List;
import java.util.stream.Collectors;

import org.apache.tomcat.jni.Local;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
Expand All @@ -35,9 +32,6 @@ public class DashboardIndexController extends DashboardController {
/** CustomerService. */
private final CustomerService customerService;

/** TicketService. */
private final TicketService ticketService;

/** EventRepository. */
private final EventRepository eventRepository;

Expand All @@ -46,16 +40,14 @@ public class DashboardIndexController extends DashboardController {
*
* @param eventService of type EventService
* @param customerService of type CustomerService
* @param ticketService of type TicketService
* @param eventRepository of type eventRepository
*/
@Autowired
public DashboardIndexController(
EventService eventService, CustomerService customerService, TicketService ticketService, EventRepository eventRepository
EventService eventService, CustomerService customerService, EventRepository eventRepository
) {
this.eventService = eventService;
this.customerService = customerService;
this.ticketService = ticketService;
this.eventRepository = eventRepository;
}

Expand All @@ -79,8 +71,10 @@ public String index(Model model) {
model.addAttribute("totalCustomers", totalCustomers);
model.addAttribute("increaseCustomers", this.calculateChangePercentage(totalCustomers - this.determineTotalCustomersLastMonth(), totalCustomers));

Attendence attCurrBoard = this.eventRepository.getAttendenceFromEventsInDateRange(CurrentBoardStartYear.minusMonths(1), CurrentBoardStartYear);
Attendence attLastBoard = this.eventRepository.getAttendenceFromEventsInDateRange(CurrentBoardStartYear.minusYears(1).minusMonths(1), CurrentBoardStartYear.minusYears(1));
Attendance attCurrBoard =
this.eventRepository.getAttendanceFromEventsInDateRange(CurrentBoardStartYear.minusMonths(1), CurrentBoardStartYear);
Attendance attLastBoard =
this.eventRepository.getAttendanceFromEventsInDateRange(CurrentBoardStartYear.minusYears(1).minusMonths(1), CurrentBoardStartYear.minusYears(1));

double attendanceRateCurrentBoard = 0d;
double attendanceRateLastBoard = 0d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public static Map<Integer, AggregatedProduct> aggregateOrders(List<TreasurerData
* @return string that should be written to csv file
*/
public static String generateCsvContent(Map<Integer, AggregatedProduct> map) {

// String csvContent = "Options:\n" + SalesExportSubmission.toString() + "\n\n";
// csvContent += "Event;Organized by;Product;Total income;Total amount;VAT rate\n";
StringBuilder csvContent = new StringBuilder("Event;Organized by;Product;Total income;Total amount;VAT rate;price\n");
for (Map.Entry<Integer, AggregatedProduct> entry : map.entrySet()) {
csvContent.append(entry.getValue().eventTitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class AggregatedProduct {
public Integer totalAmount;
public String vatRate;
public Double price;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
@RequestMapping("/api/v1/orders")
public class OrderRestController {

/** OrderService. */
private final OrderService orderService;

/** PaymentsService. */
private final PaymentsService paymentsService;

/**
* OrderRestController constructor.
*
* @param orderService of type OrderService
* @param paymentsService of type PaymentsService
*/
public OrderRestController(OrderService orderService, PaymentsService paymentsService) {
this.orderService = orderService;
public OrderRestController(PaymentsService paymentsService) {
this.paymentsService = paymentsService;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.wisv.events.core.admin;


public interface Attendence {
public interface Attendance {
long getTicketsCount();
long getScannedCount();
double getPercentageScanned();
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/ch/wisv/events/core/model/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/wisv/events/core/model/ticket/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public boolean canTransfer(Customer currentCustomer, Customer newCustomer, Event
throw new TicketNotTransferableException("Ticket can only be transferred to the owner.");

// Check if ticket is not transferred to the same customer.
if(newCustomer != null && this.owner.equals(newCustomer))
if(this.owner.equals(newCustomer))
throw new TicketNotTransferableException("Sadly you can not transfer a ticket to yourself.. Lezen is adten.");

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ch.wisv.events.core.repository;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.admin.Attendance;
import ch.wisv.events.core.model.event.Event;
import ch.wisv.events.core.model.event.EventStatus;
import ch.wisv.events.core.model.product.Product;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -92,7 +91,8 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
"(Select id from event e where e.ending between :startDate and :endDate) E " +
"ON E.id=EP.event_id) T2 ON T1.product_id=T2.products_id) B " +
"ON A.product_id=B.products_id;", nativeQuery = true) //TODO fix proper date
Attendence getAttendenceFromEventsInDateRange(@Param("startDate") LocalDateTime start, @Param("endDate") LocalDateTime End);
Attendance getAttendanceFromEventsInDateRange(@Param("startDate") LocalDateTime start,
@Param("endDate") LocalDateTime End);

@Query(value =
"select count(*) as ticketsCount, coalesce(sum(status), 0) as scannedCount, coalesce(avg(status),0 ) * 100 as percentageScanned " +
Expand All @@ -101,5 +101,5 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
"(Select :event_id as id) E " +
"ON E.id=EP.event_id) T2 ON T1.product_id=T2.products_id) B " +
"ON A.product_id=B.products_id;", nativeQuery = true)
Attendence getAttendanceFromEvent(@Param("event_id") Integer event_id);
Attendance getAttendanceFromEvent(@Param("event_id") Integer event_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
Expand Down Expand Up @@ -83,11 +81,10 @@ public Customer getCurrentCustomer() {
* @return OIDCIdToken
*/
private DefaultOidcUser getOidcUser(Authentication auth) throws InvalidTokenException {
if (!(auth.getPrincipal() instanceof DefaultOidcUser)) {
if (!(auth.getPrincipal() instanceof DefaultOidcUser oidcUser)) {
throw new InvalidTokenException("Invalid authentication");
}

DefaultOidcUser oidcUser = (DefaultOidcUser) auth.getPrincipal();
if (oidcUser.getEmail() == null) {
throw new InvalidTokenException("Invalid UserInfo object");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ch.wisv.events.core.service.event;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.admin.Attendance;
import ch.wisv.events.core.exception.normal.EventInvalidException;
import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.model.document.Document;
Expand Down Expand Up @@ -124,5 +124,5 @@ public interface EventService {
* @param event Event
* @return Attendance of event
*/
Attendence getAttendance(Event event);
Attendance getAttendance(Event event);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ch.wisv.events.core.service.event;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.admin.Attendance;
import ch.wisv.events.core.exception.normal.EventInvalidException;
import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.exception.normal.ProductInvalidException;
Expand Down Expand Up @@ -217,7 +217,7 @@ public void addDocumentImage(Event event, Document document) {
* @return Attendance of event
*/
@Override
public Attendence getAttendance(Event event) {
public Attendance getAttendance(Event event) {
return eventRepository.getAttendanceFromEvent(event.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public interface OrderValidationService {
* @param order of type Order
* @param customer of type Customer
*
* @throws OrderInvalidException when the Order is invalid for the Customer
* @throws OrderExceedCustomerLimitException when Customer limit will be exceeded
*/
void assertOrderIsValidForCustomer(Order order, Customer customer) throws OrderInvalidException, OrderExceedCustomerLimitException;
void assertOrderIsValidForCustomer(Order order, Customer customer) throws OrderExceedCustomerLimitException;

/**
* Assert if an Order is valid to go to the payment process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<WebhookTask> getAll() {
@Override
public void create(WebhookTask webhookTask) {
webhookTaskRepository.saveAndFlush(webhookTask);
log.info("Created WebhookTask #" + webhookTask.getId() + ": " + webhookTask.toString());
log.info("Created WebhookTask #" + webhookTask.getId() + ": " + webhookTask);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ private boolean isWebhookAuthenticated(Webhook webhook, Object content) {
if (webhook.getLdapGroup() == ch.wisv.events.utils.LdapGroup.BEHEER) {
return true;
} else {
if (content instanceof Event) {
Event event = (Event) content;
if (content instanceof Event event) {

return webhook.getLdapGroup() == event.getOrganizedBy();
} else if (content instanceof Product) {
Product product = (Product) content;
} else if (content instanceof Product product) {

try {
Event event = eventService.getByProduct(product);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,18 @@ public class SalesSellCustomerController {
/** OrderService. */
private final OrderService orderService;

/** OrderValidationService. */
private final OrderValidationService orderValidationService;

/**
* SalesSellCustomerController constructor.
*
* @param orderService of type OrderService
* @param customerService of type CustomerService
* @param orderValidationService of type OrderValidationService
*/
@Autowired
public SalesSellCustomerController(
OrderService orderService, CustomerService customerService, OrderValidationService orderValidationService
OrderService orderService, CustomerService customerService
) {
this.orderService = orderService;
this.customerService = customerService;
this.orderValidationService = orderValidationService;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/ch/wisv/events/sales/service/SalesService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.wisv.events.sales.service;

import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.model.customer.Customer;
import ch.wisv.events.core.model.event.Event;
import ch.wisv.events.core.model.order.Order;
Expand Down Expand Up @@ -32,5 +31,5 @@ public interface SalesService {
* @param event of type Event
* @return list of Orders
*/
List<Order> getAllOrdersByEvent(Event event) throws EventNotFoundException;
List<Order> getAllOrdersByEvent(Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ abstract class WebshopController {
/** Model attr Customer. */
static final String MODEL_ATTR_CUSTOMER = "customer";

/** Model attr Registration. */
static final String MODEL_ATTR_REGISTRATION = "registration";

/** Model attr Order. */
static final String MODEL_ATTR_ORDER = "order";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public interface PaymentsService {
* used to process a webhook request made by mollie to signal that the order status has changed.
*
* @param providerOrderReference reference of the order used by mollie
* @return the updated order
*/
Order updateStatusByProviderReference(String providerOrderReference);
void updateStatusByProviderReference(String providerOrderReference);

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ protected PaymentRequest createMolliePaymentRequestFromOrder(Order order) {


/**
* updates the order status with the given provider reference.
* updates the order status with the given provider reference.
*
* @param providerOrderReference reference of the order used by mollie
* @return the updated order
*/
@Override
public Order updateStatusByProviderReference(String providerOrderReference) {
public void updateStatusByProviderReference(String providerOrderReference) {
try {
Order order = orderService.getByChPaymentsReference(providerOrderReference);
return updateOrder(order);
updateOrder(order);
} catch (OrderNotFoundException e) {
throw new RuntimeException("Order with providerReference " + providerOrderReference + " not found");
}
Expand Down
Loading
Loading