Version3Resource.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */
package org.ctan.site.resources.catalogue;

import java.util.List;
import java.util.Map;

import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response.Status;
import lombok.NonNull;

/**
 * The class <code>Version3Resource</code> contains the controller for the
 * version resource.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
@Path("/")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class Version3Resource {

    /**
     * The constant <code>values</code> contains the acceptable values.
     */
    static List<String> values =
        List.of("3.0");

    /**
     * The method <code>getVersion</code> provides means to retrieve the version
     * number of the API in use.
     *
     * @param vers the version
     * @return the version number
     */
    @GET
    @Path("/{vers}/version")
    @PermitAll
    public Map<String, String> getVersion(
        @NonNull @PathParam("vers") String vers) {

        if (!values.contains(vers)) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        return Map.of("version", vers);
    }
}