forked from NIBLCO/niblapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
3,407 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
# api | ||
https://api.nibl.co.uk:8080/swagger-ui.html | ||
# Intro | ||
The NIBL API will be used to view XDCC bots and search for pack listings | ||
|
||
This is written in Spring Boot (of which I have little experience) and uses a MySQL database. | ||
|
||
Documentation on RESTful calls is handled in Swagger | ||
|
||
#### Swagger URL | ||
http://{Server IP}:8080/swagger-ui.html | ||
|
||
# Setup | ||
|
||
## Required Software | ||
1) Java 1.8 | ||
2) Maven | ||
3) MySQL | ||
|
||
## Database | ||
1) Import the database schema (db/schema.sql) and data (db/data.sql) | ||
2) Update the mysql username and password (src/main/resources/application.properties) | ||
|
||
Yes, I know the schema is not perfect, it was written in 2007. | ||
I will eventually update the schema to JPA standards while rewriting the software that populates it. | ||
|
||
## App | ||
1) mvn clean install | ||
2) java -jar target/nibl-api.jar | ||
|
||
# Debug | ||
|
||
## Database | ||
JPA is good about throwing errors if the database structure does not map to annotations | ||
or Java objects properly. | ||
|
||
You should see errors during start-up which tell you what is wrong. | ||
|
||
## App | ||
Log levels can be adjusted in the application.yml file. | ||
|
||
Defaults are; | ||
|
||
org.springframework.boot.env.PropertySourcesLoader: ERROR | ||
org.springframework.web: ERROR | ||
com.nibl: ERROR | ||
org.hibernate.SQL: ERROR | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
INSERT INTO `ooinuza`.`updatepacklist_bots` | ||
(`id`, `name`, `url`, `type`, `owner`, `status_id`, `last_seen`, `last_processed`, `informative`, `batchenable`, `external`, `parser_id`) | ||
VALUES | ||
('661','Harley-Quinn','Packlist URL 1','HTTP','Owner1','1','2014-08-06 17:49:03','2014-08-06 17:49:03','0','1','0','2'), | ||
('739','Kantai|Shimakaze','Packlist URL 2','HTTP','Owner2','1','2014-12-29 02:50:41','2014-12-29 02:50:41','0','1','0','2'), | ||
('808','Kantai|Mercury','Packlist URL 3','XDCC','Owner1','0','2015-07-15 05:40:09','2015-07-15 05:40:09','0','1','0','1'); | ||
|
||
INSERT INTO `ooinuza`.`updatepacklist_packs` | ||
(`bot_id`, `number`, `name`, `size`, `episode_number`, `last_modified`) | ||
VALUES | ||
('661','1','#1 File 1','6.6G','-1','2016-09-06 19:01:04'), | ||
('661','2','#1 File 2','3.2G','-1','2016-09-06 19:01:04'), | ||
('661','3','#1 File 3','2.9G','-1','2016-09-06 19:01:04'), | ||
('661','4','#1 File 4','3.4G','-1','2016-09-10 22:54:06'), | ||
('661','5','#1 File 5','4.3G','-1','2016-09-10 22:54:06'), | ||
('739','1','#2 File 1','359M','1','2016-10-11 17:16:59'), | ||
('739','2','#2 File 2','339M','2','2016-10-11 17:16:59'), | ||
('739','3','#2 File 3','362M','3','2016-10-11 17:16:59'), | ||
('739','4','#2 File 4','361M','3','2016-10-11 17:16:59'), | ||
('739','5','#2 File 5','364M','4','2016-10-11 17:16:59'), | ||
('739','6','#2 File 6','344M','5','2016-10-11 17:16:59'), | ||
('739','7','#2 File 7','322M','6','2016-10-11 17:16:59'), | ||
('739','8','#2 File 8','334M','7','2016-10-11 17:16:59'), | ||
('739','9','#2 File 9','1.0G','-1','2016-10-11 17:16:59'), | ||
('739','10','#2 File 10','306M','-1','2016-10-11 17:16:59'), | ||
('808','1','#3 File 1','1.0G','-1','2016-09-10 06:51:18'), | ||
('808','2','#3 File 2','306M','-1','2016-09-10 06:51:18'), | ||
('808','3','#3 File 3','875M','-1','2016-09-10 06:51:18'), | ||
('808','4','#3 File 4','362M','1','2016-09-10 06:51:18'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
CREATE DATABASE OOINUZA; | ||
|
||
CREATE TABLE `ooinuza`.`updatepacklist_packs` ( | ||
`id` int(12) NOT NULL AUTO_INCREMENT, | ||
`bot_id` int(12) NOT NULL, | ||
`number` int(12) NOT NULL, | ||
`name` text CHARACTER SET utf8, | ||
`size` varchar(8) CHARACTER SET latin1 NOT NULL, | ||
`episode_number` int(12) DEFAULT NULL, | ||
`last_modified` datetime NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `packid` (`number`), | ||
KEY `botid` (`bot_id`), | ||
KEY `last_modified` (`last_modified`), | ||
CONSTRAINT `updatepacklist_packs_ibfk_1` FOREIGN KEY (`bot_id`) REFERENCES `updatepacklist_bots` (`id`) ON DELETE CASCADE ON UPDATE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | ||
|
||
CREATE TABLE `ooinuza`.`updatepacklist_bots` ( | ||
`id` int(12) NOT NULL AUTO_INCREMENT, | ||
`name` varchar(40) NOT NULL, | ||
`url` varchar(200) NOT NULL, | ||
`type` varchar(10) NOT NULL, | ||
`owner` varchar(255) DEFAULT NULL, | ||
`status_id` int(2) NOT NULL, | ||
`last_seen` datetime NOT NULL, | ||
`last_processed` datetime NOT NULL, | ||
`informative` tinyint(4) NOT NULL, | ||
`batchenable` tinyint(1) NOT NULL DEFAULT '1', | ||
`external` tinyint(1) NOT NULL DEFAULT '0', | ||
`parser_id` int(11) NOT NULL DEFAULT '0', | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `name` (`name`), | ||
KEY `status_id` (`status_id`), | ||
CONSTRAINT `updatepacklist_bots_ibfk_1` FOREIGN KEY (`status_id`) REFERENCES `updatepacklist_status` (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<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> | ||
<version>SNAPSHOT-1.1.0</version> | ||
<description>NIBL API resource to list and search XDCC bots with an included AniList wrapper</description> | ||
<name>NIBL</name> | ||
<artifactId>nibl-api</artifactId> | ||
<groupId>com.nibl.api</groupId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
<finalName>${project.artifactId}</finalName> | ||
</build> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.4.1.RELEASE</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger2</artifactId> | ||
<version>2.5.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger-ui</artifactId> | ||
<version>2.5.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>2.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.json-simple</groupId> | ||
<artifactId>json-simple</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-common</artifactId> | ||
<version>2.23.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.nibl.api; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@SpringBootApplication | ||
@EnableScheduling | ||
public class Application { | ||
|
||
private static Logger log = LoggerFactory.getLogger(Application.class); | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.nibl.api; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
@Configuration | ||
public class ApplicationConfiguration { | ||
|
||
private static Logger log = LoggerFactory.getLogger(ApplicationConfiguration.class); | ||
|
||
@Bean | ||
public WebMvcConfigurer corsConfigurer() { | ||
return new WebMvcConfigurerAdapter() { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
log.info("Enabling CORS"); | ||
// TODO Restrict this to the specific host and port of the UI app on localhost | ||
registry.addMapping("/**").allowedMethods("PUT","POST","GET").allowedHeaders("Content-Type"); //.allowedOrigins("http://localhost:8080"); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.nibl.api; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger.web.UiConfiguration; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableSwagger2 | ||
public class SwaggerConfiguration { | ||
|
||
@Bean | ||
public UiConfiguration uiConfig() { | ||
return UiConfiguration.DEFAULT; | ||
} | ||
|
||
private ApiInfo metadata() { | ||
return new ApiInfoBuilder().title("NIBL API") | ||
.description("API endpoints for Nibl data").version("0.0.2") | ||
.contact(new Contact("", "", "[email protected]")).build(); | ||
} | ||
|
||
@Bean | ||
public Docket documentation() { | ||
|
||
return new Docket(DocumentationType.SWAGGER_2).select() | ||
.apis(RequestHandlerSelectors.basePackage("com.nibl.api")) | ||
.paths(PathSelectors.any()).build().pathMapping("/").apiInfo(metadata()); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/nibl/api/anilist/controller/AnilistController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.nibl.api.anilist.controller; | ||
|
||
import java.util.List; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.PathParam; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.fasterxml.jackson.annotation.JsonView; | ||
import com.nibl.api.anilist.domain.Season; | ||
import com.nibl.api.anilist.domain.Series; | ||
import com.nibl.api.anilist.service.AnilistApiService; | ||
import com.nibl.api.util.ContentResponse; | ||
import com.nibl.api.util.ErrorResponse; | ||
import com.nibl.api.xdcc.controller.BotController; | ||
import com.nibl.api.xdcc.view.Views; | ||
|
||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiParam; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
|
||
@RestController | ||
@RequestMapping(value = "anilist", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class AnilistController { | ||
|
||
private static Logger log = LoggerFactory.getLogger(BotController.class); | ||
|
||
@Autowired | ||
AnilistApiService aniListApi; | ||
|
||
@JsonView(Views.Bot.class) | ||
@ApiOperation(value = "Series By Season", nickname = "seriesBySeason") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse(code = 200, message = "Good", response = Series.class, responseContainer = "List"), | ||
@ApiResponse(code = 400, message = "Invalid parameters", response = ErrorResponse.class) | ||
} | ||
) | ||
@RequestMapping(method = RequestMethod.GET, value = "/series/season") | ||
public ContentResponse<List<Series>> aniListTest( | ||
@PathParam("year") | ||
@RequestParam(value = "year", required = true) Integer year, | ||
@PathParam("season") | ||
@ApiParam(required = true, allowableValues = "winter, spring, summer, fall") | ||
@RequestParam(value = "season", required = true) String seasonName, | ||
HttpServletRequest request) { | ||
log.debug("Enter /series/season. " + request.getQueryString()); | ||
Season season = new Season(); | ||
season.setYear(year); | ||
season.setSeasonName(seasonName); | ||
return new ContentResponse<List<Series>>(aniListApi.fetchAllSeries(season)); | ||
} | ||
|
||
} |
Oops, something went wrong.