Started Spring application
This commit is contained in:
commit
f67f9dad74
4 changed files with 147 additions and 0 deletions
73
pom.xml
Normal file
73
pom.xml
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>io.github.norbipeti</groupId>
|
||||
<artifactId>GCDC-Server</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<release>11</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.1.6.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>discord4j-core</artifactId>
|
||||
<version>3.0.12</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
11
src/main/java/io/github/norbipeti/gcdc/Application.java
Normal file
11
src/main/java/io/github/norbipeti/gcdc/Application.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package io.github.norbipeti.gcdc;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
12
src/main/java/io/github/norbipeti/gcdc/model/Session.java
Normal file
12
src/main/java/io/github/norbipeti/gcdc/model/Session.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package io.github.norbipeti.gcdc.model;
|
||||
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Session {
|
||||
String token;
|
||||
Snowflake channel;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package io.github.norbipeti.gcdc.service;
|
||||
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import io.github.norbipeti.gcdc.model.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public class SessionService extends JdbcDaoSupport {
|
||||
|
||||
@Autowired
|
||||
DataSource dataSource;
|
||||
|
||||
@PostConstruct
|
||||
private void initialize() {
|
||||
setDataSource(dataSource);
|
||||
}
|
||||
|
||||
public void insertSession(Session session) {
|
||||
String sql = "INSERT INTO sessions(token, channel) VALUES (?, ?)";
|
||||
getJdbcTemplate().update(sql, session.getToken(), session.getChannel().asLong());
|
||||
}
|
||||
|
||||
public Session getSession(String token) {
|
||||
String sql = "SELECT * FROM sessions WHERE token=? LIMIT 1";
|
||||
List<Map<String, Object>> rows = getJdbcTemplate().queryForList(sql, token);
|
||||
|
||||
if (rows.size() == 0) return null;
|
||||
|
||||
var row = rows.get(0);
|
||||
return new Session((String) row.get("token"), Snowflake.of((long) row.get("channel")));
|
||||
}
|
||||
|
||||
public void deleteSession(String token) {
|
||||
String sql = "DELETE FROM sessions WHERE token=?";
|
||||
getJdbcTemplate().update(sql, token);
|
||||
|
||||
}
|
||||
|
||||
public void updateSession(Session session) {
|
||||
String sql = "UPDATE sessions SET channel=? WHERE token=?";
|
||||
getJdbcTemplate().update(sql, session.getChannel().asLong(), session.getToken());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue