diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/event/action/insert/JooqInsertNewEventAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/event/action/insert/JooqInsertNewEventAction.java index 6a8aea2..af3e950 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/event/action/insert/JooqInsertNewEventAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/event/action/insert/JooqInsertNewEventAction.java @@ -47,7 +47,7 @@ public void invoke(@NotNull Event event) { event.getPublicUrl(), Optional .ofNullable(event.getEventNames()) - .map(jsonSerializer::serialize) + .map(jsonSerializer::serializeAsString) .orElse(null) ) ); diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/event/action/update/JooqUpdateEventAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/event/action/update/JooqUpdateEventAction.java index 1325680..ac440c0 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/event/action/update/JooqUpdateEventAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/event/action/update/JooqUpdateEventAction.java @@ -33,7 +33,7 @@ public void invoke(@NotNull Event event) { .set(EVENTS.EVENT_PUBLIC_URL, event.getPublicUrl()) .set(EVENTS.EVENT_NAMES, Optional .ofNullable(event.getEventNames()) - .map(jsonSerializer::serialize) + .map(jsonSerializer::serializeAsString) .orElse(null)) .set(EVENTS.EVENT_DATE_TO, Optional .ofNullable(event.getDateTo()) diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/Order.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/Order.java index ed281bb..f7c8434 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/Order.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/Order.java @@ -22,6 +22,7 @@ import java.time.LocalDate; import java.time.LocalTime; import java.time.ZonedDateTime; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -139,6 +140,39 @@ public long getDailyDaysBitmask() { return ret; } + public List getAllAnswers(@NotNull PretixInformation pretixInformation) { + final var list = new ArrayList(); + final var answers = getAnswers(); + for (String key : answers.keySet()) { + final var questionId = pretixInformation.getQuestionIdFromIdentifier(key); + if (questionId.isEmpty()) { + continue; + } + + int id = questionId.get(); + var type = pretixInformation.getQuestionTypeFromId(id); + if (type.isEmpty()) { + continue; + } + Object o = answers.get(key); + String out = switch (type.get()) { + case NUMBER -> Float.toString((float) o); + case STRING_ONE_LINE, FILE, COUNTRY_CODE, PHONE_NUMBER, STRING_MULTI_LINE, LIST_SINGLE_CHOICE -> + (String) o; + case BOOLEAN -> ((boolean) o) ? "True" : "False"; //fuck python + case LIST_MULTIPLE_CHOICE -> String.join(", ", (String[]) o); + case DATE, TIME -> o.toString(); + case DATE_TIME -> ((ZonedDateTime) o).format(PretixGenericUtils.PRETIX_DATETIME_FORMAT); + }; + + if (out != null && !(out = out.strip()).isEmpty()) { + list.add(new PretixAnswer(id, out)); + } + } + + return list; + } + public static class OrderBuilder { public OrderBuilder dailyDays(Set days) { dailyDays = days; @@ -160,27 +194,31 @@ public OrderBuilder answers(@NotNull List answers, @NotNull Pretix for (PretixAnswer answer : answers) { int questionId = answer.getQuestionId(); var identifier = pi.getQuestionIdentifierFromId(questionId); - if (identifier.isPresent()) { - String answerIdentifier = identifier.get(); - String value = answer.getAnswer(); - if (value != null) { - var type = pi.getQuestionTypeFromId(questionId); - if (type.isPresent()) { - Object o = switch (type.get()) { - case NUMBER -> Float.parseFloat(value); - case STRING_ONE_LINE, STRING_MULTI_LINE, COUNTRY_CODE, PHONE_NUMBER, - LIST_SINGLE_CHOICE -> value; - case BOOLEAN -> value.equalsIgnoreCase("true") - || value.equalsIgnoreCase("yes"); - case LIST_MULTIPLE_CHOICE -> value.split(", "); - case FILE -> Const.QUESTIONS_FILE_KEEP; - case DATE -> LocalDate.parse(value); - case TIME -> LocalTime.parse(value); - case DATE_TIME -> ZonedDateTime.parse(value, PretixGenericUtils.PRETIX_DATETIME_FORMAT); - }; - this.answers.put(answerIdentifier, o); - } - } + if (identifier.isEmpty()) { + throw new IllegalArgumentException("Answer identifier is empty"); + } + + String answerIdentifier = identifier.get(); + String value = answer.getAnswer(); + if (value == null) { + throw new IllegalArgumentException("Answer " + answerIdentifier + " has null value"); + } + + var type = pi.getQuestionTypeFromId(questionId); + if (type.isPresent()) { + Object o = switch (type.get()) { + case NUMBER -> Float.parseFloat(value); + case STRING_ONE_LINE, STRING_MULTI_LINE, COUNTRY_CODE, PHONE_NUMBER, + LIST_SINGLE_CHOICE -> value; + case BOOLEAN -> value.equalsIgnoreCase("true") + || value.equalsIgnoreCase("yes"); + case LIST_MULTIPLE_CHOICE -> value.split(", "); + case FILE -> Const.QUESTIONS_FILE_KEEP; + case DATE -> LocalDate.parse(value); + case TIME -> LocalTime.parse(value); + case DATE_TIME -> ZonedDateTime.parse(value, PretixGenericUtils.PRETIX_DATETIME_FORMAT); + }; + this.answers.put(answerIdentifier, o); } } return this; diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/addAnswer/AddPretixAnswerAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/addAnswer/AddPretixAnswerAction.java deleted file mode 100644 index 44aca85..0000000 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/addAnswer/AddPretixAnswerAction.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.furizon.backend.feature.pretix.order.action.addAnswer; - -import net.furizon.backend.feature.pretix.event.Event; -import net.furizon.backend.feature.pretix.order.Order; -import org.jetbrains.annotations.NotNull; - -public interface AddPretixAnswerAction { - boolean invoke( - @NotNull final Order order, - @NotNull final Event.OrganizerAndEventPair pair - ); -} diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/InsertNewOrderAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/InsertNewOrderAction.java index e1b65e5..34c3c39 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/InsertNewOrderAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/InsertNewOrderAction.java @@ -1,8 +1,12 @@ package net.furizon.backend.feature.pretix.order.action.insertNewOrder; import net.furizon.backend.feature.pretix.order.Order; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import org.jetbrains.annotations.NotNull; public interface InsertNewOrderAction { - void invoke(@NotNull Order order); + void invoke( + @NotNull final Order order, + @NotNull final PretixInformation pretixInformation + ); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/JooqInsertNewOrderAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/JooqInsertNewOrderAction.java index e279807..8a2708b 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/JooqInsertNewOrderAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/insertNewOrder/JooqInsertNewOrderAction.java @@ -2,7 +2,8 @@ import lombok.RequiredArgsConstructor; import net.furizon.backend.feature.pretix.order.Order; -import net.furizon.backend.feature.pretix.order.util.OrderTransformationUtil; +import net.furizon.backend.infrastructure.jackson.JsonSerializer; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import net.furizon.jooq.infrastructure.command.SqlCommand; import org.jetbrains.annotations.NotNull; import org.jooq.util.postgres.PostgresDSL; @@ -15,10 +16,13 @@ public class JooqInsertNewOrderAction implements InsertNewOrderAction { private final SqlCommand command; - private final OrderTransformationUtil orderTransformationUtil; + private final JsonSerializer jsonSerializer; @Override - public void invoke(@NotNull Order order) { + public void invoke( + @NotNull final Order order, + @NotNull final PretixInformation pretixInformation + ) { command.execute( PostgresDSL .insertInto( @@ -35,7 +39,7 @@ public void invoke(@NotNull Order order) { ORDERS.ORDER_ANSWERS_MAIN_POSITION_ID, //ORDERS.USER_ID, TODO //ORDERS.EVENT_ID, - ORDERS.ORDER_ANSWERS + ORDERS.ORDER_ANSWERS_JSON ) .values( order.getCode(), @@ -50,7 +54,7 @@ public void invoke(@NotNull Order order) { order.getAnswersMainPositionId(), //order.getOrderOwner(), //order.getOrderEvent(), - orderTransformationUtil.getAnswersAsJson(order) + jsonSerializer.serializeAsJson(order.getAllAnswers(pretixInformation)) ) ); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/pushAnswer/PushPretixAnswerAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/pushAnswer/PushPretixAnswerAction.java new file mode 100644 index 0000000..2d2535c --- /dev/null +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/pushAnswer/PushPretixAnswerAction.java @@ -0,0 +1,12 @@ +package net.furizon.backend.feature.pretix.order.action.pushAnswer; + +import net.furizon.backend.feature.pretix.order.Order; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; +import org.jetbrains.annotations.NotNull; + +public interface PushPretixAnswerAction { + boolean invoke( + @NotNull final Order order, + @NotNull final PretixInformation pretixInformation + ); +} diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/addAnswer/RestAddPretixAnswerAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/pushAnswer/RestPushPretixAnswerAction.java similarity index 72% rename from application/src/main/java/net/furizon/backend/feature/pretix/order/action/addAnswer/RestAddPretixAnswerAction.java rename to application/src/main/java/net/furizon/backend/feature/pretix/order/action/pushAnswer/RestPushPretixAnswerAction.java index 763e8e3..061feb4 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/addAnswer/RestAddPretixAnswerAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/pushAnswer/RestPushPretixAnswerAction.java @@ -1,13 +1,13 @@ -package net.furizon.backend.feature.pretix.order.action.addAnswer; +package net.furizon.backend.feature.pretix.order.action.pushAnswer; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import net.furizon.backend.feature.pretix.event.Event; import net.furizon.backend.feature.pretix.order.Order; -import net.furizon.backend.feature.pretix.order.util.OrderTransformationUtil; +import net.furizon.backend.feature.pretix.order.dto.PushPretixAnswerRequest; import net.furizon.backend.infrastructure.http.client.HttpClient; import net.furizon.backend.infrastructure.http.client.HttpRequest; import net.furizon.backend.infrastructure.pretix.PretixConfig; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpMethod; @@ -19,25 +19,25 @@ @Component @RequiredArgsConstructor @Slf4j -public class RestAddPretixAnswerAction implements AddPretixAnswerAction { +public class RestPushPretixAnswerAction implements PushPretixAnswerAction { @Qualifier("pretixHttpClient") private final HttpClient pretixHttpClient; - private final OrderTransformationUtil orderTransformation; - @Override public boolean invoke( @NotNull final Order order, - @NotNull final Event.OrganizerAndEventPair pair + @NotNull final PretixInformation pretixInformation ) { - final var request = HttpRequest.create() + final var pair = order.getOrderEvent().getOrganizerAndEventPair(); + final var request = HttpRequest.create() .method(HttpMethod.PATCH) .path("/organizers/{organizer}/events/{event}/orderpositions/{position}/") .uriVariable("organizer", pair.getOrganizer()) .uriVariable("event", pair.getEvent()) .uriVariable("position", String.valueOf(order.getAnswersMainPositionId())) .contentType(MediaType.APPLICATION_JSON) - .body(orderTransformation.getAnswersAsJson(order)) + .body(new PushPretixAnswerRequest(order.getAllAnswers(pretixInformation))) + .responseType(Void.class) .build(); try { return pretixHttpClient.send(PretixConfig.class, request).getStatusCode() == HttpStatus.OK; diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/JooqUpdateOrderAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/JooqUpdateOrderAction.java index 33f24b3..298b8c7 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/JooqUpdateOrderAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/JooqUpdateOrderAction.java @@ -2,7 +2,8 @@ import lombok.RequiredArgsConstructor; import net.furizon.backend.feature.pretix.order.Order; -import net.furizon.backend.feature.pretix.order.util.OrderTransformationUtil; +import net.furizon.backend.infrastructure.jackson.JsonSerializer; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import net.furizon.jooq.infrastructure.command.SqlCommand; import org.jetbrains.annotations.NotNull; import org.jooq.util.postgres.PostgresDSL; @@ -15,10 +16,13 @@ public class JooqUpdateOrderAction implements UpdateOrderAction { private final SqlCommand command; - private final OrderTransformationUtil orderTransformationUtil; + private final JsonSerializer serializer; @Override - public void invoke(@NotNull Order order) { + public void invoke( + @NotNull final Order order, + @NotNull final PretixInformation pretixInformation + ) { command.execute( PostgresDSL .update(ORDERS) @@ -33,7 +37,7 @@ public void invoke(@NotNull Order order) { .set(ORDERS.ORDER_ANSWERS_MAIN_POSITION_ID, order.getAnswersMainPositionId()) //.set(ORDERS.USER_ID, order.getOrderOwner()) //.set(ORDERS.EVENT_ID, order.getOrderEvent()) - .set(ORDERS.ORDER_ANSWERS, orderTransformationUtil.getAnswersAsJson(order)) + .set(ORDERS.ORDER_ANSWERS_JSON, serializer.serializeAsJson(order.getAllAnswers(pretixInformation))) .where(ORDERS.ORDER_CODE.eq(order.getCode())) ); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/UpdateOrderAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/UpdateOrderAction.java index 0c76db4..837e77a 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/UpdateOrderAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/updateOrder/UpdateOrderAction.java @@ -1,8 +1,12 @@ package net.furizon.backend.feature.pretix.order.action.updateOrder; import net.furizon.backend.feature.pretix.order.Order; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import org.jetbrains.annotations.NotNull; public interface UpdateOrderAction { - void invoke(@NotNull Order order); + void invoke( + @NotNull final Order order, + @NotNull final PretixInformation pretixInformation + ); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/JooqUpsertOrderAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/JooqUpsertOrderAction.java index eb7f001..dba19c9 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/JooqUpsertOrderAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/JooqUpsertOrderAction.java @@ -2,7 +2,8 @@ import lombok.RequiredArgsConstructor; import net.furizon.backend.feature.pretix.order.Order; -import net.furizon.backend.feature.pretix.order.util.OrderTransformationUtil; +import net.furizon.backend.infrastructure.jackson.JsonSerializer; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import net.furizon.jooq.infrastructure.command.SqlCommand; import org.jetbrains.annotations.NotNull; import org.jooq.util.postgres.PostgresDSL; @@ -15,10 +16,10 @@ public class JooqUpsertOrderAction implements UpsertOrderAction { private final SqlCommand command; - private final OrderTransformationUtil orderTransformationUtil; + private final JsonSerializer jsonSerializer; @Override - public void invoke(@NotNull Order order) { + public void invoke(@NotNull Order order, @NotNull PretixInformation pretixInformation) { String code = order.getCode(); short orderStatus = (short) order.getOrderStatus().ordinal(); short sponsorship = (short) order.getSponsorship().ordinal(); @@ -31,7 +32,7 @@ public void invoke(@NotNull Order order) { int answersMainPositionId = order.getAnswersMainPositionId(); //User user = order.getOrderOwner(); //Event event = order.getOrderEvent(); - String answersJson = orderTransformationUtil.getAnswersAsJson(order); + final var answers = jsonSerializer.serializeAsJson(order.getAllAnswers(pretixInformation)); command.execute( @@ -50,7 +51,7 @@ public void invoke(@NotNull Order order) { ORDERS.ORDER_ANSWERS_MAIN_POSITION_ID, //ORDERS.USER_ID, TODO //ORDERS.EVENT_ID, - ORDERS.ORDER_ANSWERS + ORDERS.ORDER_ANSWERS_JSON ) .values( code, @@ -65,7 +66,7 @@ public void invoke(@NotNull Order order) { answersMainPositionId, //user, //event, - answersJson + answers ) .onConflict(ORDERS.ORDER_CODE) .doUpdate() @@ -80,7 +81,7 @@ public void invoke(@NotNull Order order) { .set(ORDERS.ORDER_ANSWERS_MAIN_POSITION_ID, answersMainPositionId) //.set(ORDERS.USER_ID, user) //.set(ORDERS.EVENT_ID, event) - .set(ORDERS.ORDER_ANSWERS, answersJson) + .set(ORDERS.ORDER_ANSWERS_JSON, answers) ); } } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/UpsertOrderAction.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/UpsertOrderAction.java index 677e532..8a952d7 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/UpsertOrderAction.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/action/upsertOrder/UpsertOrderAction.java @@ -1,8 +1,9 @@ package net.furizon.backend.feature.pretix.order.action.upsertOrder; import net.furizon.backend.feature.pretix.order.Order; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import org.jetbrains.annotations.NotNull; public interface UpsertOrderAction { - void invoke(@NotNull Order order); + void invoke(@NotNull Order order, @NotNull PretixInformation pretixInformation); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/controller/TestOrderController.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/controller/TestOrderController.java new file mode 100644 index 0000000..26461bc --- /dev/null +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/controller/TestOrderController.java @@ -0,0 +1,34 @@ +package net.furizon.backend.feature.pretix.order.controller; + +import lombok.RequiredArgsConstructor; +import net.furizon.backend.feature.pretix.order.action.pushAnswer.PushPretixAnswerAction; +import net.furizon.backend.feature.pretix.order.finder.OrderFinder; +import net.furizon.backend.infrastructure.pretix.service.PretixInformation; +import net.furizon.backend.infrastructure.web.exception.ApiException; +import net.furizon.backend.service.pretix.PretixService; +import org.jetbrains.annotations.NotNull; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/internal/orders") +@RequiredArgsConstructor +public class TestOrderController { + private final PushPretixAnswerAction pushPretixAnswerAction; + + private final OrderFinder orderFinder; + + private final PretixInformation pretixService; + + @PutMapping("/{code}") + public Boolean pushAnswer(@PathVariable @NotNull String code) { + final var order = orderFinder.findOrderByCode(code); + if (order == null) { + throw new ApiException("No order found with code " + code); + } + + return pushPretixAnswerAction.invoke(order, pretixService); + } +} diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/dto/PushPretixAnswerRequest.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/dto/PushPretixAnswerRequest.java new file mode 100644 index 0000000..acee675 --- /dev/null +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/dto/PushPretixAnswerRequest.java @@ -0,0 +1,11 @@ +package net.furizon.backend.feature.pretix.order.dto; + +import lombok.Data; +import net.furizon.backend.feature.pretix.order.PretixAnswer; + +import java.util.List; + +@Data +public class PushPretixAnswerRequest { + private final List answers; +} diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/finder/JooqOrderFinder.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/finder/JooqOrderFinder.java index cbf5e7a..8074c2d 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/finder/JooqOrderFinder.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/finder/JooqOrderFinder.java @@ -9,8 +9,9 @@ import org.jooq.util.postgres.PostgresDSL; import org.springframework.stereotype.Component; +import static net.furizon.jooq.generated.Tables.EVENTS; import static net.furizon.jooq.generated.Tables.ORDERS; - +import static net.furizon.jooq.generated.Tables.USERS; @Component @RequiredArgsConstructor @@ -33,11 +34,20 @@ public class JooqOrderFinder implements OrderFinder { ORDERS.ORDER_SECRET, ORDERS.HAS_MEMBERSHIP, ORDERS.ORDER_ANSWERS_MAIN_POSITION_ID, - //ORDERS.USER_ID, TODO - //ORDERS.EVENT_ID, - ORDERS.ORDER_ANSWERS + ORDERS.ORDER_ANSWERS_JSON, + USERS.USER_ID, + EVENTS.EVENT_SLUG, + EVENTS.EVENT_DATE_TO, + EVENTS.EVENT_DATE_FROM, + EVENTS.EVENT_IS_CURRENT, + EVENTS.EVENT_PUBLIC_URL, + EVENTS.EVENT_NAMES ) .from(ORDERS) + .leftOuterJoin(USERS) + .on(USERS.USER_ID.eq(ORDERS.USER_ID)) + .leftOuterJoin(EVENTS) + .on(EVENTS.EVENT_SLUG.eq(ORDERS.EVENT_ID)) .where(ORDERS.ORDER_CODE.eq(code)) ).mapOrNull(orderMapper::map); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/mapper/JooqOrderMapper.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/mapper/JooqOrderMapper.java index e8c4cc3..8f04e1c 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/mapper/JooqOrderMapper.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/mapper/JooqOrderMapper.java @@ -4,8 +4,11 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; +import net.furizon.backend.feature.pretix.event.Event; +import net.furizon.backend.feature.pretix.event.mapper.JooqEventMapper; import net.furizon.backend.feature.pretix.order.Order; import net.furizon.backend.feature.pretix.order.PretixAnswer; +import net.furizon.backend.feature.user.mapper.JooqUserMapper; import net.furizon.backend.infrastructure.pretix.model.ExtraDays; import net.furizon.backend.infrastructure.pretix.model.OrderStatus; import net.furizon.backend.infrastructure.pretix.model.Sponsorship; @@ -17,20 +20,24 @@ import java.util.List; import static net.furizon.jooq.generated.Tables.ORDERS; +import static net.furizon.jooq.generated.Tables.USERS; @Component @RequiredArgsConstructor public class JooqOrderMapper { - private final TypeReference> ref = new TypeReference<>() {}; + private final TypeReference> ref = new TypeReference<>() { + }; private final ObjectMapper objectMapper; private final PretixInformation pretixInformation; + private final JooqEventMapper jooqEventMapper; + @NotNull public Order map(Record record) { try { - final var answerList = objectMapper.readValue(record.get(ORDERS.ORDER_ANSWERS), ref); + final var answerList = objectMapper.readValue(record.get(ORDERS.ORDER_ANSWERS_JSON).data(), ref); return Order.builder() .code(record.get(ORDERS.ORDER_CODE)) .orderStatus(OrderStatus.values()[record.get(ORDERS.ORDER_STATUS)]) @@ -42,8 +49,8 @@ public Order map(Record record) { .pretixOrderSecret(record.get(ORDERS.ORDER_SECRET)) .hasMembership(record.get(ORDERS.HAS_MEMBERSHIP)) .answersMainPositionId(record.get(ORDERS.ORDER_ANSWERS_MAIN_POSITION_ID)) - //.orderOwner() TODO - //.orderEvent() TODO + .orderOwner(record.get(USERS.USER_ID) != null ? JooqUserMapper.map(record) : null) + .orderEvent(jooqEventMapper.map(record)) .answers(answerList, pretixInformation) .build(); } catch (JsonProcessingException e) { diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/FetchSingleOrderUseCase.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/FetchSingleOrderUseCase.java index ad98325..2675b71 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/FetchSingleOrderUseCase.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/FetchSingleOrderUseCase.java @@ -49,14 +49,14 @@ public Optional executor(@NotNull Input input) { } var orderOpt = input.pretixInformation.parseOrderFromId(pretixOrder.get(), event); - if (orderOpt.isPresent()) { - Order order = orderOpt.get(); - insertOrUpdateOrderAction.invoke(order); - return Optional.of(order); - } else { + if (orderOpt.isEmpty()) { deleteOrderAction.invoke(orderCode); return Optional.empty(); } + + Order order = orderOpt.get(); + insertOrUpdateOrderAction.invoke(order, input.pretixInformation); + return orderOpt; } public record Input( diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/PushAnswersToPretixUseCase.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/PushAnswersToPretixUseCase.java index b8e7668..9a8cca6 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/PushAnswersToPretixUseCase.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/PushAnswersToPretixUseCase.java @@ -4,7 +4,7 @@ import lombok.extern.slf4j.Slf4j; import net.furizon.backend.feature.pretix.event.Event; import net.furizon.backend.feature.pretix.order.Order; -import net.furizon.backend.feature.pretix.order.action.addAnswer.AddPretixAnswerAction; +import net.furizon.backend.feature.pretix.order.action.pushAnswer.PushPretixAnswerAction; import net.furizon.backend.infrastructure.pretix.service.PretixInformation; import net.furizon.backend.infrastructure.usecase.UseCase; import org.jetbrains.annotations.NotNull; @@ -15,14 +15,14 @@ @Slf4j public class PushAnswersToPretixUseCase implements UseCase { @NotNull - private final AddPretixAnswerAction addPretixAnswerAction; + private final PushPretixAnswerAction pushPretixAnswerAction; @NotNull @Override public Boolean executor(@NotNull PushAnswersToPretixUseCase.Input input) { - return addPretixAnswerAction.invoke( + return pushPretixAnswerAction.invoke( input.order, - input.event.getOrganizerAndEventPair() + input.pretixInformation ); } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/ReloadOrdersUseCase.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/ReloadOrdersUseCase.java index 1400972..048ddce 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/ReloadOrdersUseCase.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/order/usecase/ReloadOrdersUseCase.java @@ -49,7 +49,7 @@ public Boolean executor(@NotNull Input input) { Order order = orderOpt.get(); OrderStatus os = order.getOrderStatus(); if (os == OrderStatus.PENDING || os == OrderStatus.PAID) { - insertOrUpdateOrderAction.invoke(order); + insertOrUpdateOrderAction.invoke(order, input.pretixInformation); shouldDelete = false; } } diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/order/util/OrderTransformationUtil.java b/application/src/main/java/net/furizon/backend/feature/pretix/order/util/OrderTransformationUtil.java deleted file mode 100644 index cfafe1d..0000000 --- a/application/src/main/java/net/furizon/backend/feature/pretix/order/util/OrderTransformationUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.furizon.backend.feature.pretix.order.util; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import net.furizon.backend.feature.pretix.order.Order; -import net.furizon.backend.feature.pretix.order.PretixAnswer; -import net.furizon.backend.infrastructure.pretix.PretixGenericUtils; -import net.furizon.backend.infrastructure.pretix.service.PretixInformation; -import org.jetbrains.annotations.NotNull; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - -import java.time.ZonedDateTime; -import java.util.ArrayList; - -@Component -@RequiredArgsConstructor -@Slf4j -public class OrderTransformationUtil { - private final ObjectMapper objectMapper; - - // @Lazy annotation will help here to avoid - //circular-injection, but let's avoid to reuse it - @Lazy - private final PretixInformation pretixInformation; - - @NotNull - public String getAnswersAsJson(@NotNull Order order) { - final var list = new ArrayList(); - final var answers = order.getAnswers(); - - for (String key : answers.keySet()) { - Object o = answers.get(key); - var identifierOpt = pretixInformation.getQuestionIdFromIdentifier(key); - if (identifierOpt.isPresent()) { - int id = identifierOpt.get(); - var type = pretixInformation.getQuestionTypeFromId(id); - if (type.isPresent()) { - String out = switch (type.get()) { - case NUMBER -> Float.toString((float) o); - case STRING_ONE_LINE, FILE, COUNTRY_CODE, PHONE_NUMBER, STRING_MULTI_LINE, LIST_SINGLE_CHOICE -> - (String) o; - case BOOLEAN -> ((boolean) o) ? "True" : "False"; //fuck python - case LIST_MULTIPLE_CHOICE -> String.join(", ", (String[]) o); - case DATE, TIME -> o.toString(); - case DATE_TIME -> ((ZonedDateTime) o).format(PretixGenericUtils.PRETIX_DATETIME_FORMAT); - }; - - if (out != null && !(out = out.strip()).isEmpty()) { - list.add(new PretixAnswer(id, out)); - } - } - } - } - - try { - return objectMapper.writeValueAsString(list); - } catch (JsonProcessingException e) { - log.error("Error while serializing answers for order {}", order.getCode(), e); - return "[]"; - } - } -} diff --git a/application/src/main/java/net/furizon/backend/feature/pretix/organizer/controller/OrganizerController.java b/application/src/main/java/net/furizon/backend/feature/pretix/organizer/controller/OrganizerController.java index 929fe0f..7ec9d88 100644 --- a/application/src/main/java/net/furizon/backend/feature/pretix/organizer/controller/OrganizerController.java +++ b/application/src/main/java/net/furizon/backend/feature/pretix/organizer/controller/OrganizerController.java @@ -15,7 +15,7 @@ public class OrganizerController { private final OrganizersFinder finder; @GetMapping - PretixPaging organizers() { + public PretixPaging organizers() { return finder.getPagedOrganizers(1); } } diff --git a/application/src/main/java/net/furizon/backend/infrastructure/jackson/JsonSerializer.java b/application/src/main/java/net/furizon/backend/infrastructure/jackson/JsonSerializer.java index 04a311b..d13c0b5 100644 --- a/application/src/main/java/net/furizon/backend/infrastructure/jackson/JsonSerializer.java +++ b/application/src/main/java/net/furizon/backend/infrastructure/jackson/JsonSerializer.java @@ -1,8 +1,12 @@ package net.furizon.backend.infrastructure.jackson; import org.jetbrains.annotations.NotNull; +import org.jooq.JSON; public interface JsonSerializer { @NotNull - String serialize(Object object); + String serializeAsString(Object object); + + @NotNull + JSON serializeAsJson(Object object); } diff --git a/application/src/main/java/net/furizon/backend/infrastructure/jackson/SimpleJsonSerializer.java b/application/src/main/java/net/furizon/backend/infrastructure/jackson/SimpleJsonSerializer.java index 5e1f0f1..e67df31 100644 --- a/application/src/main/java/net/furizon/backend/infrastructure/jackson/SimpleJsonSerializer.java +++ b/application/src/main/java/net/furizon/backend/infrastructure/jackson/SimpleJsonSerializer.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; +import org.jooq.JSON; import org.springframework.stereotype.Component; @Component @@ -14,7 +15,7 @@ public class SimpleJsonSerializer implements JsonSerializer { private final ObjectMapper objectMapper; @Override - public @NotNull String serialize(Object object) { + public @NotNull String serializeAsString(Object object) { try { return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { @@ -22,4 +23,9 @@ public class SimpleJsonSerializer implements JsonSerializer { throw new RuntimeException(e); } } + + @Override + public @NotNull JSON serializeAsJson(Object object) { + return JSON.valueOf(serializeAsString(object)); + } } diff --git a/application/src/main/java/net/furizon/backend/infrastructure/pretix/dto/PretixPaging.java b/application/src/main/java/net/furizon/backend/infrastructure/pretix/dto/PretixPaging.java index 2d32af0..f075795 100644 --- a/application/src/main/java/net/furizon/backend/infrastructure/pretix/dto/PretixPaging.java +++ b/application/src/main/java/net/furizon/backend/infrastructure/pretix/dto/PretixPaging.java @@ -1,6 +1,7 @@ package net.furizon.backend.infrastructure.pretix.dto; import lombok.Data; +import net.minidev.json.annotate.JsonIgnore; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -12,6 +13,7 @@ public class PretixPaging { public static final int DEFAULT_PAGE = 1; + @JsonIgnore private final Pattern pageNumberPatter = Pattern.compile("page=(\\d+)"); private final int page; diff --git a/application/src/main/java/net/furizon/backend/infrastructure/security/configuration/SecurityConfiguration.java b/application/src/main/java/net/furizon/backend/infrastructure/security/configuration/SecurityConfiguration.java index 0019547..065513f 100644 --- a/application/src/main/java/net/furizon/backend/infrastructure/security/configuration/SecurityConfiguration.java +++ b/application/src/main/java/net/furizon/backend/infrastructure/security/configuration/SecurityConfiguration.java @@ -15,6 +15,7 @@ import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; @@ -41,14 +42,14 @@ public class SecurityConfiguration { private final DatabaseSessionFilter databaseSessionFilter; @Bean - public SecurityFilterChain filterChain( - HttpSecurity http - ) throws Exception { + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // Map the allowed endpoints return http .cors(customizer -> - customizer.configurationSource(corsConfigurationSource()) + //customizer.configurationSource(corsConfigurationSource()) + customizer.disable() ) + .csrf(CsrfConfigurer::disable) .authorizeHttpRequests(customizer -> customizer .requestMatchers(antMatcher(HttpMethod.POST, "/api/v1/authentication/login")) .permitAll() @@ -87,8 +88,8 @@ private CorsConfigurationSource corsConfigurationSource() { return request -> { CorsConfiguration config = new CorsConfiguration(); config.setAllowedOrigins( - List.of("http://localhost")) - ; + List.of("*") // TODO -> Replace for prod + ); config.setAllowedMethods( List.of( HttpMethod.GET.name(), diff --git a/application/src/main/java/net/furizon/backend/infrastructure/usecase/SimpleUseCaseExecutor.java b/application/src/main/java/net/furizon/backend/infrastructure/usecase/SimpleUseCaseExecutor.java index 89eab7f..ba621e3 100644 --- a/application/src/main/java/net/furizon/backend/infrastructure/usecase/SimpleUseCaseExecutor.java +++ b/application/src/main/java/net/furizon/backend/infrastructure/usecase/SimpleUseCaseExecutor.java @@ -32,11 +32,20 @@ public > R execute( @NotNull I input ) { log.debug("Executing use case: {}", useCaseClass.getSimpleName()); + final var startTime = System.currentTimeMillis(); final UseCase useCase = useCaseMap.get(useCaseClass.getCanonicalName()); if (useCase == null) { throw new IllegalArgumentException("Use case not found: " + useCaseClass.getSimpleName()); } - return ((UseCase) useCase).executor(input); + final var result = ((UseCase) useCase).executor(input); + + log.debug( + "Use case '{}' finished with {} ms", + useCaseClass.getSimpleName(), + System.currentTimeMillis() - startTime + ); + + return result; } } diff --git a/db/migrations/000001_model.up.sql b/db/migrations/000001_model.up.sql index 853c3ff..0aea8fe 100644 --- a/db/migrations/000001_model.up.sql +++ b/db/migrations/000001_model.up.sql @@ -1,148 +1,162 @@ -CREATE TABLE IF NOT EXISTS events ( - event_slug varchar(255) NOT NULL, - event_date_to varchar(32) NULL, -- Probable better to use timestamp type -- - event_date_from varchar(32) NULL, -- Probable better to use timestamp type -- - event_is_current bool NOT NULL, - event_public_url text NOT NULL, - event_names text NULL, - CONSTRAINT events_pkey PRIMARY KEY (event_slug) +CREATE TABLE IF NOT EXISTS events +( + event_slug varchar(255) NOT NULL, + event_date_to varchar(32) NULL, -- Probable better to use timestamp type -- + event_date_from varchar(32) NULL, -- Probable better to use timestamp type -- + event_is_current bool NOT NULL, + event_public_url text NOT NULL, + event_names text NULL, + CONSTRAINT events_pkey PRIMARY KEY (event_slug) ); -CREATE TABLE IF NOT EXISTS "groups" ( - group_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - group_name varchar(255) NOT NULL, - CONSTRAINT groups_pkey PRIMARY KEY (group_id) +CREATE TABLE IF NOT EXISTS "groups" +( + group_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + group_name varchar(255) NOT NULL, + CONSTRAINT groups_pkey PRIMARY KEY (group_id) ); -CREATE TABLE IF NOT EXISTS media ( - media_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - media_path text NULL, - media_type varchar(255) NULL, - CONSTRAINT media_pkey PRIMARY KEY (media_id) +CREATE TABLE IF NOT EXISTS media +( + media_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + media_path text NULL, + media_type varchar(255) NULL, + CONSTRAINT media_pkey PRIMARY KEY (media_id) ); -CREATE TABLE IF NOT EXISTS group_permissions ( - group_id int8 NOT NULL, - permission_code text NOT NULL, - CONSTRAINT group_permissions_pk PRIMARY KEY (permission_code, group_id) +CREATE TABLE IF NOT EXISTS group_permissions +( + group_id int8 NOT NULL, + permission_code text NOT NULL, + CONSTRAINT group_permissions_pk PRIMARY KEY (permission_code, group_id) ); -CREATE TABLE IF NOT EXISTS users ( - user_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - user_fursona_name varchar(64) NULL, - user_locale varchar(8) DEFAULT 'en-us'::character varying NULL, - user_secret varchar(70) NOT NULL, - media_id_propic int8 NULL, - CONSTRAINT users_pkey PRIMARY KEY (user_id), - CONSTRAINT users_unique_secret UNIQUE (user_secret), - CONSTRAINT user_media_fk FOREIGN KEY (media_id_propic) REFERENCES media(media_id) +CREATE TABLE IF NOT EXISTS users +( + user_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + user_fursona_name varchar(64) NULL, + user_locale varchar(8) DEFAULT 'en-us'::character varying NULL, + user_secret varchar(70) NOT NULL, + media_id_propic int8 NULL, + CONSTRAINT users_pkey PRIMARY KEY (user_id), + CONSTRAINT users_unique_secret UNIQUE (user_secret), + CONSTRAINT user_media_fk FOREIGN KEY (media_id_propic) REFERENCES media (media_id) ); -CREATE TABLE IF NOT EXISTS authentications ( - authentication_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - authentication_email varchar(255) NOT NULL, - authentication_email_verified bool NULL, - authentication_2fa_enabled bool NULL, - authentication_disabled bool NULL, - authentication_expired bool NULL, - authentication_from_oauth bool NULL, - authentication_password text NOT NULL, - authentication_token varchar(255) NULL, - user_id int8 NULL, - CONSTRAINT authentications_pkey PRIMARY KEY (authentication_id), - CONSTRAINT authentications_unique_email UNIQUE (authentication_email), - CONSTRAINT authentications_unique_user_id UNIQUE (user_id), - CONSTRAINT authentications_users_fk FOREIGN KEY (user_id) REFERENCES users(user_id) +CREATE TABLE IF NOT EXISTS authentications +( + authentication_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + authentication_email varchar(255) NOT NULL, + authentication_email_verified bool NULL, + authentication_2fa_enabled bool NULL, + authentication_disabled bool NULL, + authentication_expired bool NULL, + authentication_from_oauth bool NULL, + authentication_password text NOT NULL, + authentication_token varchar(255) NULL, + user_id int8 NULL, + CONSTRAINT authentications_pkey PRIMARY KEY (authentication_id), + CONSTRAINT authentications_unique_email UNIQUE (authentication_email), + CONSTRAINT authentications_unique_user_id UNIQUE (user_id), + CONSTRAINT authentications_users_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ); -CREATE TABLE IF NOT EXISTS membership_info ( - user_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - info_first_name text NULL, - info_last_name text NULL, - info_address text NULL, - info_zip varchar(16) NULL, - info_city text NULL, - info_country text NULL, - info_tax_id varchar(16) NULL, - info_birth_city text NULL, - info_birth_region text NULL, - info_birth_country text NULL, - info_region text NULL, - info_phone text NULL, - CONSTRAINT membership_info_id_pkey PRIMARY KEY (user_id), - CONSTRAINT membership_info_users_fk FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE +CREATE TABLE IF NOT EXISTS membership_info +( + user_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + info_first_name text NULL, + info_last_name text NULL, + info_address text NULL, + info_zip varchar(16) NULL, + info_city text NULL, + info_country text NULL, + info_tax_id varchar(16) NULL, + info_birth_city text NULL, + info_birth_region text NULL, + info_birth_country text NULL, + info_region text NULL, + info_phone text NULL, + CONSTRAINT membership_info_id_pkey PRIMARY KEY (user_id), + CONSTRAINT membership_info_users_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE ); -CREATE TABLE IF NOT EXISTS fursuits ( - fursuit_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - fursuit_name varchar(255) NULL, - fursuit_species varchar(255) NULL, - user_id int8 NULL, - media_id_propic int8 NULL, - CONSTRAINT fursuits_pkey PRIMARY KEY (fursuit_id), - CONSTRAINT fursuits_media_fk FOREIGN KEY (media_id_propic) REFERENCES media(media_id), - CONSTRAINT fursuits_users_fk FOREIGN KEY (user_id) REFERENCES users(user_id) +CREATE TABLE IF NOT EXISTS fursuits +( + fursuit_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + fursuit_name varchar(255) NULL, + fursuit_species varchar(255) NULL, + user_id int8 NULL, + media_id_propic int8 NULL, + CONSTRAINT fursuits_pkey PRIMARY KEY (fursuit_id), + CONSTRAINT fursuits_media_fk FOREIGN KEY (media_id_propic) REFERENCES media (media_id), + CONSTRAINT fursuits_users_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ); -CREATE TABLE IF NOT EXISTS fursuits_events ( - event_id int8 NOT NULL, - fursuit_id int8 NOT NULL, - CONSTRAINT fursuits_events_pk PRIMARY KEY (event_id, fursuit_id), - CONSTRAINT fursuits_events_event_fk FOREIGN KEY (event_id) REFERENCES media(media_id), - CONSTRAINT fursuits_events_fursuit_fk FOREIGN KEY (fursuit_id) REFERENCES fursuits(fursuit_id) +CREATE TABLE IF NOT EXISTS fursuits_events +( + event_id int8 NOT NULL, + fursuit_id int8 NOT NULL, + CONSTRAINT fursuits_events_pk PRIMARY KEY (event_id, fursuit_id), + CONSTRAINT fursuits_events_event_fk FOREIGN KEY (event_id) REFERENCES media (media_id), + CONSTRAINT fursuits_events_fursuit_fk FOREIGN KEY (fursuit_id) REFERENCES fursuits (fursuit_id) ); -CREATE TABLE IF NOT EXISTS membership_cards ( - card_db_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - card_year int2 NOT NULL, - user_id int8 NOT NULL, - CONSTRAINT cards_pkey PRIMARY KEY (card_db_id), - CONSTRAINT card_user_fk FOREIGN KEY (user_id) REFERENCES users(user_id) +CREATE TABLE IF NOT EXISTS membership_cards +( + card_db_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + card_year int2 NOT NULL, + user_id int8 NOT NULL, + CONSTRAINT cards_pkey PRIMARY KEY (card_db_id), + CONSTRAINT card_user_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ); -CREATE TABLE IF NOT EXISTS orders ( - order_code varchar(64) NOT NULL, - order_answers text NULL, - order_status int2 DEFAULT 0 NOT NULL, - order_answers_main_position_id int4 NOT NULL, - order_daily_days int8 NOT NULL, - order_extra_days_type int2 NULL, - order_room_capacity int2 NULL, - order_hotel_location varchar(255), - has_membership bool NOT NULL, - order_secret varchar(32) NULL, - order_sponsorship_type int2 NULL, - event_id varchar(255) NULL, - user_id int8 NULL, - CONSTRAINT orders_extra_days_check CHECK (((order_extra_days_type >= 0) AND (order_extra_days_type <= 3))), - CONSTRAINT orders_pkey PRIMARY KEY (order_code), - CONSTRAINT orders_sponsorship_check CHECK (((order_sponsorship_type >= 0) AND (order_sponsorship_type <= 2))), - CONSTRAINT orders_status_check CHECK (((order_status >= 0) AND (order_status <= 3))), - CONSTRAINT orders_events_id FOREIGN KEY (event_id) REFERENCES events(event_slug), - CONSTRAINT orders_users_id FOREIGN KEY (user_id) REFERENCES users(user_id) +CREATE TABLE IF NOT EXISTS orders +( + order_code varchar(64) NOT NULL, + order_answers_json json NULL, + order_status int2 DEFAULT 0 NOT NULL, + order_answers_main_position_id int4 NOT NULL, + order_daily_days int8 NOT NULL, + order_extra_days_type int2 NULL, + order_room_capacity int2 NULL, + order_hotel_location varchar(255), + has_membership bool NOT NULL, + order_secret varchar(32) NULL, + order_sponsorship_type int2 NULL, + event_id varchar(255) NULL, + user_id int8 NULL, + CONSTRAINT orders_extra_days_check CHECK (((order_extra_days_type >= 0) AND (order_extra_days_type <= 3))), + CONSTRAINT orders_pkey PRIMARY KEY (order_code), + CONSTRAINT orders_sponsorship_check CHECK (((order_sponsorship_type >= 0) AND (order_sponsorship_type <= 2))), + CONSTRAINT orders_status_check CHECK (((order_status >= 0) AND (order_status <= 3))), + CONSTRAINT orders_events_id FOREIGN KEY (event_id) REFERENCES events (event_slug), + CONSTRAINT orders_users_id FOREIGN KEY (user_id) REFERENCES users (user_id) ); -CREATE TABLE IF NOT EXISTS rooms ( - room_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - room_confirmed bool NULL, - room_name varchar(255) NULL, - order_id varchar(64) NULL, - CONSTRAINT rooms_pkey PRIMARY KEY (room_id), - CONSTRAINT rooms_orders_id FOREIGN KEY (order_id) REFERENCES orders(order_code) +CREATE TABLE IF NOT EXISTS rooms +( + room_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + room_confirmed bool NULL, + room_name varchar(255) NULL, + order_id varchar(64) NULL, + CONSTRAINT rooms_pkey PRIMARY KEY (room_id), + CONSTRAINT rooms_orders_id FOREIGN KEY (order_id) REFERENCES orders (order_code) ); -CREATE TABLE IF NOT EXISTS user_group ( - group_id int8 NULL, - user_id int8 NULL, - CONSTRAINT user_group_groups_fk FOREIGN KEY (group_id) REFERENCES "groups"(group_id), - CONSTRAINT user_group_users_fk FOREIGN KEY (user_id) REFERENCES users(user_id) +CREATE TABLE IF NOT EXISTS user_group +( + group_id int8 NULL, + user_id int8 NULL, + CONSTRAINT user_group_groups_fk FOREIGN KEY (group_id) REFERENCES "groups" (group_id), + CONSTRAINT user_group_users_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ); -CREATE TABLE IF NOT EXISTS room_guests ( - room_guest_id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, - user_id int8 NULL, - room_id int8 NULL, - CONSTRAINT room_guests_pkey PRIMARY KEY (room_guest_id), - CONSTRAINT room_guests_rooms_fk FOREIGN KEY (room_id) REFERENCES rooms(room_id), - CONSTRAINT room_guests_users_fk FOREIGN KEY (user_id) REFERENCES users(user_id) +CREATE TABLE IF NOT EXISTS room_guests +( + room_guest_id int8 GENERATED BY DEFAULT AS IDENTITY ( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, + user_id int8 NULL, + room_id int8 NULL, + CONSTRAINT room_guests_pkey PRIMARY KEY (room_guest_id), + CONSTRAINT room_guests_rooms_fk FOREIGN KEY (room_id) REFERENCES rooms (room_id), + CONSTRAINT room_guests_users_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ); \ No newline at end of file diff --git a/jooq-common/pom.xml b/jooq-common/pom.xml index 10c58bb..3de0224 100644 --- a/jooq-common/pom.xml +++ b/jooq-common/pom.xml @@ -26,6 +26,11 @@ jooq ${jooq.version} + + org.jooq + jooq-jackson-extensions + ${jooq.version} + org.jetbrains annotations diff --git a/jooq-common/src/main/java/net/furizon/jooq/generated/tables/Orders.java b/jooq-common/src/main/java/net/furizon/jooq/generated/tables/Orders.java index 988f34b..406b364 100644 --- a/jooq-common/src/main/java/net/furizon/jooq/generated/tables/Orders.java +++ b/jooq-common/src/main/java/net/furizon/jooq/generated/tables/Orders.java @@ -22,6 +22,7 @@ import org.jooq.Field; import org.jooq.ForeignKey; import org.jooq.InverseForeignKey; +import org.jooq.JSON; import org.jooq.Name; import org.jooq.Path; import org.jooq.PlainSQL; @@ -75,9 +76,9 @@ public Class getRecordType() { public final TableField ORDER_CODE = createField(DSL.name("order_code"), SQLDataType.VARCHAR(64).nullable(false), this, ""); /** - * The column public.orders.order_answers. + * The column public.orders.order_answers_json. */ - public final TableField ORDER_ANSWERS = createField(DSL.name("order_answers"), SQLDataType.CLOB, this, ""); + public final TableField ORDER_ANSWERS_JSON = createField(DSL.name("order_answers_json"), SQLDataType.JSON, this, ""); /** * The column public.orders.order_status.