Skip to content

Commit 7e3a1f4

Browse files
authored
Merge branch 'master' into authentication
2 parents 63bc4ba + 2151161 commit 7e3a1f4

File tree

9 files changed

+256
-129
lines changed

9 files changed

+256
-129
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.furizon.backend.feature.pretix.cache.controller;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import net.furizon.backend.infrastructure.pretix.service.PretixInformation;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@Slf4j
11+
@RestController
12+
@RequestMapping("/internal/cache/pretix")
13+
@RequiredArgsConstructor
14+
//TODO: Only admins are allowed to run these!
15+
public class PretixCacheController {
16+
private final PretixInformation pretixService;
17+
18+
@PostMapping("/reload-struct")
19+
public void reloadCache() {
20+
log.info("[PRETIX] Manual reload of cache");
21+
pretixService.resetCache();
22+
}
23+
24+
@PostMapping("/reload-orders")
25+
public void reloadOrders() {
26+
log.info("[PRETIX] Manual reload of orders");
27+
pretixService.reloadAllOrders();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package net.furizon.backend.feature.pretix.order.controller;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import net.furizon.backend.feature.pretix.event.Event;
6+
import net.furizon.backend.feature.pretix.order.dto.OrderWebhookRequest;
7+
import net.furizon.backend.feature.pretix.order.usecase.FetchSingleOrderUseCase;
8+
import net.furizon.backend.infrastructure.pretix.PretixGenericUtils;
9+
import net.furizon.backend.infrastructure.pretix.service.PretixInformation;
10+
import net.furizon.backend.infrastructure.usecase.UseCaseExecutor;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
@Slf4j
17+
@RestController
18+
@RequestMapping("/internal/orders")
19+
@RequiredArgsConstructor
20+
public class OrderController {
21+
private final UseCaseExecutor useCaseExecutor;
22+
23+
private final PretixInformation pretixService;
24+
25+
@PostMapping("/webhook")
26+
public ResponseEntity<Void> pretixWebhook(OrderWebhookRequest request) {
27+
log.info("[PRETIX WEBHOOK] Fetching order {}", request);
28+
var e = pretixService.getCurrentEvent();
29+
if (!e.isPresent()) {
30+
log.error("[PRETIX WEBHOOK] No current event set!");
31+
return ResponseEntity.internalServerError().build();
32+
}
33+
34+
String slug = PretixGenericUtils.buildOrgEventSlug(request.getEvent(), request.getOrganizer());
35+
Event event = e.get();
36+
37+
if (!event.getSlug().equals(slug)) {
38+
log.error("[PRETIX WEBHOOK] Webhook request is not for the current event!");
39+
return ResponseEntity.internalServerError().build();
40+
}
41+
42+
var res = useCaseExecutor.execute(FetchSingleOrderUseCase.class, new FetchSingleOrderUseCase.Input(
43+
event,
44+
request.getCode(),
45+
pretixService
46+
));
47+
return res.isPresent() ? ResponseEntity.ok().build() : ResponseEntity.internalServerError().build();
48+
}
49+
}

application/src/main/java/net/furizon/backend/feature/pretix/order/controller/TestOrderController.java

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.furizon.backend.feature.pretix.order.dto;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import jakarta.validation.constraints.NotEmpty;
6+
import jakarta.validation.constraints.NotNull;
7+
import lombok.Data;
8+
9+
@Data
10+
public class OrderWebhookRequest {
11+
@JsonProperty("notification_id")
12+
private final long notificationId;
13+
14+
@NotNull
15+
@NotEmpty
16+
private final String organizer;
17+
18+
@NotNull
19+
@NotEmpty
20+
private final String event;
21+
22+
@NotNull
23+
@NotEmpty
24+
private final String code;
25+
26+
@NotNull
27+
@NotEmpty
28+
private final String action;
29+
}

application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/FetchSingleOrderUseCase.java

+3
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ public Optional<Order> executor(@NotNull Input input) {
4545

4646
if (pretixOrder.isEmpty()) {
4747
deleteOrderAction.invoke(orderCode);
48+
log.error("[PRETIX] Unable to fetch order: {}@{}", orderCode, eventInfo);
4849
return Optional.empty();
4950
}
5051

5152
var orderOpt = input.pretixInformation.parseOrderFromId(pretixOrder.get(), event);
5253
if (orderOpt.isEmpty()) {
5354
deleteOrderAction.invoke(orderCode);
55+
log.error("[PRETIX] Unable to parse order: {}@{}", orderCode, eventInfo);
5456
return Optional.empty();
5557
}
5658

5759
Order order = orderOpt.get();
60+
log.debug("[PRETIX] Storing / Updating order: {}@{}", orderCode, eventInfo);
5861
insertOrUpdateOrderAction.invoke(order, input.pretixInformation);
5962
return orderOpt;
6063
}

application/src/main/java/net/furizon/backend/infrastructure/pretix/Const.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ public class Const {
2020
public static final String METADATA_ROOM = "room";
2121
public static final String METADATA_ROOM_TYPE_TAG_PREFIX = "room_type_";
2222

23+
2324
public static final String QUESTIONS_FILE_KEEP = "file:keep";
25+
26+
27+
public static final String RELOAD_CACHE_CRONJOB = "0 0 * * * *";
2428
}

application/src/main/java/net/furizon/backend/infrastructure/pretix/PretixConfig.java

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public class PretixConfig implements HttpConfig {
2929
private final int connectionTimeout;
3030

3131
private final boolean enableSync;
32+
33+
@NotNull
34+
private String cacheReloadCronjob;
35+
36+
private int connectionTimeout;
3237

3338
@NotNull
3439
@Override

0 commit comments

Comments
 (0)