Skip to content

Gambit-chalenge solution #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d9ced5a
intial gambit chalenge app
Ghh84 Mar 5, 2023
84193a0
fechData from live text feed
Ghh84 Mar 5, 2023
70597f8
Define the `header` `main body` and `footer` for display the feched data
Ghh84 Mar 5, 2023
85acbd3
define the `displayResult` component structure and attributes
Ghh84 Mar 5, 2023
615df22
define the reusable `table` component
Ghh84 Mar 5, 2023
2470330
define the reusable `header for table` component
Ghh84 Mar 5, 2023
759f082
define the reusable `tbody` component
Ghh84 Mar 5, 2023
9d1e67f
Pagination component is defined
Ghh84 Mar 5, 2023
1235cc9
Pagination is added to the `displayResult` components
Ghh84 Mar 5, 2023
4324d43
Footer page is defined
Ghh84 Mar 5, 2023
e746df7
define array of variable names
Ghh84 Mar 5, 2023
92303da
add backgraound image
Ghh84 Mar 5, 2023
ffe232d
function for paginate the data is defined
Ghh84 Mar 5, 2023
e2ab216
Adding styles
Ghh84 Mar 5, 2023
41dfae8
Adding login form
Ghh84 Mar 5, 2023
4c802e5
adding login form for authentication the user
Ghh84 Mar 5, 2023
460080f
define reusable input field component
Ghh84 Mar 5, 2023
ccc0851
handling function relate to login and validation of login form compo…
Ghh84 Mar 5, 2023
385a91a
Component for search box
Ghh84 Mar 5, 2023
8660671
Restructure the App and adding of routes
Ghh84 Mar 6, 2023
8394617
Modifying the contents
Ghh84 Mar 6, 2023
b684784
Adding the config file
Ghh84 Mar 6, 2023
c7b230d
Local Authentication service is defined.
Ghh84 Mar 6, 2023
66d4ec9
Mock data are defined as `Json` for authentication locally
Ghh84 Mar 6, 2023
90250e7
Adding the config file
Ghh84 Mar 6, 2023
435fd12
Modify the login form and adding uthentication
Ghh84 Mar 6, 2023
b448cc4
Modify the login form and adding uthentication
Ghh84 Mar 6, 2023
e009367
Modifying the feching and displaying data
Ghh84 Mar 6, 2023
6d94b54
Add register form component for posting new users
Ghh84 Mar 6, 2023
30f53f6
Removing file from repo
Ghh84 Mar 6, 2023
2b18251
Bg-image and styles are added in the assets folder
Ghh84 Mar 6, 2023
b9b8f0c
Adding of util functions
Ghh84 Mar 6, 2023
0212ff4
Add package.json file
Ghh84 Mar 6, 2023
d932c8d
README file
Ghh84 Mar 6, 2023
69f60eb
Extracting reusable route as reusable components
Ghh84 Mar 6, 2023
6f9db5a
Code review and fixing bugs
Ghh84 Mar 6, 2023
a3d829d
Adding scripts in `README` file
Ghh84 Mar 6, 2023
6864b92
Modify `README`
Ghh84 Mar 6, 2023
0c2a8c9
Read me file
Ghh84 Mar 7, 2023
39ea683
Code reviews, extracting reusable components
Ghh84 Mar 7, 2023
23b5e6a
Add to read me file
Ghh84 Mar 7, 2023
5898e16
Review and fix bugs
Ghh84 Mar 11, 2023
79772d4
Adding config parameters
Ghh84 Mar 11, 2023
27c8e67
Modify to auth from server
Ghh84 Mar 11, 2023
9a07d93
Add variables name
Ghh84 Mar 11, 2023
0ff78e3
Add error handling
Ghh84 Mar 11, 2023
79595ad
Add of nodejs
Ghh84 Mar 11, 2023
67ed2fc
Remove api folder
Ghh84 Mar 11, 2023
0259ef3
Adding node api
Ghh84 Mar 11, 2023
44bb5b4
Add database connection
Ghh84 Mar 11, 2023
1a146c4
adding routes
Ghh84 Mar 11, 2023
1ad4b93
initial middleware
Ghh84 Mar 11, 2023
a8432f0
Set the `auth controller`
Ghh84 Mar 11, 2023
46c3f23
Set the `user controller`
Ghh84 Mar 11, 2023
6cf1609
Add info
Ghh84 Mar 11, 2023
76db7e4
intial .env
Ghh84 Mar 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gambit/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
61 changes: 61 additions & 0 deletions gambit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

