added round API

This commit is contained in:
2024-05-27 12:44:45 -04:00
parent a0b6ff4153
commit 7dfcc45b2e
5 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package com.poststats.golf.rs.api;
import java.math.BigInteger;
import com.poststats.golf.rs.api.model.Round;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.RolesAllowed;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
/**
* @author brian.long@poststats.com
*/
@Path("/golf/round/{roundId}")
@Tag(name = "Round API")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "404", description = "A round with the specified ID could not be found")
})
public interface RoundApi {
@GET
@Produces(Constants.V1_JSON)
@Operation(summary = "Retrieves limited meta-data about a round.")
Round get(@NotNull @Positive @PathParam("roundId") BigInteger roundId);
@PUT
@Path("/recompute")
@RolesAllowed(Constants.ADMIN_ROLE)
@SecurityRequirement(name = "basic")
@Operation(summary = "Recomputes a round's score and its impact on leaderboards and future handicaps.")
void recompute(@NotNull @Positive @PathParam("roundId") BigInteger roundId);
}

View File

@@ -0,0 +1,38 @@
package com.poststats.golf.rs.api;
import java.util.List;
import com.poststats.golf.rs.api.model.Round;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
/**
* @author brian.long@poststats.com
*/
@Path("/golf/rounds")
@Tag(name = "Round API")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "400", description = "A query parameter is not valid"),
@ApiResponse(responseCode = "404", description = "No matching rounds were found")
})
public interface RoundsApi {
// FIXME String to LocalDate
@GET
@Path("/byDate")
@Produces(Constants.V1_JSON)
@Operation(summary = "Finds rounds before a date.", description = "Searches for rounds by date, exclusive.")
List<Round> findByDate(@NotNull @Positive @QueryParam("personId") long personId,
@QueryParam("cutoffDate") String cutoffDate);
}

View File

@@ -0,0 +1,48 @@
package com.poststats.golf.rs.api.model;
import java.time.LocalDate;
import java.time.LocalTime;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.poststats.rs.api.annotation.MapEntry;
import com.poststats.rs.api.model.BaseModel;
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class BaseRound<ConcreteT extends BaseRound<ConcreteT>> extends BaseModel<ConcreteT> {
@JsonProperty
@MapEntry
private LocalDate teedate;
@JsonProperty
@MapEntry
private LocalTime teetime;
public LocalDate getTeedate() {
return teedate;
}
public void setTeedate(LocalDate teedate) {
this.teedate = teedate;
}
public LocalTime getTeetime() {
return teetime;
}
public void setTeetime(LocalTime teetime) {
this.teetime = teetime;
}
public ConcreteT withTeedate(LocalDate teedate) {
this.teedate = teedate;
return this.withThis();
}
public ConcreteT withTeetime(LocalTime teetime) {
this.teetime = teetime;
return this.withThis();
}
}

View File

@@ -0,0 +1,9 @@
package com.poststats.golf.rs.api.model;
import java.math.BigInteger;
public interface ReferenceableRound {
BigInteger getId();
}

View File

@@ -0,0 +1,48 @@
package com.poststats.golf.rs.api.model;
import java.math.BigInteger;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.poststats.rs.api.annotation.MapEntry;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Round extends BaseRound<Round> implements ReferenceableRound {
@JsonProperty(required = true, access = Access.READ_ONLY)
@MapEntry("roundID")
private BigInteger roundId;
@JsonProperty
@MapEntry
private Golfer golfer;
@Override
public BigInteger getId() {
return roundId;
}
public void setId(BigInteger roundId) {
this.roundId = roundId;
}
public Golfer getGolfer() {
return golfer;
}
public void setGolfer(Golfer golfer) {
this.golfer = golfer;
}
public Round withId(BigInteger roundId) {
this.roundId = roundId;
return this;
}
public Round withGolfer(Golfer golfer) {
this.golfer = golfer;
return this;
}
}