Skip to content
New issue

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

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

Already on GitHub? # to your account

Jewellery Management CRUD Operations #44

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion itp-project/Back-End/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.noobstack.jewellery.api;

import com.noobstack.jewellery.model.Jewellery;
import com.noobstack.jewellery.repository.JewelleryRepository;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@CrossOrigin(origins = "http://localhost:5000")
@RestController
@RequestMapping("/api/v2")
public class JewelleryController {

@Autowired
private JewelleryRepository jewelleryRepository;

// get all employees
@GetMapping("/jewellery")
public List<Jewellery> getAllJewellery(){
return jewelleryRepository.findAll();
}

// create employee rest api
@PostMapping("/jewellery")
public Jewellery createJewellery(@RequestBody Jewellery jewellery) {
return jewelleryRepository.save(jewellery);
}

// get jewellery by id rest api
@GetMapping("/jewellery/{id}")
public ResponseEntity<Jewellery> getJewelleryById(@PathVariable UUID id) {
Jewellery jewellery = jewelleryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("jewellery not exist with id :" + id));
return ResponseEntity.ok(jewellery);
}

// update jewellery rest api

@PutMapping("/jewellery/{id}")
public ResponseEntity<Jewellery> updateJewellery(@PathVariable UUID id, @RequestBody Jewellery jewelleryDetails){
Jewellery jewellery = jewelleryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("jewellery not exist with id :" + id));

jewellery.setName(jewelleryDetails.getName());
jewellery.setMaterial(jewelleryDetails.getMaterial());
jewellery.setSupplyPrice(jewelleryDetails.getSupplyPrice());

Jewellery updatedJewellery = jewelleryRepository.save(jewellery);
return ResponseEntity.ok(updatedJewellery);
}

// delete jewellery rest api
@DeleteMapping("/jewellery/{id}")
public ResponseEntity<Map<String, Boolean>> deleteEmployee(@PathVariable UUID id){
Jewellery jewellery = jewelleryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("jewellery not exist with id :" + id));

jewelleryRepository.delete(jewellery);
Map<String, Boolean> response = new HashMap<>();
response.put("deleted", Boolean.TRUE);
return ResponseEntity.ok(response);
}

/*
private final JewelleryService jewelleryService;

@Autowired
public JewelleryController(JewelleryService jewelleryService) {
this.jewelleryService = jewelleryService;
}

//retrieve all jewelries
@GetMapping("/jewellery")
List<Jewellery> getAllJewelry() {
return this.jewelleryService.getAllJewelry();
}
*/
/*
@Autowired
private JewelleryRepository jewelleryRepository;

// get all jewellery
@GetMapping("/jewellery")
public List<Jewellery> getAllJewellery(){
return jewelleryRepository.findAll();
}

// create jewellery rest api
@PostMapping("/jewellery")
public Jewellery createJewellery(@RequestBody Jewellery jewellery) {
return jewelleryRepository.save(jewellery);
}

// get jewellery by id rest api
@GetMapping("/jewellery/{id}")
public ResponseEntity<Jewellery> getJewelleryById(@PathVariable UUID id) {
Jewellery jewellery = jewelleryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("jewellery not exist with id :" + id));
return ResponseEntity.ok(jewellery);
}




*/

}
8 changes: 8 additions & 0 deletions itp-project/front-end/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions itp-project/front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.20.0",
"crypto-js": "^4.0.0",
"firebase": "^7.22.1",
"mailgun-js": "^0.22.0",
Expand Down
14 changes: 13 additions & 1 deletion itp-project/front-end/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ import ConfirmDriver from "./components/Delivery/DeliveryDriverReport/ConfirmDri
import Report from "./components/Delivery/DeliveryDriverReport/Report";
import Moredetails from "./components/Delivery/DeliveryDriverReport/Moredetails";
import CancelPage from "./components/Delivery/DeliverCancelRequest/CancelPage";
import JewelleryDisplay from "./components/Jewellery/JewelleryDisplay";
import JewelleryInfo from "./components/Jewellery/JewelleryInfo";
import JewelleryInsert from "./components/Jewellery/JewelleryInsert";
import UpdateJewellery from "./components/Jewellery/UpdateJewellery";




