Commit 3d31a386 authored by Brian Long's avatar Brian Long
Browse files

split from api

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+55 −0
Original line number Diff line number Diff line
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
#     https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/

# Eclipse files
.settings
.project
.classpath

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

pom.xml

0 → 100644
+146 −0
Original line number Diff line number Diff line
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.poststats</groupId>
	<artifactId>poststats-rs-api</artifactId>
	<version>2.0-SNAPSHOT</version>
	<packaging>jar</packaging>
	
	<properties>
		<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
		<maven.compiler.source>11</maven.compiler.source>
		<maven.compiler.target>11</maven.compiler.target>
		<maven.compiler.release>11</maven.compiler.release>
		<maven.compiler.debug>true</maven.compiler.debug>
		<maven.compiler.debuglevel>lines,vars,source</maven.compiler.debuglevel>
		
		<formatter.excludes>**/*Api.java</formatter.excludes>
		
		<swagger.version>2.2.8</swagger.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>com.poststats</groupId>
			<artifactId>poststats-core</artifactId>
			<version>2.0-SNAPSHOT</version>
		</dependency>
		
		<!-- adds JAX-RS support (REST services) -->
		<dependency>
			<groupId>jakarta.ws.rs</groupId>
			<artifactId>jakarta.ws.rs-api</artifactId>
			<version>3.1.0</version>
		</dependency>
		
		<!-- adds Servlet support -->
		<dependency>
			<groupId>jakarta.servlet</groupId>
			<artifactId>jakarta.servlet-api</artifactId>
			<version>6.0.0</version>
		</dependency>
		
		<!-- adds CDI support -->
		<dependency>
			<groupId>jakarta.enterprise</groupId>
			<artifactId>jakarta.enterprise.cdi-api</artifactId>
			<version>4.0.1</version>
		</dependency>
		<dependency>
			<groupId>jakarta.transaction</groupId>
			<artifactId>jakarta.transaction-api</artifactId>
			<version>2.0.1</version>
		</dependency>
		
		<!-- adds EJB support -->
		<dependency>
			<groupId>jakarta.ejb</groupId>
			<artifactId>jakarta.ejb-api</artifactId>
			<version>4.0.1</version>
		</dependency>
		
		<!-- adds JavaTime support for JSON (de)serialization -->
		<dependency>
			<groupId>com.fasterxml.jackson.datatype</groupId>
			<artifactId>jackson-datatype-jsr310</artifactId>
			<version>2.13.4</version>
		</dependency>
		
		<!-- adds multi-part support -->
		<dependency>
			<groupId>org.jboss.resteasy</groupId>
			<artifactId>resteasy-multipart-provider</artifactId>
			<version>6.2.1.Final</version>
		</dependency>
		
		<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-annotations-jakarta</artifactId>
			<version>${swagger.version}</version>
		</dependency>
		
		<dependency>
			<groupId>org.telegram</groupId>
			<artifactId>telegrambots-meta</artifactId>
			<version>6.4.0</version>
		</dependency>
		
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-slf4j2-impl</artifactId>
			<version>2.20.0</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>3.1.2</version>
			</plugin>
			<plugin>
				<groupId>io.swagger.core.v3</groupId>
				<artifactId>swagger-maven-plugin-jakarta</artifactId>
				<version>${swagger.version}</version>
				<configuration>
					<resourcePackages>
						<resourcePackage>com.poststats.api</resourcePackage>
					</resourcePackages>
					<outputPath>${project.build.outputDirectory}/META-INF</outputPath>
					<outputFileName>poststats-swagger</outputFileName>
					<outputFormat>JSONANDYAML</outputFormat>
					<prettyPrint>true</prettyPrint>
				</configuration>
				<executions>
					<execution>
						<id>swagger-generate</id>
						<goals>
							<goal>resolve</goal>
						</goals>
						<phase>compile</phase>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>io.repaint.maven</groupId>
				<artifactId>tiles-maven-plugin</artifactId>
				<version>2.33</version>
				<extensions>true</extensions>
				<configuration>
					<tiles>
						<tile>com.poststats:source-format-tile:[1.0.0,1.1.0)</tile>
					</tiles>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>
+25 −0
Original line number Diff line number Diff line
package com.poststats.rs.api;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import jakarta.ws.rs.Path;

/**
 * @author brian.long@poststats.com
 */