# Create UI for showing the data for user
This project is a code challenge task named ad Gambit-challenge
The folling are scripts and links how to operate it.
## Technology
### Frontend: React with JavaScript
All the compontes, configs services utils for the task is bulid using react with JavaScrip to display the TUF-2000M energy meter reading.
### Backend: nodejs
The 'api' folder hold the nodjs files for authentication user login. User information is saved in MySql. Controllers, middleware, routes are defined
### mysql database
Users info(username, password, name ...) are saved in MySql.

How to run the app
1. npm start form the src
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
2. node server.js
3. open Mysql and put sample data
for creating users Table in demodb database
CREATE TABLE `users` (
`userId` int NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`username` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL,
`role` int NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`city` varchar(45) DEFAULT NULL,
`phone` varchar(45) DEFAULT NULL,
`email` varchar(45) DEFAULT NULL,
`country` varchar(45) DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=4681 DEFAULT CHARSET=utf8mb3;
SELECT * FROM demodb.users;

### Version control: git
used for version control and communicate with gitHub

## Getting Started with Create React App
Run the script in windows explorer or set the security of your browser
For test the project you can see the local saved password in

In the project directory, you can run:
../mockData/users.jsx # temporary username and password are saved there.

N.b: this project is not build
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

About development [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**



28 changes: 28 additions & 0 deletions gambit/api/controllers/auth.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

const _=require('lodash')
const signin = (req, res) => {
const DbConnection=require('../db')
console.log('REQUEST.......',req.body)
var connection=DbConnection
if(!connection._connectCalled ){
connection.connect();
}
const sql="SELECT * from users where username=? AND password=?"
connection.query(sql,[req.body.username,req.body.password],(err,rows)=>{
if(err){
throw err
}else {
if(!_.isEmpty(rows)){
console.log('data sent...',rows[0].name,rows.role)
res.status(200).send({username:rows[0].username,role:rows[0].role,id:rows[0].id,userId:rows[0].userId});
}
else res.status(400).send({ message:'Invalid credentials! Try again' });
}
})
};

const authenticateUser = async (req,res) =>{
res.status(404).send({message:'message' || 'User not authenticated.'});
}
module.exports= {signin, authenticateUser}

74 changes: 74 additions & 0 deletions gambit/api/controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const _=require('lodash')
const DbConnection=require('../db')

var connection=DbConnection
const sql="SELECT * from users"

const getUsers = async (req, res) => {
console.log("came in users controller...........");
connection.query(sql,(err,row)=>{
if(err){
console.log('error occured',err)
}
else{
console.log('returned records')
res.status(200).send(row)
}
})
};
const getUser = async (req, res) => {
console.log("came in users controller...........");
connection.query(sql,(err,row)=>{
if(err){
console.log('error occured',err)
}
else{
console.log('returned records')
res.status(200).send(row)
}
})
};
const updateUser = async (req, res) => {
let values=[]
for (const [key, value] of Object.entries(req.body)) {
console.log(`${key}: ${value}`);
values.push(value)
}
connection.query("UPDATE users SET name=?,city=?,country=?,phone=?,email=?,role=?,username=?,password=? where userId=?",
[values[0],values[1],values[2],values[3],values[4],values[5],values[6],values[7],values[8],values[9]],(err,row)=>{
if(err){
console.log('error adding to transactions',err)
res.status(400).send('Error updating the transaction')
}
else{
console.log('returned records',row)
res.status(200).send(row)
}
})
// }
};
const addUser = async (req, res) => {
let values=[]
for (const [key, value] of Object.entries(req.body)) {
console.log(`${key}: ${value}`);
values.push(value)
}
connection.query("INSERT INTO users (name,city,country,phone,email,role,username,password) VALUES (?)",[values],(err,row)=>{
if(err){
console.log('error adding to users',err)
}
else{
console.log('returned records',row)
res.status(200).send(row)
}
})

};
const deleteUser = (req, res) => {};
module.exports= {
updateUser,
getUser,
getUsers,
addUser,
deleteUser
}
7 changes: 7 additions & 0 deletions gambit/api/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

const mysql=require('mysql')
const {host,user,password,database,port}=require('../src/configs/local')
console.log('DB CONNECTION........')
const DbConnection=mysql.createConnection({host,user,password,database,port})
module.exports=DbConnection

9 changes: 9 additions & 0 deletions gambit/api/middleware/authJwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const verifyToken = (req, res, next) => {
console.log('Came on verify token....')
next();
};

const authJwt = {
verifyToken: verifyToken
};
module.exports = authJwt;
5 changes: 5 additions & 0 deletions gambit/api/middleware/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const authJwt = require("./authJwt");

module.exports = {
authJwt
};
Loading