Poll3Resource.java
/*
* Copyright © 2026 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.poll;
import java.util.Map;
import org.ctan.site.services.poll.PollService;
import io.dropwizard.hibernate.UnitOfWork;
import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
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>Poll3Resource</code> contains the controller for the poll
* resource.
*
* @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
*/
@Path("/3.0")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class Poll3Resource {
/**
* The field <code>service</code> contains the underlying service.
*/
private PollService service;
/**
* This is the constructor for the class <code>Poll3Resource</code>.
*
* @param service the underlying service
*/
public Poll3Resource(@NonNull PollService service) {
this.service = service;
}
/**
* ...
*
* @param poll the poll
* @return the version number
*/
@GET
@Path("/poll")
@PermitAll
@UnitOfWork(value = "siteDb")
public boolean save(
@NonNull Map<String, String> poll) {
try {
service.save(poll);
} catch (Exception e) {
throw new WebApplicationException(e.getMessage(),
Status.BAD_REQUEST);
}
return true;
}
}