From 5eaeb3552afc6ce2b236f6fbecb9bf525fc89466 Mon Sep 17 00:00:00 2001 From: akastijn Date: Fri, 17 Oct 2025 21:42:32 +0200 Subject: [PATCH] Add API endpoint to check staff application availability and enforce open/close periods --- .../forms/ApplicationController.java | 19 ++++++++++++++++ open_api/src/main/resources/api.yml | 2 ++ .../schemas/forms/staff_apply/staff_apply.yml | 22 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/ApplicationController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/ApplicationController.java index f155d21..457b4cf 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/ApplicationController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/ApplicationController.java @@ -16,9 +16,12 @@ import com.alttd.altitudeweb.services.mail.StaffApplicationMail; import com.alttd.altitudeweb.setup.Connection; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; +import java.time.Instant; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -34,8 +37,24 @@ public class ApplicationController implements ApplicationsApi { private final StaffApplicationMail staffApplicationMail; private final StaffApplicationDiscord staffApplicationDiscord; + private final Instant open = Instant.parse("2025-10-18T00:00:00Z"); + private final Instant close = Instant.parse("2020-10-26T00:00:00Z"); + + @Override + public ResponseEntity getStaffApplicationsIsOpen() { + return ResponseEntity.ok(isOpen()); + } + + private boolean isOpen() { + Instant now = Instant.now(); + return !now.isBefore(open) && !now.isAfter(close); + } + @Override public ResponseEntity submitStaffApplication(StaffApplicationDto staffApplicationDto) { + if (!isOpen()) { + return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); + } UUID userUuid = AuthenticatedUuid.getAuthenticatedUserUuid(); String email = staffApplicationDto.getEmail() == null ? null : staffApplicationDto.getEmail().toLowerCase(); diff --git a/open_api/src/main/resources/api.yml b/open_api/src/main/resources/api.yml index 7fb448e..6c047ed 100644 --- a/open_api/src/main/resources/api.yml +++ b/open_api/src/main/resources/api.yml @@ -57,6 +57,8 @@ paths: $ref: './schemas/forms/appeal/appeal.yml#/DiscordAppeal' /api/apply/staff-application: $ref: './schemas/forms/staff_apply/staff_apply.yml#/StaffApply' + /api/apply/staff-application-is-open: + $ref: './schemas/forms/staff_apply/staff_apply.yml#/StaffApplicationsIsOpen' /api/login/requestNewUserLogin/{uuid}: $ref: './schemas/login/login.yml#/RequestNewUserLogin' /api/login/userLogin/{code}: diff --git a/open_api/src/main/resources/schemas/forms/staff_apply/staff_apply.yml b/open_api/src/main/resources/schemas/forms/staff_apply/staff_apply.yml index b866d74..8bed1b8 100644 --- a/open_api/src/main/resources/schemas/forms/staff_apply/staff_apply.yml +++ b/open_api/src/main/resources/schemas/forms/staff_apply/staff_apply.yml @@ -24,6 +24,28 @@ StaffApply: application/json: schema: $ref: '../../generic/errors.yml#/components/schemas/ApiError' +StaffApplicationsIsOpen: + get: + tags: + - applications + summary: Get if staff applications are open + description: Get if staff applications are open + operationId: getStaffApplicationsIsOpen + responses: + '200': + description: If staff applications are open + content: + application/json: + schema: + type: boolean + '403': + description: If staff applications are not open + default: + description: Unexpected error + content: + application/json: + schema: + $ref: '../../generic/errors.yml#/components/schemas/ApiError' components: schemas: StaffApplication: