Skip to content
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

Added a Webservice for getting a random quote(Mocked Data) #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions react-frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@
background-color: black;
text-align: center;
color: white;
}

.btnQuote{
float: right;
margin-top: 30px;
background-color: white;
}
2 changes: 2 additions & 0 deletions react-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FooterComponent from './components/FooterComponent';
import CreateEmployeeComponent from './components/CreateEmployeeComponent';
import UpdateEmployeeComponent from './components/UpdateEmployeeComponent';
import ViewEmployeeComponent from './components/ViewEmployeeComponent';
import getAQuote from './components/getAQuote';

function App() {
return (
Expand All @@ -20,6 +21,7 @@ function App() {
<Route path = "/employees" component = {ListEmployeeComponent}></Route>
<Route path = "/add-employee/:id" component = {CreateEmployeeComponent}></Route>
<Route path = "/view-employee/:id" component = {ViewEmployeeComponent}></Route>
<Route path = "/get-a-quote" component= {getAQuote}></Route>
{/* <Route path = "/update-employee/:id" component = {UpdateEmployeeComponent}></Route> */}
</Switch>
</div>
Expand Down
13 changes: 11 additions & 2 deletions react-frontend/src/components/ListEmployeeComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ListEmployeeComponent extends Component {
this.addEmployee = this.addEmployee.bind(this);
this.editEmployee = this.editEmployee.bind(this);
this.deleteEmployee = this.deleteEmployee.bind(this);
this.getQuote = this.getQuote.bind(this);
}

deleteEmployee(id){
Expand All @@ -35,17 +36,24 @@ class ListEmployeeComponent extends Component {
this.props.history.push('/add-employee/_add');
}

getQuote(){
this.props.history.push('/get-a-quote');
}

render() {
return (


<div>
<button className="btnQuote" onClick = {this.getQuote}> Get A Quote</button>
<h2 className="text-center">Employees List</h2>
<div className = "row">
<button className="btn btn-primary" onClick={this.addEmployee}> Add Employee</button>
</div>
<br></br>
<div className = "row">
<table className = "table table-striped table-bordered">

<thead>
<tr>
<th> Employee First Name</th>
Expand All @@ -55,7 +63,8 @@ class ListEmployeeComponent extends Component {
</tr>
</thead>
<tbody>
{

{
this.state.employees.map(
employee =>
<tr key = {employee.id}>
Expand Down
34 changes: 34 additions & 0 deletions react-frontend/src/components/getAQuote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


import React, { Component } from 'react';
import EmployeeService from '../services/EmployeeService';

class getAQuote extends Component {

constructor(props) {
super(props)
this.state = {
QuoteMessage : ''
}
}

componentDidMount(){
EmployeeService.getQuote().then(res => {
this.setState({
QuoteMessage: res.data
})
})
}

render(props) {
return (
<div >
<center><h3>Here is a Quote for you : </h3>
<h1>{this.state.QuoteMessage}</h1>
</center>
</div>
);
}
}

export default getAQuote;
6 changes: 6 additions & 0 deletions react-frontend/src/services/EmployeeService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from 'axios';

const EMPLOYEE_API_BASE_URL = "http://localhost:8080/api/v1/employees";
const GET_A_QUOTE_BASE_URL = "http://localhost:8081/api/v1/get-a-quote"


class EmployeeService {

Expand All @@ -23,6 +25,10 @@ class EmployeeService {
deleteEmployee(employeeId){
return axios.delete(EMPLOYEE_API_BASE_URL + '/' + employeeId);
}

getQuote(){
return axios.get(GET_A_QUOTE_BASE_URL);
}
}

export default new EmployeeService()
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public ResponseEntity<Map<String, Boolean>> deleteEmployee(@PathVariable Long id
response.put("deleted", Boolean.TRUE);
return ResponseEntity.ok(response);
}


@GetMapping("/get-a-quote")
public String returnAQuote() {
int randomQuoteNumber = (int) Math.floor(Math.random() * (quotes.size() - 0) + 0);
return quotes.get(randomQuoteNumber);
}


}
18 changes: 18 additions & 0 deletions springboot-backend/src/main/java/utility/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utility;

import java.util.*;

public class Util {

public List<String> quotes(){
List<String> quotes = new ArrayList<String>(Arrays.asList(
"“That which does not kill us makes us stronger.”",
"“Be who you are and say what you feel, because those who mind don’t matter and those who matter don’t mind.”",
"“We must not allow other people’s limited perceptions to define us.”",
"“Be yourself; everyone else is already taken.”",
"“This above all: to thine own self be true.”"
));
return quotes;
}

}
20 changes: 15 additions & 5 deletions springboot-backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?useSSL=false
#spring.datasource.username=root
#spring.datasource.password=root
#
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
#
#spring.jpa.hibernate.ddl-auto = update

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

spring.jpa.hibernate.ddl-auto = update

server.port = 8081
spring.jpa.show-sql=true

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:testdb
spring.devtools.livereload.enabled = true