Skip to content

Commit

Permalink
Add repository and entity definitions for MongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored and Daniel Villavicencio committed Feb 20, 2024
1 parent 63c043c commit 8e41b55
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 32 deletions.
16 changes: 6 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,19 @@ ext {
set('springCloudVersion', "2023.0.0-RC1")
set('apacheCollectionsVersion', '4.4')
set('pandoCryptoVersion', '1.1.1')
set('postgresqlVersion', '42.5.1')
set('postgresR2dbcVersion', '1.0.4.RELEASE')
set('flywayCoreVersion', '10.6.0')
set('flywayPostgresVersion', '10.4.1')
set('commonsCodecVersion', '1.15')
set('lombokVersion', '1.18.30')
set('aspectJWeaverVersion', '1.8.9')
set('aspectJRTVersion', '1.9.20')
set('i2pCryptoVersion', '0.3.0')
set('IOCommonsVersion', '2.15.1')
set('reactorTestVersion', '3.6.0')
set('flywayTestVersion', '10.0.0')
set('tcPostgresVersion', '1.19.4')
set('tcJdbcVersion', '1.19.4')
set('tcR2dbcVersion', '1.19.4')
set('testContainersVersion', '1.19.2')
set('tcJunitVersion', '1.19.3')
set('junitJupiterParamsVersion', '5.10.1')
set('springDataMongoDbVersion', '3.1.2')
set('springDataRedisVersion', '3.1.2')
set('springSessionRedisVersion', '3.1.1')
}

jar {
Expand All @@ -55,10 +50,11 @@ jar {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.session:spring-session-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation "org.springframework.session:spring-session-data-redis:${springSessionRedisVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-redis:${springDataRedisVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springDataMongoDbVersion}"
implementation "net.i2p.crypto:eddsa:${i2pCryptoVersion}"
implementation "commons-io:commons-io:${IOCommonsVersion}"
implementation "org.projectlombok:lombok:${lombokVersion}"
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/entity/PGCRDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.danielvm.destiny2bot.entity;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Document
public class PGCRDetails {

/**
* The ID of the Post Game Carnage Report
*/
private Long instanceId;

/**
* If the raid was started from the beginning
*/
private Boolean fromBeginning;

/**
* List of players and some relevant information
*/
private List<PlayerEntry> players;
}
41 changes: 41 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/entity/PlayerEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.danielvm.destiny2bot.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PlayerEntry {

/**
* The name of the player participant
*/
private String playerName;

/**
* The icon of the player at the time
*/
private String playerIcon;

/**
* The player membership type
*/
private Integer membershipType;

/**
* The player membership ID
*/
private Long membershipId;

/**
* Total amount of deaths
*/
private Integer deaths;

/**
* Total amount of kills
*/
private Integer kills;
}
42 changes: 26 additions & 16 deletions src/main/java/com/danielvm/destiny2bot/entity/UserDetails.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
package com.danielvm.destiny2bot.entity;

import java.io.Serial;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Collection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "user_details")
public class UserDetails implements Serializable {

@Serial
private static final long serialVersionUID = 6161559188488304844L;

private String discordId;

private String discordUsername;

private String accessToken;

private String refreshToken;

private Instant expiration;
/**
* The user identifier for a user which is a combination of their global username and their global
* tag, e.g., Deaht#8080
*/
@Id
private String userIdentifier;

/**
* Whether this user has a clan or not it will be saved in this field
*/
private String destinyClanName;

/**
* The last time this user was requested
*/
private LocalDateTime lastRequestDateTime;

/**
* Collection of user raid data
*/
private Collection<UserRaidDetails> userRaidDetails;
}
65 changes: 65 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/entity/UserRaidDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.danielvm.destiny2bot.entity;

import com.danielvm.destiny2bot.enums.RaidDifficulty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserRaidDetails implements Serializable {

/**
* The name of the raid
*/
private String raidName;

/**
* The difficulty of the raid, e.g., NORMAL or MASTER
*/
private RaidDifficulty raidDifficulty;

/**
* The size of the fireteam that completed the raid
*/
private Integer completionFireteamSize;

/**
* Whether the user completed this raid or not
*/
private Boolean isCompleted;

/**
* Total number of kills in the raid
*/
private Integer totalKills;

/**
* Total number of deaths in the raid
*/
private Integer totalDeaths;

/**
* The KDA of the player in the raid
*/
private Double kda;

/**
* Duration of the raid in seconds
*/
private Integer durationSeconds;

/**
* If the raid was started from the beginning
*/
private Boolean fromBeginning;

/**
* The related PGCR ID that relates to this specific instance of the raid. This field is more for
* reference purposes, so we can always reference back to the PGCR in case we need more
* information.
*/
private Long instanceId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.danielvm.destiny2bot.enums;

public enum RaidDifficulty {

NORMAL,
MASTER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.danielvm.destiny2bot.repository;

import com.danielvm.destiny2bot.entity.PGCRDetails;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PGCRRepository extends ReactiveMongoRepository<PGCRDetails, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.danielvm.destiny2bot.repository;

import com.danielvm.destiny2bot.entity.UserDetails;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserDetailsRepository extends ReactiveMongoRepository<UserDetails, String> {

}
7 changes: 7 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ spring:
redis:
port: 6379
host: localhost
mongodb:
username: root
password: root
database: riven_of_a_thousand_servers
host: localhost
port: 27017
authentication-database: admin

bungie:
api:
Expand Down
13 changes: 7 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ spring:
redis:
port: 6379
host: redis
flyway:
enabled: true
datasource:
url: # TODO: Define production parameters
username: # TODO: Define production parameters
password: #TODO: Define production parameters
mongodb:
username: ${MONGO_DB_ROOT_USERNAME}
password: ${MONGO_DB_ROOT_PASSWORD}
authentication-database: admin
database: riven_of_a_thousand_servers
host: mongo
port: 27017

server:
port: 443
Expand Down

0 comments on commit 8e41b55

Please sign in to comment.