This project provides backend services for a system managing ingress of students. It handles login, student logs, student statistics and allows student check-in and check-out.
This repository is a submodule of Project Ingress
- GoLang
- PostgreSQL
- Clone the repository.
git clone https://github.com/Kunalvrm555/ingress-backend/`
- Change directory into the project's root directory.
cd ingress_backend
- Set up environment variables in
.env
file.
POSTGRES_USERNAME=<postgres_username>
POSTGRES_PASSWORD=<postgres_password>
ADMIN_USERNAME=<admin_username>
ADMIN_PASSWORD=<admin_password>
USERNAME=<username>
PASSWORD=<password>
JWT_SECRET_KEY=<jwt_secret_key>
- Install the necessary Go dependencies.
go mod download
- Set up the database.Create a new database named
ingress
and use your terminal or GUI to create the necessary tables using the SQL commands below:
CREATE TABLE students (
rollno VARCHAR(50) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
dept VARCHAR(50) NOT NULL,
type VARCHAR(50) NOT NULL
);
CREATE TABLE logs (
rollno VARCHAR(50) NOT NULL,
name VARCHAR(255) NOT NULL,
checkintime TIMESTAMP NOT NULL,
checkouttime TIMESTAMP,
);
CREATE TABLE users (
username VARCHAR(50) PRIMARY KEY,
password VARCHAR(255) NOT NULL,
usertype VARCHAR(50) NOT NULL
);
- Run the application.
go run cmd/main.go
The login service accepts username and password, validates them and if successful, returns a JWT token.
The logs service retrieves and returns a list of student logs - it lists students who have checked in but haven't checked out yet.
The statistics service retrieves and returns the total count of students who have checked in for the day and the count of students who are currently checked in.
The student service handles student check-in and check-out operations.
This application uses a utility script seedUser.go
located in the util folder to seed an initial set of users in the database. The script picks up the credentials from the environment variables.
Note: The students data have to be populated manually or you could write a script to seed the data. The SeedUsers function only seeds the users data.