Only ABS connection
This commit is contained in:
parent
b5146eebc6
commit
886d31bbf8
@ -1,52 +1,19 @@
|
|||||||
# docker-compose.yml
|
# docker-compose.yml
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
# Define the services for our application stack
|
# Define the services for our application stack
|
||||||
services:
|
services:
|
||||||
# PostgreSQL database service
|
|
||||||
postgres:
|
|
||||||
# Using the official PostgreSQL base image.
|
|
||||||
# 'postgres:16' is recommended for a stable, recent version.
|
|
||||||
# You can use 'postgres:latest' for the very newest, but versions like 13, 14, 15, 16 are common.
|
|
||||||
image: postgres:16 # Or postgres:latest, postgres:13-alpine, etc.
|
|
||||||
container_name: postgres_db # Assign a friendly name to the container
|
|
||||||
environment:
|
|
||||||
# --- CRITICAL: These settings will ONLY take effect if ./dbData directory is EMPTY on first run ---
|
|
||||||
POSTGRES_DB: horse # Your database name
|
|
||||||
POSTGRES_USER: postgres # Set to 'postgres', the default superuser for the official image
|
|
||||||
POSTGRES_PASSWORD: root # Your desired password for the 'postgres' user
|
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
ports:
|
|
||||||
- "5434:5432" # Map host port 5434 to container port 5432
|
|
||||||
volumes:
|
|
||||||
# Using a bind mount. You MUST delete the ./dbData directory manually if you change user/pass/db.
|
|
||||||
# This directory MUST be empty when the container first starts to trigger initialization.
|
|
||||||
- ./dbData:/var/lib/postgresql/data # Persist PostgreSQL data to a local directory
|
|
||||||
# Added command for more verbose logging during startup (optional, but highly recommended here)
|
|
||||||
command: postgres -c log_statement=all
|
|
||||||
networks:
|
|
||||||
- app_network # Connect to our custom application network
|
|
||||||
# networks:
|
|
||||||
# - app_network # Connect to our custom application network
|
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
#image: mathewfrancisv/spring_back_postgres:v1.0.0
|
#image: mathewfrancisv/spring_back_postgres:v1.0.0
|
||||||
image: mathewfrancisv/btc_cezen_backend:v1.0.2
|
image: mathewfrancisv/btc_cezen_backend:v2.3.0
|
||||||
container_name: spring_app
|
container_name: spring_app
|
||||||
ports:
|
ports:
|
||||||
- "8083:8080"
|
- "8083:8080"
|
||||||
environment:
|
environment:
|
||||||
# jdbc:postgresql://localhost:5432/horse
|
|
||||||
# SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/horse
|
|
||||||
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/horse
|
|
||||||
SPRING_DATASOURCE_USERNAME: postgres # Ensure this matches POSTGRES_USER
|
|
||||||
SPRING_DATASOURCE_PASSWORD: root # Ensure this matches POSTGRES_PASSWORD
|
|
||||||
SPRING_DATASOURCE_CORSIP: http://10.83.77.61:4200
|
SPRING_DATASOURCE_CORSIP: http://10.83.77.61:4200
|
||||||
#network_mode: host
|
#network_mode: host
|
||||||
networks:
|
networks:
|
||||||
- app_network
|
- app_network
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
|
|
||||||
# Angular frontend application service
|
# Angular frontend application service
|
||||||
angular-dev:
|
angular-dev:
|
||||||
@ -56,9 +23,6 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ../btc-UI:/app
|
- ../btc-UI:/app
|
||||||
command: sh -c "npm install && npm run start"
|
command: sh -c "npm install && npm run start"
|
||||||
# IMPORTANT: This service is explicitly part of the 'app_network' (bridge)
|
|
||||||
# Removing network_mode: host for this service
|
|
||||||
# network_mode: host
|
|
||||||
ports:
|
ports:
|
||||||
- "4200:4200" # REQUIRED to expose Angular to the host machine in bridge mode
|
- "4200:4200" # REQUIRED to expose Angular to the host machine in bridge mode
|
||||||
networks:
|
networks:
|
||||||
@ -66,20 +30,6 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- spring # The 'spring' service might not be directly reachable by name here
|
- spring # The 'spring' service might not be directly reachable by name here
|
||||||
|
|
||||||
# Optional Nginx service for Angular (if you were deploying production build)
|
|
||||||
# angular:
|
|
||||||
# image: nginx:alpine
|
|
||||||
# container_name: angular_app
|
|
||||||
# ports:
|
|
||||||
# - "80:80"
|
|
||||||
# volumes:
|
|
||||||
# - ./angular/dist/your-angular-app:/usr/share/nginx/html
|
|
||||||
# - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
|
|
||||||
# networks:
|
|
||||||
# - app_network
|
|
||||||
# depends_on:
|
|
||||||
# - spring
|
|
||||||
|
|
||||||
# Define the custom bridge network for 'angular-dev'
|
# Define the custom bridge network for 'angular-dev'
|
||||||
networks:
|
networks:
|
||||||
app_network:
|
app_network:
|
||||||
|
|||||||
@ -30,10 +30,10 @@
|
|||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>org.springframework.boot</groupId>
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
@ -45,11 +45,11 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>org.postgresql</groupId>
|
<!-- <groupId>org.postgresql</groupId>-->
|
||||||
<artifactId>postgresql</artifactId>
|
<!-- <artifactId>postgresql</artifactId>-->
|
||||||
<scope>runtime</scope>
|
<!-- <scope>runtime</scope>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>org.mariadb.jdbc</groupId>-->
|
<!-- <groupId>org.mariadb.jdbc</groupId>-->
|
||||||
<!-- <artifactId>mariadb-java-client</artifactId>-->
|
<!-- <artifactId>mariadb-java-client</artifactId>-->
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
package com.example.cezenBTC.DAO;
|
//package com.example.cezenBTC.DAO;
|
||||||
|
//
|
||||||
import com.example.cezenBTC.DTO.ReturnStatus;
|
//import com.example.cezenBTC.DTO.ReturnStatus;
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
//import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
//import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
||||||
|
//
|
||||||
import java.time.LocalDate;
|
//import java.time.LocalDate;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
public interface BtcOpsDAO {
|
//public interface BtcOpsDAO {
|
||||||
|
//
|
||||||
public ReturnStatus sentARaceVenue(RaceVenue raceVenue);
|
// public ReturnStatus sentARaceVenue(RaceVenue raceVenue);
|
||||||
|
//
|
||||||
public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRaces);
|
// public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRaces);
|
||||||
|
//
|
||||||
public List<RaceVenue> getAllRaceVenue();
|
// public List<RaceVenue> getAllRaceVenue();
|
||||||
|
//
|
||||||
public List<RaceNumber> getALlRacesByVenueId(int raceVenueId);
|
// public List<RaceNumber> getALlRacesByVenueId(int raceVenueId);
|
||||||
|
//
|
||||||
public List<RaceNumber> getAllRacesByDate(LocalDate date);
|
// public List<RaceNumber> getAllRacesByDate(LocalDate date);
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,92 +1,92 @@
|
|||||||
package com.example.cezenBTC.DAO;
|
//package com.example.cezenBTC.DAO;
|
||||||
|
//
|
||||||
import com.example.cezenBTC.DTO.ReturnStatus;
|
//import com.example.cezenBTC.DTO.ReturnStatus;
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
//import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
//import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
||||||
import com.example.cezenBTC.entity.user.UserEntity;
|
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||||
import jakarta.persistence.EntityManager;
|
//import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.TypedQuery;
|
//import jakarta.persistence.TypedQuery;
|
||||||
import jakarta.transaction.Transactional;
|
//import jakarta.transaction.Transactional;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Repository;
|
//import org.springframework.stereotype.Repository;
|
||||||
|
//
|
||||||
import java.time.LocalDate;
|
//import java.time.LocalDate;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
@Repository
|
//@Repository
|
||||||
public class BtcOpsDAOImpl implements BtcOpsDAO{
|
//public class BtcOpsDAOImpl implements BtcOpsDAO{
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private EntityManager entityManager;
|
// private EntityManager entityManager;
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
@Transactional
|
// @Transactional
|
||||||
public ReturnStatus sentARaceVenue(RaceVenue raceVenue) {
|
// public ReturnStatus sentARaceVenue(RaceVenue raceVenue) {
|
||||||
this.entityManager.persist(raceVenue);
|
// this.entityManager.persist(raceVenue);
|
||||||
return new ReturnStatus(true, "Venue added successfully", "");
|
// return new ReturnStatus(true, "Venue added successfully", "");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
@Transactional
|
// @Transactional
|
||||||
public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace) {
|
// public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace) {
|
||||||
|
//
|
||||||
// find the venue if it exists
|
// // find the venue if it exists
|
||||||
RaceVenue raceVenue = getRaceVenueById(raceVenueId);
|
// RaceVenue raceVenue = getRaceVenueById(raceVenueId);
|
||||||
|
//
|
||||||
// find a race event
|
// // find a race event
|
||||||
System.out.println("Race Venue is" + raceVenue.getVenue());
|
// System.out.println("Race Venue is" + raceVenue.getVenue());
|
||||||
// only if a race event exists then persist a race
|
// // only if a race event exists then persist a race
|
||||||
System.out.println(raceVenue.getVenue());
|
// System.out.println(raceVenue.getVenue());
|
||||||
RaceNumber raceNumber = new RaceNumber(localDate, raceVenue, numberOfRace);
|
// RaceNumber raceNumber = new RaceNumber(localDate, raceVenue, numberOfRace);
|
||||||
|
//
|
||||||
this.entityManager.persist(raceNumber);
|
// this.entityManager.persist(raceNumber);
|
||||||
return new ReturnStatus(true, "raceNumber persisted", "");
|
// return new ReturnStatus(true, "raceNumber persisted", "");
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private RaceVenue getRaceVenueById(int raceVenueId){
|
// private RaceVenue getRaceVenueById(int raceVenueId){
|
||||||
|
//
|
||||||
TypedQuery<RaceVenue> query = this.entityManager
|
// TypedQuery<RaceVenue> query = this.entityManager
|
||||||
.createQuery("SELECT V FROM RaceVenue as V WHERE V.raceVenueId = :venueID", RaceVenue.class);
|
// .createQuery("SELECT V FROM RaceVenue as V WHERE V.raceVenueId = :venueID", RaceVenue.class);
|
||||||
|
//
|
||||||
query.setParameter("venueID", raceVenueId);
|
// query.setParameter("venueID", raceVenueId);
|
||||||
|
//
|
||||||
return query.getSingleResult();
|
// return query.getSingleResult();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public List<RaceVenue> getAllRaceVenue() {
|
// public List<RaceVenue> getAllRaceVenue() {
|
||||||
|
//
|
||||||
TypedQuery<RaceVenue> query = this.entityManager
|
// TypedQuery<RaceVenue> query = this.entityManager
|
||||||
.createQuery("SELECT R FROM RaceVenue as R", RaceVenue.class);
|
// .createQuery("SELECT R FROM RaceVenue as R", RaceVenue.class);
|
||||||
|
//
|
||||||
return query.getResultList();
|
// return query.getResultList();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public List<RaceNumber> getALlRacesByVenueId(int raceVenueId) {
|
// public List<RaceNumber> getALlRacesByVenueId(int raceVenueId) {
|
||||||
|
//
|
||||||
// get the race venue from the backend
|
// // get the race venue from the backend
|
||||||
RaceVenue raceVenue = this.getRaceVenueById(raceVenueId);
|
// RaceVenue raceVenue = this.getRaceVenueById(raceVenueId);
|
||||||
|
//
|
||||||
TypedQuery<RaceNumber> query = this.entityManager
|
// TypedQuery<RaceNumber> query = this.entityManager
|
||||||
.createQuery("SELECT V FROM RaceNumber as V WHERE V.raceVenue = :venue", RaceNumber.class);
|
// .createQuery("SELECT V FROM RaceNumber as V WHERE V.raceVenue = :venue", RaceNumber.class);
|
||||||
|
//
|
||||||
query.setParameter("venue", raceVenue);
|
// query.setParameter("venue", raceVenue);
|
||||||
|
//
|
||||||
return query.getResultList();
|
// return query.getResultList();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public List<RaceNumber> getAllRacesByDate(LocalDate date) {
|
// public List<RaceNumber> getAllRacesByDate(LocalDate date) {
|
||||||
|
//
|
||||||
// get all races today
|
// // get all races today
|
||||||
|
//
|
||||||
TypedQuery<RaceNumber> query = this.entityManager
|
// TypedQuery<RaceNumber> query = this.entityManager
|
||||||
.createQuery("SELECT T FROM RaceNumber as T JOIN FETCH T.raceVenue WHERE T.sysDataOnly = :date", RaceNumber.class);
|
// .createQuery("SELECT T FROM RaceNumber as T JOIN FETCH T.raceVenue WHERE T.sysDataOnly = :date", RaceNumber.class);
|
||||||
|
//
|
||||||
query.setParameter("date", date);
|
// query.setParameter("date", date);
|
||||||
|
//
|
||||||
return query.getResultList();
|
// return query.getResultList();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
package com.example.cezenBTC.DAO;
|
//package com.example.cezenBTC.DAO;
|
||||||
|
//
|
||||||
import com.example.cezenBTC.DTO.ReturnStatus;
|
//import com.example.cezenBTC.DTO.ReturnStatus;
|
||||||
import com.example.cezenBTC.entity.user.UserEntity;
|
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||||
|
//
|
||||||
// TODO only one admin allowed ... once the admin creates an
|
//// TODO only one admin allowed ... once the admin creates an
|
||||||
// account they should not be able to make the account again
|
//// account they should not be able to make the account again
|
||||||
// admin login, logout and signup DAO operations
|
//// admin login, logout and signup DAO operations
|
||||||
public interface UserOpsDAO {
|
//public interface UserOpsDAO {
|
||||||
|
//
|
||||||
// check if user exists;
|
// // check if user exists;
|
||||||
public boolean checkIfAdminExists(UserEntity userEntity) throws Exception;
|
// public boolean checkIfAdminExists(UserEntity userEntity) throws Exception;
|
||||||
|
//
|
||||||
// admin login
|
// // admin login
|
||||||
public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity);
|
// public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity);
|
||||||
|
//
|
||||||
public UserEntity getUserByUserStringId(String userName);
|
// public UserEntity getUserByUserStringId(String userName);
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,105 +1,105 @@
|
|||||||
package com.example.cezenBTC.DAO;
|
//package com.example.cezenBTC.DAO;
|
||||||
|
|
||||||
import com.example.cezenBTC.DTO.ReturnStatus;
|
|
||||||
import com.example.cezenBTC.entity.user.Role;
|
|
||||||
import com.example.cezenBTC.entity.user.UserEntity;
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.Query;
|
|
||||||
import jakarta.persistence.TypedQuery;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public class UserOpsDAOImpl implements UserOpsDAO{
|
|
||||||
|
|
||||||
private final String roleNameInDb = "ROLE_admin";
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkIfAdminExists(UserEntity userEntity){
|
|
||||||
// check if info exists in the database users table
|
|
||||||
// this enforces the fact that only one user can exist
|
|
||||||
Query query = entityManager.createQuery(
|
|
||||||
"SELECT COUNT(u) FROM UserEntity u JOIN u.roles r WHERE r.role = :roleName");
|
|
||||||
query.setParameter("roleName", this.roleNameInDb);
|
|
||||||
Long count = (Long) query.getSingleResult();
|
|
||||||
return count > 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//check if user already exists
|
|
||||||
private boolean checkIfUserExists(UserEntity userEntity){
|
|
||||||
|
|
||||||
try{
|
|
||||||
TypedQuery<UserEntity> query = this.entityManager.createQuery(
|
|
||||||
"SELECT U FROM UserEntity U where U.userName= :givenUserName",UserEntity.class );
|
|
||||||
query.setParameter("givenUserName", userEntity.getUserName());
|
|
||||||
System.out.println("Existing user "+ userEntity.getUserName());
|
|
||||||
return query.getSingleResult() != null;
|
|
||||||
|
|
||||||
}catch ( Exception e){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get roles from the databasepbxUserService.adminSetUserNamePasswordSet("1234567890", "12345", "12345");
|
|
||||||
|
|
||||||
// Admin sets a username and password for the first time
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity) {
|
|
||||||
|
|
||||||
if(this.checkIfUserExists(userEntity)){
|
|
||||||
return new ReturnStatus(false, "User already exists", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// if (checkIfAdminExists(userEntity)) {
|
|
||||||
// return new ReturnStatus(false, "Admin already exists", "");
|
|
||||||
// }
|
|
||||||
// Fetch existing ROLE_Admin from DB
|
|
||||||
TypedQuery<Role> query = entityManager.createQuery("FROM Role r WHERE r.role = :roleName", Role.class)
|
|
||||||
.setParameter("roleName", roleNameInDb);
|
|
||||||
|
|
||||||
Role role = query.getSingleResult();
|
|
||||||
System.out.println("Adding " + userEntity.getUserName());
|
|
||||||
userEntity.setARole(role);
|
|
||||||
// Persist the user
|
|
||||||
entityManager.persist(userEntity);
|
|
||||||
return new ReturnStatus(true, "Admin created", "");
|
|
||||||
} catch (Exception e) {
|
|
||||||
return new ReturnStatus(false, "Admin creation failed", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get user details by username
|
|
||||||
// throws an exception if the user doesn't exist
|
|
||||||
// exception is caught and returns null ... custom authentication provider must catch the exception
|
|
||||||
@Override
|
|
||||||
public UserEntity getUserByUserStringId(String userStringId) {
|
|
||||||
try{
|
|
||||||
TypedQuery<UserEntity> query = this.entityManager
|
|
||||||
.createQuery("SELECT u FROM UserEntity u JOIN FETCH u.roles AS r WHERE u.userIdNumber = :userStringId", UserEntity.class);
|
|
||||||
|
|
||||||
query.setParameter("userStringId", userStringId);
|
|
||||||
|
|
||||||
return query.getSingleResult();
|
|
||||||
|
|
||||||
}catch ( Exception e){
|
|
||||||
System.out.println("User not found User exception");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// public UserEntity getUserByUserName(String userName){
|
|
||||||
// TypedQuery<UserEntity> query = this.entityManager
|
|
||||||
// .createQuery("SELECT u FROM UserEntity u WHERE u.userName = :userString", UserEntity.class);
|
|
||||||
//
|
//
|
||||||
// query.setParameter("userString", userName);
|
//import com.example.cezenBTC.DTO.ReturnStatus;
|
||||||
|
//import com.example.cezenBTC.entity.user.Role;
|
||||||
|
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||||
|
//import jakarta.persistence.EntityManager;
|
||||||
|
//import jakarta.persistence.Query;
|
||||||
|
//import jakarta.persistence.TypedQuery;
|
||||||
|
//import jakarta.transaction.Transactional;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.stereotype.Repository;
|
||||||
|
//
|
||||||
|
//@Repository
|
||||||
|
//public class UserOpsDAOImpl implements UserOpsDAO{
|
||||||
|
//
|
||||||
|
// private final String roleNameInDb = "ROLE_admin";
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private EntityManager entityManager;
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public boolean checkIfAdminExists(UserEntity userEntity){
|
||||||
|
// // check if info exists in the database users table
|
||||||
|
// // this enforces the fact that only one user can exist
|
||||||
|
// Query query = entityManager.createQuery(
|
||||||
|
// "SELECT COUNT(u) FROM UserEntity u JOIN u.roles r WHERE r.role = :roleName");
|
||||||
|
// query.setParameter("roleName", this.roleNameInDb);
|
||||||
|
// Long count = (Long) query.getSingleResult();
|
||||||
|
// return count > 0;
|
||||||
//
|
//
|
||||||
// return query.getSingleResult();
|
|
||||||
// }
|
// }
|
||||||
}
|
//
|
||||||
|
// //check if user already exists
|
||||||
|
// private boolean checkIfUserExists(UserEntity userEntity){
|
||||||
|
//
|
||||||
|
// try{
|
||||||
|
// TypedQuery<UserEntity> query = this.entityManager.createQuery(
|
||||||
|
// "SELECT U FROM UserEntity U where U.userName= :givenUserName",UserEntity.class );
|
||||||
|
// query.setParameter("givenUserName", userEntity.getUserName());
|
||||||
|
// System.out.println("Existing user "+ userEntity.getUserName());
|
||||||
|
// return query.getSingleResult() != null;
|
||||||
|
//
|
||||||
|
// }catch ( Exception e){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // get roles from the databasepbxUserService.adminSetUserNamePasswordSet("1234567890", "12345", "12345");
|
||||||
|
//
|
||||||
|
// // Admin sets a username and password for the first time
|
||||||
|
// @Override
|
||||||
|
// @Transactional
|
||||||
|
// public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity) {
|
||||||
|
//
|
||||||
|
// if(this.checkIfUserExists(userEntity)){
|
||||||
|
// return new ReturnStatus(false, "User already exists", "");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
//// if (checkIfAdminExists(userEntity)) {
|
||||||
|
//// return new ReturnStatus(false, "Admin already exists", "");
|
||||||
|
//// }
|
||||||
|
// // Fetch existing ROLE_Admin from DB
|
||||||
|
// TypedQuery<Role> query = entityManager.createQuery("FROM Role r WHERE r.role = :roleName", Role.class)
|
||||||
|
// .setParameter("roleName", roleNameInDb);
|
||||||
|
//
|
||||||
|
// Role role = query.getSingleResult();
|
||||||
|
// System.out.println("Adding " + userEntity.getUserName());
|
||||||
|
// userEntity.setARole(role);
|
||||||
|
// // Persist the user
|
||||||
|
// entityManager.persist(userEntity);
|
||||||
|
// return new ReturnStatus(true, "Admin created", "");
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// return new ReturnStatus(false, "Admin creation failed", e.getMessage());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // get user details by username
|
||||||
|
// // throws an exception if the user doesn't exist
|
||||||
|
// // exception is caught and returns null ... custom authentication provider must catch the exception
|
||||||
|
// @Override
|
||||||
|
// public UserEntity getUserByUserStringId(String userStringId) {
|
||||||
|
// try{
|
||||||
|
// TypedQuery<UserEntity> query = this.entityManager
|
||||||
|
// .createQuery("SELECT u FROM UserEntity u JOIN FETCH u.roles AS r WHERE u.userIdNumber = :userStringId", UserEntity.class);
|
||||||
|
//
|
||||||
|
// query.setParameter("userStringId", userStringId);
|
||||||
|
//
|
||||||
|
// return query.getSingleResult();
|
||||||
|
//
|
||||||
|
// }catch ( Exception e){
|
||||||
|
// System.out.println("User not found User exception");
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//// public UserEntity getUserByUserName(String userName){
|
||||||
|
//// TypedQuery<UserEntity> query = this.entityManager
|
||||||
|
//// .createQuery("SELECT u FROM UserEntity u WHERE u.userName = :userString", UserEntity.class);
|
||||||
|
////
|
||||||
|
//// query.setParameter("userString", userName);
|
||||||
|
////
|
||||||
|
//// return query.getSingleResult();
|
||||||
|
//// }
|
||||||
|
//}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package com.example.cezenBTC;
|
package com.example.cezenBTC;
|
||||||
|
|
||||||
import com.example.cezenBTC.service.BtcRaceService;
|
//import com.example.cezenBTC.service.BtcRaceService;
|
||||||
import com.example.cezenBTC.service.BtcUserService;
|
//import com.example.cezenBTC.service.BtcUserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
@ -20,37 +20,37 @@ public class HorseBTC {
|
|||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
CommandLineRunner runner(@Autowired BtcUserService btcUserService, @Autowired BtcRaceService btcRaceService) {
|
CommandLineRunner runner(/*@Autowired BtcUserService btcUserService, @Autowired BtcRaceService btcRaceService*/) {
|
||||||
return (args) -> {
|
return (args) -> {
|
||||||
btcUserService.adminSetUserNamePasswordSet("123412341234", "John Dow", "1234567");
|
// btcUserService.adminSetUserNamePasswordSet("123412341234", "John Dow", "1234567");
|
||||||
btcUserService.adminSetUserNamePasswordSet("432143214321", "John Dow 1", "1231234");
|
// btcUserService.adminSetUserNamePasswordSet("432143214321", "John Dow 1", "1231234");
|
||||||
btcUserService.adminSetUserNamePasswordSet("567856785678", "John Dow 2", "1234567");
|
// btcUserService.adminSetUserNamePasswordSet("567856785678", "John Dow 2", "1234567");
|
||||||
btcUserService.adminSetUserNamePasswordSet("876587658765", "John Dow 3", "1234567");
|
// btcUserService.adminSetUserNamePasswordSet("876587658765", "John Dow 3", "1234567");
|
||||||
btcUserService.adminSetUserNamePasswordSet("098709870987", "John Dow 4", "2222222");
|
// btcUserService.adminSetUserNamePasswordSet("098709870987", "John Dow 4", "2222222");
|
||||||
btcUserService.adminSetUserNamePasswordSet("789078907890", "John Dow 5", "4444444");
|
// btcUserService.adminSetUserNamePasswordSet("789078907890", "John Dow 5", "4444444");
|
||||||
btcUserService.adminSetUserNamePasswordSet("231120230065", "Gowathami v", "1111111");
|
// btcUserService.adminSetUserNamePasswordSet("231120230065", "Gowathami v", "1111111");
|
||||||
|
//
|
||||||
btcRaceService.addARaceVenue("BNG");
|
// btcRaceService.addARaceVenue("BNG");
|
||||||
btcRaceService.addARaceVenue("MYS");
|
// btcRaceService.addARaceVenue("MYS");
|
||||||
|
//
|
||||||
|
//
|
||||||
//add a few venue races
|
// //add a few venue races
|
||||||
//LocalDate.of(2025, 6, 29) year month day
|
// //LocalDate.of(2025, 6, 29) year month day
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 29), 1, 4);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 29), 1, 4);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 2);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 2);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 8, 29), 1, 4);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 8, 29), 1, 4);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 1, 4);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 1, 4);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 4);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 4);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 1, 4);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 1, 4);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 2);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 2);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 1);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 1);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 3);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 3);
|
||||||
btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 2, 3);
|
// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 2, 3);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,54 @@ public class LoginRequest {
|
|||||||
this.btMake = btMake;
|
this.btMake = btMake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOpCard() {
|
||||||
|
return opCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpCard(String opCard) {
|
||||||
|
this.opCard = opCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBtId() {
|
||||||
|
return btId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBtId(String btId) {
|
||||||
|
this.btId = btId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsrId() {
|
||||||
|
return usrId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsrId(String usrId) {
|
||||||
|
this.usrId = usrId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPasswordEnc() {
|
||||||
|
return passwordEnc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPasswordEnc(String passwordEnc) {
|
||||||
|
this.passwordEnc = passwordEnc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getBtMake() {
|
||||||
|
return btMake;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBtMake(Object btMake) {
|
||||||
|
this.btMake = btMake;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LoginRequest{" +
|
return "LoginRequest{" +
|
||||||
|
|||||||
@ -1,101 +1,101 @@
|
|||||||
package com.example.cezenBTC.config;
|
//package com.example.cezenBTC.config;
|
||||||
|
//
|
||||||
import com.example.cezenBTC.DAO.UserOpsDAO;
|
//import com.example.cezenBTC.DAO.UserOpsDAO;
|
||||||
import com.example.cezenBTC.entity.user.UserEntity;
|
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.AuthenticationProvider;
|
//import org.springframework.security.authentication.AuthenticationProvider;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
//import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
//import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
//import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
//import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
//import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import java.util.ArrayList;
|
//import java.util.ArrayList;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
@Component
|
//@Component
|
||||||
public class CezenCustomAuthenticationProviderForBTC /*implements AuthenticationProvider */ {
|
//public class CezenCustomAuthenticationProviderForBTC /*implements AuthenticationProvider */ {
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private UserOpsDAO userOpsDAO;
|
// private UserOpsDAO userOpsDAO;
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
// private PasswordEncoder passwordEncoder;
|
||||||
|
//
|
||||||
//@Override
|
// //@Override
|
||||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
// public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||||
|
//
|
||||||
//get credentials from login form
|
// //get credentials from login form
|
||||||
String[] karthickHamu = authentication.getName().split(",");
|
// String[] karthickHamu = authentication.getName().split(",");
|
||||||
String userStringId = karthickHamu[0]+"disabled by ABS";
|
// String userStringId = karthickHamu[0]+"disabled by ABS";
|
||||||
String btId = karthickHamu[1];
|
// String btId = karthickHamu[1];
|
||||||
String pwd = authentication.getCredentials().toString();
|
// String pwd = authentication.getCredentials().toString();
|
||||||
|
//
|
||||||
System.out.println("user Id " + userStringId + " password " + pwd);
|
// System.out.println("user Id " + userStringId + " password " + pwd);
|
||||||
|
//
|
||||||
|
//
|
||||||
//sanity check
|
// //sanity check
|
||||||
if (userStringId.isEmpty() || pwd.isEmpty()) return null;
|
// if (userStringId.isEmpty() || pwd.isEmpty()) return null;
|
||||||
|
//
|
||||||
// validate if the user input consists of only numbers
|
// // validate if the user input consists of only numbers
|
||||||
// and in the number rage is only 12
|
// // and in the number rage is only 12
|
||||||
try{
|
// try{
|
||||||
if(userStringId.length() != 12){
|
// if(userStringId.length() != 12){
|
||||||
System.out.println("Number not equal to 12");
|
// System.out.println("Number not equal to 12");
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
Double.parseDouble(userStringId);
|
// Double.parseDouble(userStringId);
|
||||||
}catch (Exception e){
|
// }catch (Exception e){
|
||||||
System.out.println(e.toString());
|
// System.out.println(e.toString());
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
//check for employee
|
// //check for employee
|
||||||
UserEntity user = null;
|
// UserEntity user = null;
|
||||||
try {
|
// try {
|
||||||
//check if employee exists if yes then fetch details
|
// //check if employee exists if yes then fetch details
|
||||||
user = this.userOpsDAO.getUserByUserStringId(userStringId);
|
// user = this.userOpsDAO.getUserByUserStringId(userStringId);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
System.out.println(e.toString());
|
// System.out.println(e.toString());
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (passwordEncoder.matches(pwd, user.getPassword())) {
|
// if (passwordEncoder.matches(pwd, user.getPassword())) {
|
||||||
|
//
|
||||||
//then it is a match a number of springs granted authorities
|
// //then it is a match a number of springs granted authorities
|
||||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
// List<GrantedAuthority> authorities = new ArrayList<>();
|
||||||
|
//
|
||||||
//loop through the users authorities and add each of them to simple granted authority
|
// //loop through the users authorities and add each of them to simple granted authority
|
||||||
try {
|
// try {
|
||||||
//check if user is part of permission set for admin signing in
|
// //check if user is part of permission set for admin signing in
|
||||||
boolean isAdmin = false;
|
// boolean isAdmin = false;
|
||||||
for(var permission : user.getRoles()){
|
// for(var permission : user.getRoles()){
|
||||||
if(permission.getRole().equals("ROLE_admin")) isAdmin = true;
|
// if(permission.getRole().equals("ROLE_admin")) isAdmin = true;
|
||||||
}
|
// }
|
||||||
if(!isAdmin) throw new BadCredentialsException("no employee permission for given employee");
|
// if(!isAdmin) throw new BadCredentialsException("no employee permission for given employee");
|
||||||
|
//
|
||||||
user.getRoles().forEach(a -> authorities.add(new SimpleGrantedAuthority(a.getRole())));
|
// user.getRoles().forEach(a -> authorities.add(new SimpleGrantedAuthority(a.getRole())));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
//use/**/r doesn't have permissions or roles = null
|
// //use/**/r doesn't have permissions or roles = null
|
||||||
System.out.println(e.toString());
|
// System.out.println(e.toString());
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
System.out.println("Auth DONE");
|
// System.out.println("Auth DONE");
|
||||||
|
//
|
||||||
return new UsernamePasswordAuthenticationToken(user.getUserIdNumber()+","+btId, pwd, authorities);
|
// return new UsernamePasswordAuthenticationToken(user.getUserIdNumber()+","+btId, pwd, authorities);
|
||||||
} else {
|
// } else {
|
||||||
throw new BadCredentialsException("Invalid password!");
|
// throw new BadCredentialsException("Invalid password!");
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public boolean supports(Class<?> authentication) {
|
|
||||||
// //tells spring that i want to support username password style of auth
|
|
||||||
// return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
|
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
}
|
//// @Override
|
||||||
|
//// public boolean supports(Class<?> authentication) {
|
||||||
|
//// //tells spring that i want to support username password style of auth
|
||||||
|
//// return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|||||||
@ -94,7 +94,12 @@ public class CezenRoutsSecurityChain {
|
|||||||
//.csrf(AbstractHttpConfigurer::disable)
|
//.csrf(AbstractHttpConfigurer::disable)
|
||||||
.csrf((csrf) ->
|
.csrf((csrf) ->
|
||||||
csrf.csrfTokenRequestHandler(requestHandler).
|
csrf.csrfTokenRequestHandler(requestHandler).
|
||||||
ignoringRequestMatchers("/open/signup","/user/getXSRfToken","/user/ping", "/abs/*")
|
ignoringRequestMatchers(
|
||||||
|
"/open/signup",
|
||||||
|
"/user/getXSRfToken",
|
||||||
|
"/user/ping",
|
||||||
|
"/abs/*",
|
||||||
|
"/download/rpinfo")
|
||||||
//.csrfTokenRepository(new CookieCsrfTokenRepository())
|
//.csrfTokenRepository(new CookieCsrfTokenRepository())
|
||||||
.csrfTokenRepository(cookieCsrfTokenRepo)
|
.csrfTokenRepository(cookieCsrfTokenRepo)
|
||||||
)
|
)
|
||||||
@ -115,7 +120,8 @@ public class CezenRoutsSecurityChain {
|
|||||||
"/cezen/set_aors",
|
"/cezen/set_aors",
|
||||||
"/cezen/set_password",
|
"/cezen/set_password",
|
||||||
"/cezen/add_extension",
|
"/cezen/add_extension",
|
||||||
"/abs/*"
|
"/abs/*",
|
||||||
|
"/download/rpinfo"
|
||||||
).hasAnyRole("OPTR")
|
).hasAnyRole("OPTR")
|
||||||
//any one who is authenticated can access /logout
|
//any one who is authenticated can access /logout
|
||||||
.requestMatchers("/user/getXSRfToken","/user/ping", "/logout").authenticated()
|
.requestMatchers("/user/getXSRfToken","/user/ping", "/logout").authenticated()
|
||||||
|
|||||||
@ -36,6 +36,31 @@ public class AbsController {
|
|||||||
@PostMapping(value = "/login", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
@PostMapping(value = "/login", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public ApiResponse login(@RequestBody LoginRequest req) {
|
public ApiResponse login(@RequestBody LoginRequest req) {
|
||||||
|
|
||||||
|
// for (int i = 0; i <= 255; i++) {
|
||||||
|
//
|
||||||
|
// int sleeper = i % 11;
|
||||||
|
//
|
||||||
|
// if(sleeper == 10){
|
||||||
|
// try {
|
||||||
|
// // Pause execution for 3000 milliseconds (3 seconds)
|
||||||
|
// Thread.sleep(1000);
|
||||||
|
// } catch (InterruptedException e) {
|
||||||
|
// // Handle the case where the thread is interrupted while sleeping
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // Cast the integer 'i' to a character to get the ASCII character
|
||||||
|
// char asciiChar = (char) i;
|
||||||
|
// System.out.println("ASCII Value: " + i + ", Character: " + asciiChar);
|
||||||
|
// req.setBtMake(asciiChar);
|
||||||
|
// ApiResponse res = absServiceForLogIn.loginInServiceListener(req);
|
||||||
|
//
|
||||||
|
// if(res.rcvHeaderRaw().nTxnId() != 0){
|
||||||
|
// System.out.println(res.rcvHeaderRaw().nTxnId());
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return absServiceForLogIn.loginInServiceListener(req);
|
return absServiceForLogIn.loginInServiceListener(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,50 +1,50 @@
|
|||||||
package com.example.cezenBTC.controller;
|
//package com.example.cezenBTC.controller;
|
||||||
|
|
||||||
import com.example.cezenBTC.DTO.race_card.RaceCard;
|
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
|
||||||
import com.example.cezenBTC.service.BtcRaceService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/btc")
|
|
||||||
public class BtcOperations {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BtcRaceService btcRaceService;
|
|
||||||
|
|
||||||
// @GetMapping("/get_all_venues")
|
|
||||||
// public List<RaceVenue> getAllVenus(){
|
|
||||||
//
|
//
|
||||||
// return this.btcRaceService.allRaceVenue();
|
//import com.example.cezenBTC.DTO.race_card.RaceCard;
|
||||||
|
//import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
||||||
|
//import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
||||||
|
//import com.example.cezenBTC.service.BtcRaceService;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.http.ResponseEntity;
|
||||||
|
//import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
//import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
//import org.springframework.web.bind.annotation.RestController;
|
||||||
|
//
|
||||||
|
//import java.time.LocalDate;
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
//@RestController
|
||||||
|
//@RequestMapping("/btc")
|
||||||
|
//public class BtcOperations {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private BtcRaceService btcRaceService;
|
||||||
|
//
|
||||||
|
//// @GetMapping("/get_all_venues")
|
||||||
|
//// public List<RaceVenue> getAllVenus(){
|
||||||
|
////
|
||||||
|
//// return this.btcRaceService.allRaceVenue();
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// @GetMapping("get_races_by_venue_id")
|
||||||
|
//// public List<RaceNumber> getRacesByVenueId(@RequestParam final int venueId){
|
||||||
|
////
|
||||||
|
//// System.out.println(venueId);
|
||||||
|
////
|
||||||
|
//// return this.btcRaceService.getRaceNumbersByVenueId(venueId);
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// @GetMapping("/get_all_races_by_today")
|
||||||
|
// public List<RaceNumber> getAllRacesByDateController(){
|
||||||
|
//
|
||||||
|
// return this.btcRaceService.getAllRacesByDateService(LocalDate.now());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// @GetMapping("get_races_by_venue_id")
|
|
||||||
// public List<RaceNumber> getRacesByVenueId(@RequestParam final int venueId){
|
|
||||||
//
|
//
|
||||||
// System.out.println(venueId);
|
// @GetMapping("/get_race_card")
|
||||||
|
// public ResponseEntity<RaceCard> getRaceCard(){
|
||||||
//
|
//
|
||||||
// return this.btcRaceService.getRaceNumbersByVenueId(venueId);
|
// return this.btcRaceService.getRaceCard(LocalDate.now());
|
||||||
// }
|
// }
|
||||||
|
//}
|
||||||
@GetMapping("/get_all_races_by_today")
|
|
||||||
public List<RaceNumber> getAllRacesByDateController(){
|
|
||||||
|
|
||||||
return this.btcRaceService.getAllRacesByDateService(LocalDate.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/get_race_card")
|
|
||||||
public ResponseEntity<RaceCard> getRaceCard(){
|
|
||||||
|
|
||||||
return this.btcRaceService.getRaceCard(LocalDate.now());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import com.example.cezenBTC.DTO.ReturnStatus;
|
|||||||
import com.example.cezenBTC.DTO.user.AdminSetPasswordDTO;
|
import com.example.cezenBTC.DTO.user.AdminSetPasswordDTO;
|
||||||
import com.example.cezenBTC.DTO.user.UserDataDTO;
|
import com.example.cezenBTC.DTO.user.UserDataDTO;
|
||||||
import com.example.cezenBTC.absbridge.model.LoginRequest;
|
import com.example.cezenBTC.absbridge.model.LoginRequest;
|
||||||
import com.example.cezenBTC.entity.user.UserEntity;
|
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||||
import com.example.cezenBTC.service.ABS.ABSServiceForLogIn;
|
import com.example.cezenBTC.service.ABS.ABSServiceForLogIn;
|
||||||
import com.example.cezenBTC.service.BtcUserService;
|
//import com.example.cezenBTC.service.BtcUserService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
@ -18,39 +18,39 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@RequestMapping("/open")
|
@RequestMapping("/open")
|
||||||
public class SignUpController {
|
public class SignUpController {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private BtcUserService btcUserService;
|
// private BtcUserService btcUserService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ABSServiceForLogIn absServiceForLogIn;
|
private ABSServiceForLogIn absServiceForLogIn;
|
||||||
|
|
||||||
|
|
||||||
//sign up route
|
// //sign up route
|
||||||
@PostMapping("/signup")
|
// @PostMapping("/signup")
|
||||||
public ReturnStatus signUp(@RequestBody @Valid AdminSetPasswordDTO adminSetPasswordDTO){
|
// public ReturnStatus signUp(@RequestBody @Valid AdminSetPasswordDTO adminSetPasswordDTO){
|
||||||
|
//
|
||||||
return this.btcUserService.adminSetUserNamePasswordSet(
|
// return this.btcUserService.adminSetUserNamePasswordSet(
|
||||||
adminSetPasswordDTO.userName(),
|
// adminSetPasswordDTO.userName(),
|
||||||
adminSetPasswordDTO.password(),
|
// adminSetPasswordDTO.password(),
|
||||||
adminSetPasswordDTO.confirmPassword()
|
// adminSetPasswordDTO.confirmPassword()
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// and a login route
|
// // and a login route
|
||||||
@GetMapping("/login/old")
|
// @GetMapping("/login/old")
|
||||||
public UserDataDTO loginOld(){
|
// public UserDataDTO loginOld(){
|
||||||
|
//
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
//
|
||||||
// this is to venerate karthik garu and hamu
|
// // this is to venerate karthik garu and hamu
|
||||||
String[] garuHamu = authentication.getName().split(",");
|
// String[] garuHamu = authentication.getName().split(",");
|
||||||
|
//
|
||||||
System.out.println("User Id is " + garuHamu[0] + "the betting terminal id is " + garuHamu[1]);
|
// System.out.println("User Id is " + garuHamu[0] + "the betting terminal id is " + garuHamu[1]);
|
||||||
|
//
|
||||||
UserEntity userEntity = this.btcUserService.getUserByUserId(garuHamu[0]);
|
// UserEntity userEntity = this.btcUserService.getUserByUserId(garuHamu[0]);
|
||||||
|
//
|
||||||
return new UserDataDTO(userEntity.getUserIdNumber(), userEntity.getUserName(), garuHamu[1], null);
|
// return new UserDataDTO(userEntity.getUserIdNumber(), userEntity.getUserName(), garuHamu[1], null);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,42 +1,42 @@
|
|||||||
package com.example.cezenBTC.entity.btc_entity;
|
//package com.example.cezenBTC.entity.btc_entity;
|
||||||
|
//
|
||||||
import jakarta.persistence.Column;
|
//import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
//import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
//import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
//import jakarta.persistence.Table;
|
||||||
|
//
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "ip_to_device")
|
//@Table(name = "ip_to_device")
|
||||||
public class IpToDevice {
|
//public class IpToDevice {
|
||||||
|
//
|
||||||
@Id
|
// @Id
|
||||||
@Column(name = "ip_address")
|
// @Column(name = "ip_address")
|
||||||
private String ipAddress;
|
// private String ipAddress;
|
||||||
|
//
|
||||||
@Column(name = "sys_data_only")
|
// @Column(name = "sys_data_only")
|
||||||
private int device_id;
|
// private int device_id;
|
||||||
|
//
|
||||||
public IpToDevice(String ipAddress, int device_id) {
|
// public IpToDevice(String ipAddress, int device_id) {
|
||||||
this.ipAddress = ipAddress;
|
// this.ipAddress = ipAddress;
|
||||||
this.device_id = device_id;
|
// this.device_id = device_id;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public IpToDevice() {
|
// public IpToDevice() {
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String getIpAddress() {
|
// public String getIpAddress() {
|
||||||
return ipAddress;
|
// return ipAddress;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setIpAddress(String ipAddress) {
|
// public void setIpAddress(String ipAddress) {
|
||||||
this.ipAddress = ipAddress;
|
// this.ipAddress = ipAddress;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getDevice_id() {
|
// public int getDevice_id() {
|
||||||
return device_id;
|
// return device_id;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setDevice_id(int device_id) {
|
// public void setDevice_id(int device_id) {
|
||||||
this.device_id = device_id;
|
// this.device_id = device_id;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,71 +1,71 @@
|
|||||||
package com.example.cezenBTC.entity.btc_entity;
|
//package com.example.cezenBTC.entity.btc_entity;
|
||||||
|
//
|
||||||
import jakarta.persistence.*;
|
//import jakarta.persistence.*;
|
||||||
|
//
|
||||||
import java.time.LocalDate;
|
//import java.time.LocalDate;
|
||||||
|
//
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "race_number")
|
//@Table(name = "race_number")
|
||||||
public class RaceNumber {
|
//public class RaceNumber {
|
||||||
|
//
|
||||||
@Id
|
// @Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
// @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "race_id", columnDefinition = "serial")
|
// @Column(name = "race_id", columnDefinition = "serial")
|
||||||
private int raceId;
|
// private int raceId;
|
||||||
|
//
|
||||||
@Column(name = "sys_data_only")
|
// @Column(name = "sys_data_only")
|
||||||
private LocalDate sysDataOnly;
|
// private LocalDate sysDataOnly;
|
||||||
|
//
|
||||||
@ManyToOne(
|
// @ManyToOne(
|
||||||
fetch = FetchType.EAGER,
|
// fetch = FetchType.EAGER,
|
||||||
cascade = {
|
// cascade = {
|
||||||
CascadeType.MERGE,
|
// CascadeType.MERGE,
|
||||||
CascadeType.DETACH,
|
// CascadeType.DETACH,
|
||||||
CascadeType.PERSIST,
|
// CascadeType.PERSIST,
|
||||||
CascadeType.REFRESH
|
// CascadeType.REFRESH
|
||||||
}
|
// }
|
||||||
)
|
// )
|
||||||
@JoinColumn(name = "race_venue_id")
|
// @JoinColumn(name = "race_venue_id")
|
||||||
private RaceVenue raceVenue;
|
// private RaceVenue raceVenue;
|
||||||
|
//
|
||||||
@Column(name = "number_of_races")
|
// @Column(name = "number_of_races")
|
||||||
private int numberOfRace;
|
// private int numberOfRace;
|
||||||
|
//
|
||||||
|
//
|
||||||
public RaceNumber(LocalDate sysDataOnly, RaceVenue raceVenue, int numberOfRace) {
|
// public RaceNumber(LocalDate sysDataOnly, RaceVenue raceVenue, int numberOfRace) {
|
||||||
this.sysDataOnly = sysDataOnly;
|
// this.sysDataOnly = sysDataOnly;
|
||||||
this.raceVenue = raceVenue;
|
// this.raceVenue = raceVenue;
|
||||||
this.numberOfRace = numberOfRace;
|
// this.numberOfRace = numberOfRace;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public RaceNumber() {
|
// public RaceNumber() {
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getRaceId() {
|
// public int getRaceId() {
|
||||||
return raceId;
|
// return raceId;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public LocalDate getSysDataOnly() {
|
// public LocalDate getSysDataOnly() {
|
||||||
return sysDataOnly;
|
// return sysDataOnly;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setSysDataOnly(LocalDate sysDataOnly) {
|
// public void setSysDataOnly(LocalDate sysDataOnly) {
|
||||||
this.sysDataOnly = sysDataOnly;
|
// this.sysDataOnly = sysDataOnly;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public RaceVenue getRaceVenue() {
|
// public RaceVenue getRaceVenue() {
|
||||||
return raceVenue;
|
// return raceVenue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setRaceVenue(RaceVenue raceVenue) {
|
// public void setRaceVenue(RaceVenue raceVenue) {
|
||||||
this.raceVenue = raceVenue;
|
// this.raceVenue = raceVenue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getNumberOfRace() {
|
// public int getNumberOfRace() {
|
||||||
return numberOfRace;
|
// return numberOfRace;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setNumberOfRace(int numberOfRace) {
|
// public void setNumberOfRace(int numberOfRace) {
|
||||||
this.numberOfRace = numberOfRace;
|
// this.numberOfRace = numberOfRace;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,50 +1,50 @@
|
|||||||
package com.example.cezenBTC.entity.btc_entity;
|
//package com.example.cezenBTC.entity.btc_entity;
|
||||||
|
//
|
||||||
import jakarta.persistence.*;
|
//import jakarta.persistence.*;
|
||||||
|
//
|
||||||
import java.util.LinkedList;
|
//import java.util.LinkedList;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "race_venue")
|
//@Table(name = "race_venue")
|
||||||
public class RaceVenue {
|
//public class RaceVenue {
|
||||||
|
//
|
||||||
@Id
|
// @Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
// @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "race_venue_id", columnDefinition = "serial")
|
// @Column(name = "race_venue_id", columnDefinition = "serial")
|
||||||
private int raceVenueId;
|
// private int raceVenueId;
|
||||||
|
//
|
||||||
@Column(name = "venue")
|
// @Column(name = "venue")
|
||||||
private String venue;
|
// private String venue;
|
||||||
|
//
|
||||||
@OneToMany(
|
// @OneToMany(
|
||||||
fetch = FetchType.LAZY,
|
// fetch = FetchType.LAZY,
|
||||||
mappedBy = "raceVenue",
|
// mappedBy = "raceVenue",
|
||||||
cascade = {
|
// cascade = {
|
||||||
CascadeType.MERGE,
|
// CascadeType.MERGE,
|
||||||
CascadeType.DETACH,
|
// CascadeType.DETACH,
|
||||||
CascadeType.PERSIST,
|
// CascadeType.PERSIST,
|
||||||
CascadeType.REFRESH
|
// CascadeType.REFRESH
|
||||||
}
|
// }
|
||||||
)
|
// )
|
||||||
private List<RaceNumber> raceNumbers;
|
// private List<RaceNumber> raceNumbers;
|
||||||
|
//
|
||||||
public RaceVenue(String venue) {
|
// public RaceVenue(String venue) {
|
||||||
this.venue = venue;
|
// this.venue = venue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public RaceVenue() {
|
// public RaceVenue() {
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getRaceVenueId() {
|
// public int getRaceVenueId() {
|
||||||
return raceVenueId;
|
// return raceVenueId;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String getVenue() {
|
// public String getVenue() {
|
||||||
return venue;
|
// return venue;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setVenue(String venue) {
|
// public void setVenue(String venue) {
|
||||||
this.venue = venue;
|
// this.venue = venue;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,65 +1,65 @@
|
|||||||
package com.example.cezenBTC.entity.user;
|
//package com.example.cezenBTC.entity.user;
|
||||||
|
//
|
||||||
import jakarta.persistence.*;
|
//import jakarta.persistence.*;
|
||||||
|
//
|
||||||
import java.util.Collection;
|
//import java.util.Collection;
|
||||||
|
//
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "roles")
|
//@Table(name = "roles")
|
||||||
final public class Role {
|
//final public class Role {
|
||||||
|
//
|
||||||
@Id
|
// @Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
// @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "role_id", columnDefinition = "serial")
|
// @Column(name = "role_id", columnDefinition = "serial")
|
||||||
private int id;
|
// private int id;
|
||||||
|
//
|
||||||
//remember ROLE_
|
// //remember ROLE_
|
||||||
@Column(name = "role_name")
|
// @Column(name = "role_name")
|
||||||
private String role;
|
// private String role;
|
||||||
|
//
|
||||||
//all employees under this role
|
// //all employees under this role
|
||||||
// map by may be required
|
// // map by may be required
|
||||||
@ManyToMany(
|
// @ManyToMany(
|
||||||
fetch = FetchType.LAZY,
|
// fetch = FetchType.LAZY,
|
||||||
cascade = {
|
// cascade = {
|
||||||
//The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
|
// //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
|
||||||
CascadeType.DETACH,
|
// CascadeType.DETACH,
|
||||||
CascadeType.MERGE,
|
// CascadeType.MERGE,
|
||||||
CascadeType.PERSIST,
|
// CascadeType.PERSIST,
|
||||||
CascadeType.REFRESH,
|
// CascadeType.REFRESH,
|
||||||
}
|
// }
|
||||||
//cascade = CascadeType.ALL
|
// //cascade = CascadeType.ALL
|
||||||
)
|
// )
|
||||||
@JoinTable(
|
// @JoinTable(
|
||||||
name = "user_roles",
|
// name = "user_roles",
|
||||||
joinColumns = @JoinColumn(name = "role_id"),
|
// joinColumns = @JoinColumn(name = "role_id"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "u_id")
|
// inverseJoinColumns = @JoinColumn(name = "u_id")
|
||||||
)
|
// )
|
||||||
private Collection<UserEntity> employees;
|
// private Collection<UserEntity> employees;
|
||||||
|
//
|
||||||
public Role(){}
|
// public Role(){}
|
||||||
|
//
|
||||||
public Role(String role) {
|
// public Role(String role) {
|
||||||
this.role = role;
|
// this.role = role;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getId() {
|
// public int getId() {
|
||||||
return id;
|
// return id;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public String getRole() {
|
// public String getRole() {
|
||||||
return role;
|
// return role;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setRole(String role) {
|
// public void setRole(String role) {
|
||||||
this.role = role;
|
// this.role = role;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Collection<UserEntity> getEmployees() {
|
// public Collection<UserEntity> getEmployees() {
|
||||||
return employees;
|
// return employees;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setEmployees(Collection<UserEntity> employees) {
|
// public void setEmployees(Collection<UserEntity> employees) {
|
||||||
this.employees = employees;
|
// this.employees = employees;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,98 +1,98 @@
|
|||||||
package com.example.cezenBTC.entity.user;
|
//package com.example.cezenBTC.entity.user;
|
||||||
|
//
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
//import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
//import jakarta.persistence.*;
|
||||||
|
//
|
||||||
import java.util.Collection;
|
//import java.util.Collection;
|
||||||
import java.util.HashSet;
|
//import java.util.HashSet;
|
||||||
|
//
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "users")
|
//@Table(name = "users")
|
||||||
final public class UserEntity {
|
//final public class UserEntity {
|
||||||
|
//
|
||||||
@Id
|
// @Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
// @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "u_id", columnDefinition = "serial")
|
// @Column(name = "u_id", columnDefinition = "serial")
|
||||||
private int id;
|
// private int id;
|
||||||
|
//
|
||||||
@Column(name = "user_id_number")
|
// @Column(name = "user_id_number")
|
||||||
private String userIdNumber;
|
// private String userIdNumber;
|
||||||
|
//
|
||||||
@Column(name = "user_name")
|
// @Column(name = "user_name")
|
||||||
private String userName;
|
// private String userName;
|
||||||
|
//
|
||||||
@JsonIgnore
|
// @JsonIgnore
|
||||||
@Column(name = "user_password")
|
// @Column(name = "user_password")
|
||||||
private String password;
|
// private String password;
|
||||||
|
//
|
||||||
// @Column(name = "user_email_id")
|
//// @Column(name = "user_email_id")
|
||||||
// private String email;
|
//// private String email;
|
||||||
|
//
|
||||||
//ROLE
|
// //ROLE
|
||||||
@ManyToMany(
|
// @ManyToMany(
|
||||||
fetch = FetchType.LAZY,
|
// fetch = FetchType.LAZY,
|
||||||
cascade = {
|
// cascade = {
|
||||||
//The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
|
// //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
|
||||||
CascadeType.DETACH,
|
// CascadeType.DETACH,
|
||||||
CascadeType.MERGE,
|
// CascadeType.MERGE,
|
||||||
CascadeType.PERSIST,
|
// CascadeType.PERSIST,
|
||||||
CascadeType.REFRESH,
|
// CascadeType.REFRESH,
|
||||||
}
|
// }
|
||||||
//cascade = CascadeType.ALL
|
// //cascade = CascadeType.ALL
|
||||||
)
|
// )
|
||||||
@JoinTable(
|
// @JoinTable(
|
||||||
name = "user_roles",
|
// name = "user_roles",
|
||||||
joinColumns = @JoinColumn(name = "u_id"),
|
// joinColumns = @JoinColumn(name = "u_id"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "role_id")
|
// inverseJoinColumns = @JoinColumn(name = "role_id")
|
||||||
)
|
// )
|
||||||
private Collection<Role> roles;
|
// private Collection<Role> roles;
|
||||||
|
//
|
||||||
|
//
|
||||||
public UserEntity(){}
|
// public UserEntity(){}
|
||||||
|
//
|
||||||
// public UserEntity(String userName, String password) {
|
//// public UserEntity(String userName, String password) {
|
||||||
|
//// this.userName = userName;
|
||||||
|
//// this.password = password;
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// public UserEntity(String userIdNumber, String userName, String password) {
|
||||||
|
// this.userIdNumber = userIdNumber;
|
||||||
// this.userName = userName;
|
// this.userName = userName;
|
||||||
// this.password = password;
|
// this.password = password;
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
public UserEntity(String userIdNumber, String userName, String password) {
|
// public int getId() {
|
||||||
this.userIdNumber = userIdNumber;
|
// return id;
|
||||||
this.userName = userName;
|
// }
|
||||||
this.password = password;
|
// public String getUserName() {
|
||||||
}
|
// return userName;
|
||||||
|
// }
|
||||||
public int getId() {
|
// public void setUserName(String userName) {
|
||||||
return id;
|
// this.userName = userName;
|
||||||
}
|
// }
|
||||||
public String getUserName() {
|
// public String getPassword() {
|
||||||
return userName;
|
// return password;
|
||||||
}
|
// }
|
||||||
public void setUserName(String userName) {
|
// public void setPassword(String password) {
|
||||||
this.userName = userName;
|
// this.password = password;
|
||||||
}
|
// }
|
||||||
public String getPassword() {
|
// public Collection<Role> getRoles() {
|
||||||
return password;
|
// return roles;
|
||||||
}
|
// }
|
||||||
public void setPassword(String password) {
|
//
|
||||||
this.password = password;
|
// public String getUserIdNumber() {
|
||||||
}
|
// return userIdNumber;
|
||||||
public Collection<Role> getRoles() {
|
// }
|
||||||
return roles;
|
//
|
||||||
}
|
// public void setUserIdNumber(String userIdNumber) {
|
||||||
|
// this.userIdNumber = userIdNumber;
|
||||||
public String getUserIdNumber() {
|
// }
|
||||||
return userIdNumber;
|
//
|
||||||
}
|
// public void setARole(Role role){
|
||||||
|
// if(this.roles == null){
|
||||||
public void setUserIdNumber(String userIdNumber) {
|
// this.roles = new HashSet<Role>();
|
||||||
this.userIdNumber = userIdNumber;
|
// }
|
||||||
}
|
//
|
||||||
|
// this.roles.add(role);
|
||||||
public void setARole(Role role){
|
// }
|
||||||
if(this.roles == null){
|
//}
|
||||||
this.roles = new HashSet<Role>();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.roles.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,129 +1,129 @@
|
|||||||
package com.example.cezenBTC.service;
|
//package com.example.cezenBTC.service;
|
||||||
|
//
|
||||||
import com.example.cezenBTC.DAO.BtcOpsDAO;
|
//import com.example.cezenBTC.DAO.BtcOpsDAO;
|
||||||
import com.example.cezenBTC.DTO.ReturnStatus;
|
//import com.example.cezenBTC.DTO.ReturnStatus;
|
||||||
import com.example.cezenBTC.DTO.race_card.Pools;
|
//import com.example.cezenBTC.DTO.race_card.Pools;
|
||||||
import com.example.cezenBTC.DTO.race_card.RaceCard;
|
//import com.example.cezenBTC.DTO.race_card.RaceCard;
|
||||||
import com.example.cezenBTC.DTO.race_card.RaceVenueRaces;
|
//import com.example.cezenBTC.DTO.race_card.RaceVenueRaces;
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
//import com.example.cezenBTC.entity.btc_entity.RaceNumber;
|
||||||
import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
//import com.example.cezenBTC.entity.btc_entity.RaceVenue;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
//import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
//import org.springframework.stereotype.Service;
|
||||||
|
//
|
||||||
import java.time.LocalDate;
|
//import java.time.LocalDate;
|
||||||
import java.util.*;
|
//import java.util.*;
|
||||||
|
//
|
||||||
@Service
|
//@Service
|
||||||
public class BtcRaceService {
|
//public class BtcRaceService {
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private BtcOpsDAO btcOpsDAO;
|
// private BtcOpsDAO btcOpsDAO;
|
||||||
|
//
|
||||||
|
//
|
||||||
public ReturnStatus addARaceVenue(String raceName){
|
// public ReturnStatus addARaceVenue(String raceName){
|
||||||
try{
|
// try{
|
||||||
return this.btcOpsDAO.sentARaceVenue(new RaceVenue(raceName));
|
// return this.btcOpsDAO.sentARaceVenue(new RaceVenue(raceName));
|
||||||
}catch (Exception e){
|
// }catch (Exception e){
|
||||||
return new ReturnStatus(false, "Duplicate race name", "");
|
// return new ReturnStatus(false, "Duplicate race name", "");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
/*
|
// /*
|
||||||
*
|
// *
|
||||||
* this.sysDataOnly = sysDataOnly;
|
// * this.sysDataOnly = sysDataOnly;
|
||||||
this.raceVenue = raceVenue;
|
// this.raceVenue = raceVenue;
|
||||||
this.numberOfRace = numberOfRace;
|
// this.numberOfRace = numberOfRace;
|
||||||
*
|
// *
|
||||||
* */
|
// * */
|
||||||
|
//
|
||||||
public ReturnStatus addARaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace){
|
// public ReturnStatus addARaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace){
|
||||||
|
//
|
||||||
// null here ... raceVenue will
|
// // null here ... raceVenue will
|
||||||
try{
|
// try{
|
||||||
return this.btcOpsDAO.setRaceNumber(localDate, raceVenueId, numberOfRace);
|
// return this.btcOpsDAO.setRaceNumber(localDate, raceVenueId, numberOfRace);
|
||||||
}catch (Exception e){
|
// }catch (Exception e){
|
||||||
return new ReturnStatus(false, "Duplicate race number", "");
|
// return new ReturnStatus(false, "Duplicate race number", "");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
public List<RaceVenue> allRaceVenue(){
|
// public List<RaceVenue> allRaceVenue(){
|
||||||
|
//
|
||||||
try{
|
// try{
|
||||||
return this.btcOpsDAO.getAllRaceVenue();
|
// return this.btcOpsDAO.getAllRaceVenue();
|
||||||
}
|
// }
|
||||||
catch (Exception e){
|
// catch (Exception e){
|
||||||
System.out.println("No races found");
|
// System.out.println("No races found");
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
public List<RaceNumber> getRaceNumbersByVenueId(int venueId){
|
// public List<RaceNumber> getRaceNumbersByVenueId(int venueId){
|
||||||
|
//
|
||||||
try{
|
// try{
|
||||||
|
//
|
||||||
return this.btcOpsDAO.getALlRacesByVenueId(venueId);
|
// return this.btcOpsDAO.getALlRacesByVenueId(venueId);
|
||||||
}catch (Exception e){
|
// }catch (Exception e){
|
||||||
System.out.println("No races found");
|
// System.out.println("No races found");
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
public List<RaceNumber> getAllRacesByDateService(LocalDate date){
|
// public List<RaceNumber> getAllRacesByDateService(LocalDate date){
|
||||||
|
//
|
||||||
try{
|
// try{
|
||||||
return this.btcOpsDAO.getAllRacesByDate(date);
|
// return this.btcOpsDAO.getAllRacesByDate(date);
|
||||||
}catch (Exception e){
|
// }catch (Exception e){
|
||||||
System.out.println("No races found");
|
// System.out.println("No races found");
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public ResponseEntity<RaceCard> getRaceCard(LocalDate date){
|
// public ResponseEntity<RaceCard> getRaceCard(LocalDate date){
|
||||||
|
//
|
||||||
//create race numbers
|
// //create race numbers
|
||||||
Set<Integer> races1 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10));
|
// Set<Integer> races1 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10));
|
||||||
Set<Integer> races2 = new LinkedHashSet<>(List.of(2,4,6,8,10,12));
|
// Set<Integer> races2 = new LinkedHashSet<>(List.of(2,4,6,8,10,12));
|
||||||
Set<Integer> races3 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12));
|
// Set<Integer> races3 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12));
|
||||||
Set<Integer> races4 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,12,13));
|
// Set<Integer> races4 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,12,13));
|
||||||
Set<Integer> races5 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,11,12));
|
// Set<Integer> races5 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,11,12));
|
||||||
Set<Integer> races6 = new LinkedHashSet<>(List.of(2,4,6,8,10,12,13));
|
// Set<Integer> races6 = new LinkedHashSet<>(List.of(2,4,6,8,10,12,13));
|
||||||
Set<Integer> races7 = new LinkedHashSet<>(List.of(1,2,3,5,7,8,9,10,11));
|
// Set<Integer> races7 = new LinkedHashSet<>(List.of(1,2,3,5,7,8,9,10,11));
|
||||||
Set<Integer> races8 = new LinkedHashSet<>(List.of(1,2,3,4,5));
|
// Set<Integer> races8 = new LinkedHashSet<>(List.of(1,2,3,4,5));
|
||||||
|
//
|
||||||
// create a Venue
|
// // create a Venue
|
||||||
Set<Set<Integer>> mysRaces = new LinkedHashSet<>();
|
// Set<Set<Integer>> mysRaces = new LinkedHashSet<>();
|
||||||
mysRaces.add(races1);
|
// mysRaces.add(races1);
|
||||||
mysRaces.add(races2);
|
// mysRaces.add(races2);
|
||||||
mysRaces.add(races3);
|
// mysRaces.add(races3);
|
||||||
mysRaces.add(races4);
|
// mysRaces.add(races4);
|
||||||
mysRaces.add(races5);
|
// mysRaces.add(races5);
|
||||||
mysRaces.add(races6);
|
// mysRaces.add(races6);
|
||||||
mysRaces.add(races7);
|
// mysRaces.add(races7);
|
||||||
mysRaces.add(races8);
|
// mysRaces.add(races8);
|
||||||
RaceVenueRaces raceVenueMYS = new RaceVenueRaces(mysRaces);
|
// RaceVenueRaces raceVenueMYS = new RaceVenueRaces(mysRaces);
|
||||||
|
//
|
||||||
//create a Pool combination
|
// //create a Pool combination
|
||||||
Set<Integer> pool1 = new LinkedHashSet<>(List.of(5, 6, 7));
|
// Set<Integer> pool1 = new LinkedHashSet<>(List.of(5, 6, 7));
|
||||||
Set<Integer> pool2 = new LinkedHashSet<>(List.of(1, 2, 3, 4));
|
// Set<Integer> pool2 = new LinkedHashSet<>(List.of(1, 2, 3, 4));
|
||||||
Set<Integer> pool3 = new LinkedHashSet<>(List.of(2, 3, 4));
|
// Set<Integer> pool3 = new LinkedHashSet<>(List.of(2, 3, 4));
|
||||||
Set<Integer> pool4 = new LinkedHashSet<>(List.of(3, 4, 5, 6, 7));
|
// Set<Integer> pool4 = new LinkedHashSet<>(List.of(3, 4, 5, 6, 7));
|
||||||
|
//
|
||||||
// pole id to pool combo
|
// // pole id to pool combo
|
||||||
Map<String, Set<Integer>> mysPools = new LinkedHashMap<>();
|
// Map<String, Set<Integer>> mysPools = new LinkedHashMap<>();
|
||||||
mysPools.put("TRB1", pool3);
|
// mysPools.put("TRB1", pool3);
|
||||||
mysPools.put("TRB2", pool1);
|
// mysPools.put("TRB2", pool1);
|
||||||
mysPools.put("MJP1", pool2);
|
// mysPools.put("MJP1", pool2);
|
||||||
mysPools.put("JPPI", pool4);
|
// mysPools.put("JPPI", pool4);
|
||||||
Pools mysPool = new Pools(mysPools);
|
// Pools mysPool = new Pools(mysPools);
|
||||||
|
//
|
||||||
RaceCard raceCard = new RaceCard("MYS", date, raceVenueMYS, mysPool);
|
// RaceCard raceCard = new RaceCard("MYS", date, raceVenueMYS, mysPool);
|
||||||
|
//
|
||||||
return ResponseEntity.status(200).body(raceCard);
|
// return ResponseEntity.status(200).body(raceCard);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,39 +1,39 @@
|
|||||||
package com.example.cezenBTC.service;
|
//package com.example.cezenBTC.service;
|
||||||
|
//
|
||||||
import com.example.cezenBTC.DAO.UserOpsDAO;
|
//import com.example.cezenBTC.DAO.UserOpsDAO;
|
||||||
import com.example.cezenBTC.DTO.ReturnStatus;
|
//import com.example.cezenBTC.DTO.ReturnStatus;
|
||||||
import com.example.cezenBTC.entity.user.UserEntity;
|
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
//import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
//import org.springframework.stereotype.Service;
|
||||||
|
//
|
||||||
@Service
|
//@Service
|
||||||
public class BtcUserService {
|
//public class BtcUserService {
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private UserOpsDAO userOpsDAO;
|
// private UserOpsDAO userOpsDAO;
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
// private PasswordEncoder passwordEncoder;
|
||||||
|
//
|
||||||
|
//
|
||||||
// must perform the sanity checks before being set to the database
|
// // must perform the sanity checks before being set to the database
|
||||||
// method will return a faulty return status if the damin exists
|
// // method will return a faulty return status if the damin exists
|
||||||
public ReturnStatus adminSetUserNamePasswordSet(String userId, String userName, String password){
|
// public ReturnStatus adminSetUserNamePasswordSet(String userId, String userName, String password){
|
||||||
// password encryption
|
// // password encryption
|
||||||
UserEntity userEntity = new UserEntity(userId, userName, passwordEncoder.encode(password));
|
// UserEntity userEntity = new UserEntity(userId, userName, passwordEncoder.encode(password));
|
||||||
|
//
|
||||||
// commit the username and password to the database
|
// // commit the username and password to the database
|
||||||
return userOpsDAO.adminSetUsernameAndPassword(userEntity);
|
// return userOpsDAO.adminSetUsernameAndPassword(userEntity);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public UserEntity getUserByUserId(String userNameId){
|
// public UserEntity getUserByUserId(String userNameId){
|
||||||
|
//
|
||||||
try{
|
// try{
|
||||||
return this.userOpsDAO.getUserByUserStringId(userNameId);
|
// return this.userOpsDAO.getUserByUserStringId(userNameId);
|
||||||
}catch ( Exception e){
|
// }catch ( Exception e){
|
||||||
System.out.println("Exception occurred");
|
// System.out.println("Exception occurred");
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
spring.application.name=cezenHorse
|
spring.application.name=cezenHorse
|
||||||
#server.port=8083
|
#server.port=8083
|
||||||
server.port=8081
|
server.port=8080
|
||||||
server.address=0.0.0.0
|
server.address=0.0.0.0
|
||||||
|
|
||||||
spring.datasource.url = jdbc:postgresql://localhost:5434/horse
|
#spring.datasource.url = jdbc:postgresql://localhost:5434/horse
|
||||||
spring.datasource.username = postgres
|
#spring.datasource.username = postgres
|
||||||
spring.datasource.password = root
|
#spring.datasource.password = root
|
||||||
|
|
||||||
#spring.datasource.url = jdbc:postgresql://postgres:5432/horse
|
#spring.datasource.url = jdbc:postgresql://postgres:5432/horse
|
||||||
#spring.datasource.username = postgres
|
#spring.datasource.username = postgres
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user