@Path("/")
@OpenAPIDefinition(
		info = @Info(
				contact = @Contact(name = "Brian Long", email = "brian.long@poststats.com"),
				title = "PostStats API",
				description = "An API providing access to PostStats objects.",
				version = "v1"
		)
)
@SecurityScheme(name = "basic", type = SecuritySchemeType.HTTP, scheme = "BASIC")
public interface BaseApi {

}
+16 −0
Original line number Diff line number Diff line
package com.poststats.rs.api;

public class Constants {

	public static final String V1_JSON = "application/vnd.poststats-v1+json";
	public static final String ADMIN_ROLE = "admin";
	public static final String AUTH_ROLE = "auth";
	public static final String MANAGER_ROLE = "owner";
	public static final String MANAGER_ROLE_PREFIX = MANAGER_ROLE
			+ ":";
	public static final String FACILITY_ROLE_PREFIX = "facility:";

	public static final String PERSON_ID = "personId";
	public static final String FACILITY_ID = "facilityId";

}
+78 −0
Original line number Diff line number Diff line
package com.poststats.rs.api;

import java.util.List;

import com.poststats.rs.api.model.Facility;
import com.poststats.rs.api.model.PagedCollection;
import com.poststats.rs.api.model.Pagination;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;
import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

/**
 * @author brian.long@poststats.com
 */
@Path("/facilities")
@Tag(name = "Facility API")
@Produces({ MediaType.APPLICATION_JSON, Constants.V1_JSON })
@ApiResponse(responseCode = "200", description = "Success", content = {
        @Content(mediaType = MediaType.APPLICATION_JSON),
        @Content(mediaType = Constants.V1_JSON)
})
@ApiResponse(responseCode = "400", description = "A request parameter is not valid")
@ApiResponse(responseCode = "404", description = "No matching facilities were found")
public interface FacilitiesApi {

    @GET
    @Path("/byName")
    @Operation(summary = "Searches for facilities by their name.", description = "Searches for facilities by their name, excluding prefix (e.g. The) and suffix (e.g. Golf Club), returning limited meta-data about each matched facility.")
    @Tag(name = "Search API")
    PagedCollection<List<Facility>> searchByName(
            @Parameter(description = "A fragment or whole facility name; the prefix and suffix are not included", example = "Bushwood") @QueryParam("name") @NotNull @Size(min = 3) String name,
            @BeanParam @Valid Pagination paging);

    @GET
    @Path("/byLocation/{country}")
    @Operation(summary = "Searches for facilities by their location.", description = "Searches for facilities by their country, returning limited meta-data about each matched facility.")
    @Tag(name = "Search API")
    PagedCollection<List<Facility>> searchByJurisdiction(
            @Parameter(description = "A country code", example = "US") @PathParam("country") @NotNull String country,
            @BeanParam @Valid Pagination paging);

    @GET
    @Path("/byLocation/{country}/{state}")
    @Operation(summary = "Searches for facilities by their location.", description = "Searches for facilities by their major jurisdiction (e.g. US States), returning limited meta-data about each matched facility.")
    @Tag(name = "Search API")
    PagedCollection<List<Facility>> searchByJurisdiction(
            @Parameter(description = "A country code", example = "US") @PathParam("country") @NotNull String country,
            @Parameter(description = "A State or high-level jurisdiction", example = "FL") @PathParam("state") @NotNull String state,
            @BeanParam @Valid Pagination paging);

    @GET
    @Path("/byGeo")
    @Operation(summary = "Searches for facilities by their location.", description = "Searches for facilities by their major jurisdiction (e.g. US States), returning limited meta-data about each matched facility.")
    @Tag(name = "Search API")
    PagedCollection<List<Facility>> searchByJurisdiction(
            @Parameter(description = "A latitude in decimal degrees", example = "41.2390") @QueryParam("latitude") @NotNull @DecimalMin("-90.0") @DecimalMax("90.0") double latitude,
            @Parameter(description = "A longitude in decimal degrees", example = "-81.34891") @QueryParam("longitude") @NotNull @DecimalMin("-180.0") @DecimalMax("180.0") double longitude,
            @Parameter(name = "radius", description = "A search radius in miles", example = "15") @QueryParam("radius") @Positive @Max(100) Integer radiusInMiles,
            @BeanParam @Valid Pagination paging);

}
Loading