const App = () => {
return (
Expand Down Expand Up @@ -92,7 +99,12 @@ const App = () => {
<Route path="/ConfirmDriver" exact component={ConfirmDriver} />
<Route path="/Report" exact component={Report} />
<Route path="/More" exact component={Moredetails} />
<Route path="/cancel" exact component={CancelPage} />
<Route path="/cancel" exact component={CancelPage} />
<Route path="/JewelleryDisplay" exact component={JewelleryDisplay} />
<Route path="/jewellery" exact component={JewelleryInfo} />
<Route path="/JewelleryInsert" exact component={JewelleryInsert} />
<Route path="/UpdateJewellery/:id" exact component={UpdateJewellery} />

</Switch>
</div>
<Footer />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Component } from "react";

class JewelleryDisplay extends Component{

style = () => {
return {
marginLeft: "20px",
};
};

render(){
return(
<div align="center">
<h2>Jewellery</h2>
<br/><br/>
<a class="waves-effect black btn-large" href="/jewellery">Display Jewellery</a><br/><br/>
<br/><br/><br/>
</div>

);
}

}

export default JewelleryDisplay;
96 changes: 96 additions & 0 deletions itp-project/front-end/src/components/Jewellery/JewelleryInfo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, { Component } from "react";
import JewelleryService from "../Service/JewelleryService";

class JewelleryInfo extends Component{

constructor(props) {
super(props)
this.state = {
jewellery: []
}
this.addJewelry = this.addJewelry.bind(this);
this.editJewelry = this.editJewelry.bind(this);
this.deleteJewelry = this.deleteJewelry.bind(this);
}


componentDidMount(){
JewelleryService.getJewellery().then((res) => {
this.setState({ jewellery: res.data});
});
}

editJewelry(jewellery_id){
this.props.history.push(`/UpdateJewellery/${jewellery_id}`);
}

addJewelry(){
this.props.history.push('/JewelleryInsert');
}

deleteJewelry(id){
JewelleryService.deleteJewellery(id).then( res => {
this.setState({jewellery: this.state.jewellery.filter(jewellery => jewellery.jewellery_id !== id)});
});
}


render(){
return(
<div>
<h3>All Jewellery</h3>
<br/>
{/*<a class="waves-effect black btn-small" href="/JewelleryInsert">Add New Jewellery</a><br/><br/>*/}
<div className = "row">
<button className="waves-effect black btn-small" onClick={this.addJewelry}>Add New Jewellery</button>
</div>

<br/>
<div className = "row">
<table className = "table table-striped table-bordered">
<thead>
<tr>
<th> Sell / Rent</th>
<th> Material</th>
{/*<th> Category</th>
<th> Description</th>*/}
<th> Supply Price</th>
{/*<th> Discount</th>*/}
<th> Actions</th>
</tr>
</thead>

<tbody>
{
this.state.jewellery.map(
jewellery =>
<tr key = {jewellery.jewellery_id}>
<td>{jewellery.name}</td>
<td>{jewellery.material}</td>
{/*<td>{jewellery.category}</td>
<td>{jewellery.des}</td>*/}
<td>{jewellery.supplyPrice}</td>
{/*<td>{jewellery.discount}</td>*/}
<td>
<button onClick={ () => this.editJewelry(jewellery.jewellery_id)} className="btn btn-info">Update </button>
<button style={{marginLeft: "10px"}} onClick={ () => this.deleteJewelry(jewellery.jewellery_id)} className="btn btn-danger">Delete </button>
</td>
</tr>
)
}
</tbody>
</table>
</div>
<br/>


</div>



);
}

}

export default JewelleryInfo;
21 changes: 21 additions & 0 deletions itp-project/front-end/src/components/Jewellery/JewelleryInsert.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { Component } from "react";
import ValidationForm from "./ValidateJewellery";

class JewelleryInsert extends Component{

state = {
//id: this.props.match.params.id,
visible: true
};

render() {
return (
<div className="JewelleryInsert">
<ValidationForm />
</div>
);
}

}

export default JewelleryInsert;
Loading