Skip to content

Commit

Permalink
Merge branch 'master' into fix/change-password-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdyZ authored Feb 22, 2022
2 parents 3ff318e + 9cd7086 commit 398468d
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 32 deletions.
17 changes: 10 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ buildscript {
}

plugins {
id 'org.springframework.boot' version '2.4.0'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'idea'
id 'eclipse'
id 'jacoco'
id "io.freefair.lombok" version "5.3.0"
id 'com.google.cloud.tools.jib' version '2.7.0'
id 'io.freefair.lombok' version '5.3.0'
id 'com.google.cloud.tools.jib' version '2.8.0'
}

repositories {
Expand All @@ -35,14 +35,13 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.flywaydb:flyway-core:7.3.2'
implementation 'com.google.guava:guava:30.0-jre'
implementation 'org.flywaydb:flyway-core:7.7.2'
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'nl.stil4m:mollie-api:2.7.0'
implementation 'net.logstash.logback:logstash-logback-encoder:4.11'
implementation 'in.ashwanthkumar:slack-java-webhook:0.0.9'
Expand All @@ -51,9 +50,13 @@ dependencies {
runtimeOnly 'org.postgresql:postgresql'

testImplementation 'org.springframework.boot:spring-boot-starter-test'

// rest-assured 4.3+ ships with Groovy 3.0, which doesn't play nice with Gradle (yet)
testImplementation 'io.rest-assured:rest-assured:4.2.1'
testImplementation 'io.rest-assured:json-path:4.2.1'
testImplementation 'io.rest-assured:xml-path:4.2.1'

developmentOnly 'org.springframework.boot:spring-boot-devtools'
}

jib {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ch.wisv.areafiftylan.exception.OrderNotFoundException;
import ch.wisv.areafiftylan.exception.TicketNotFoundException;
import ch.wisv.areafiftylan.exception.TicketUnavailableException;
import ch.wisv.areafiftylan.products.model.order.OrderStatus;
import ch.wisv.areafiftylan.products.model.AssignDTO;
import ch.wisv.areafiftylan.products.model.TicketDTO;
import ch.wisv.areafiftylan.products.model.order.Order;
Expand Down Expand Up @@ -113,6 +114,13 @@ public Order getOrderById(@PathVariable Long orderId) {
return orderService.getOrderById(orderId);
}

@PreAuthorize("hasRole('ADMIN')")
@DeleteMapping("/{orderId}")
public ResponseEntity<?> deleteOrder(@PathVariable Long orderId) {
orderService.removeOrder(orderId);
return createResponseEntity(HttpStatus.OK, "Order successfully deleted.");
}

/**
* Adds a ticket to an existing Order. It's possible to buy serveral ticket at once. After the order has been
* created, tickets can be added by POSTing more TicketDTOs to this location.
Expand Down Expand Up @@ -263,7 +271,11 @@ public ResponseEntity<?> handleMollieTestCall() {
@JsonView(View.OrderOverview.class)
@GetMapping("/{orderId}/status")
public ResponseEntity<?> updateOrderStatusManual(@PathVariable long orderId) {
Order order = orderService.updateOrderStatusByOrderId(orderId);
Order order = orderService.getOrderById(orderId);
if (order.getStatus() == OrderStatus.PAID) {
return createResponseEntity(HttpStatus.OK, "Order status updated", order);
}
order = orderService.updateOrderStatusByOrderId(orderId);

log.info(controllerMarker, "Order {} updated", order.getId(), StructuredArguments.v("order_id", order.getId()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public Collection<Ticket> getAllTickets() {
return ticketService.getAllTickets();
}

@PreAuthorize("hasRole('ADMIN')")
@DeleteMapping("{ticketId}")
public ResponseEntity<?> deleteTicket(@PathVariable Long ticketId) {
ticketService.removeTicket(ticketId);
return createResponseEntity(HttpStatus.OK, "Ticket successfully deleted.");
}

@PreAuthorize("hasRole('ADMIN')")
@GetMapping("/transport")
public Collection<Ticket> getAllTicketsWithTransport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public float getAmount() {
return price;
}

@JsonView(View.OrderOverview.class)
public int getAmountTickets() {
return tickets.size();
}

public void setUser(User user) {
this.user = user;
if (user != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface OrderService {
*/
Order create(String type, List<String> options);

/**
* Delete the Order with orderId
*/
public Order removeOrder(Long orderId);

/**
* Add a ticket to an order. Checks if a ticket is available first
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class OrderServiceImpl implements OrderService {
private final PaymentService paymentService;
private final MailService mailService;

@Value("${a5l.paymentReturnUrl}")
private String RETURN_URL;

@Value("${a5l.orderLimit}")
private int ORDER_LIMIT;

Expand Down Expand Up @@ -123,6 +126,18 @@ public Order create(String type, List<String> options) {
return orderRepository.save(order);
}

@Override
public Order removeOrder(Long orderId) {
if (orderId == null) {
throw new IllegalArgumentException("No ID given for deleting the order.");
}

Order order = getOrderById(orderId);
orderRepository.delete(order);

return order;
}

@Override
public Order addTicketToOrder(Long orderId, String type, List<String> options) {
Order order = getOrderById(orderId);
Expand Down Expand Up @@ -194,12 +209,18 @@ public Order removeTicketFromOrder(Long orderId, Long ticketId) {
@Override
public String requestPayment(Long orderId) {
Order order = getOrderById(orderId);
if (order.getAmount() == 0) {
if (order.getAmountTickets() == 0) {
throw new IllegalStateException("Order can not be empty");
}
if (order.getStatus() != OrderStatus.ASSIGNED) {
throw new UnassignedOrderException(order.getId());
}
if (order.getAmount() == 0) {
order.setStatus(OrderStatus.PAID);
validateTicketsIfPaid(order);
orderRepository.save(order);
return RETURN_URL + "?order=" + orderId;
}

return paymentService.registerOrder(order);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(@Nonnull CorsRegistry registry) {
registry.addMapping("/**").exposedHeaders("X-Auth-Token");
registry.addMapping("/**").exposedHeaders("X-Auth-Token").allowedMethods("*");
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class UserProfileRestController {
private boolean allowedToEditProfile(User user, ProfileDTO input) {
boolean isUserCheckedIn = rfidService.isOwnerLinked(user.getEmail());
LocalDate currentBirthday = user.getProfile().getBirthday();
boolean isDateChanged = !currentBirthday.equals(input.getBirthday());
boolean isDateChanged = !input.getBirthday().equals(currentBirthday);


return !isDateChanged || !isUserCheckedIn;
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/ch/wisv/areafiftylan/utils/TestDataRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
import ch.wisv.areafiftylan.products.model.Ticket;
import ch.wisv.areafiftylan.products.model.TicketOption;
import ch.wisv.areafiftylan.products.model.TicketType;
import ch.wisv.areafiftylan.products.model.order.OrderStatus;
import ch.wisv.areafiftylan.products.service.repository.OrderRepository;
import ch.wisv.areafiftylan.products.service.repository.TicketOptionRepository;
import ch.wisv.areafiftylan.products.service.repository.TicketRepository;
import ch.wisv.areafiftylan.products.service.repository.TicketTypeRepository;
import ch.wisv.areafiftylan.products.service.OrderService;
import ch.wisv.areafiftylan.products.model.order.Order;
import ch.wisv.areafiftylan.seats.model.SeatGroupDTO;
import ch.wisv.areafiftylan.seats.service.SeatService;
import ch.wisv.areafiftylan.teams.model.Team;
Expand Down Expand Up @@ -80,6 +84,8 @@ public class TestDataRunner {
private final FaqRepository faqRepository;
private final SponsorRepository sponsorRepository;
private final TournamentRepository tournamentRepository;
private final OrderService orderService;
private final OrderRepository orderRepository;

@Autowired
public TestDataRunner(UserRepository accountRepository, TicketRepository ticketRepository,
Expand All @@ -88,7 +94,7 @@ public TestDataRunner(UserRepository accountRepository, TicketRepository ticketR
RFIDLinkRepository rfidLinkRepository, PossibleConsumptionsRepository consumptionsRepository,
ConsumptionService consumptionService, BannerRepository bannerRepository, CommitteeRepository committeeRepository,
FaqRepository faqRepository, SponsorRepository sponsorRepository,
TournamentRepository tournamentRepository) {
TournamentRepository tournamentRepository, OrderService orderService, OrderRepository orderRepository) {
this.accountRepository = accountRepository;
this.ticketRepository = ticketRepository;
this.seatService = seatService;
Expand All @@ -103,6 +109,9 @@ public TestDataRunner(UserRepository accountRepository, TicketRepository ticketR
this.faqRepository = faqRepository;
this.sponsorRepository = sponsorRepository;
this.tournamentRepository = tournamentRepository;
this.orderService = orderService;
this.orderRepository = orderRepository;

}

@EventListener(ApplicationStartedEvent.class)
Expand Down Expand Up @@ -269,6 +278,17 @@ public void insertTestData() {
tournament(TournamentType.UNOFFICIAL, "JD", "images-optimized/unofficial/justdance.jpg", "2 V 2", "Just Dance",
"Just Dance is about dancing.", Collections.singletonList("Nothing."), sogeti);
//endregion Web Data
//region Orders
Order order_admin = orderService.create("Normal", null);
orderService.assignOrderToUser(order_admin.getId(), userAdmin.getId());
order_admin.setStatus(OrderStatus.PAID);
orderRepository.save(order_admin);

Order order_normal = orderService.create("Normal", null);
orderService.assignOrderToUser(order_normal.getId(), userNormal.getId());
order_normal.setStatus(OrderStatus.PAID);
orderRepository.save(order_admin);
//endregion Orders
}

private CommitteeMember committeeMember(Long position, String function, String name, String icon) {
Expand Down
Loading

0 comments on commit 398468d

Please sign in to comment.