Skip to content

Commit 87df1a2

Browse files
committed
-version-6
1 parent fb712f2 commit 87df1a2

File tree

6 files changed

+200
-46
lines changed

6 files changed

+200
-46
lines changed

src/main/java/com/godmode/rest/controller/CloudBackendController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import com.godmode.rest.service.CloudVendorService;
1818
import com.godmode.rest.service.ResourcesService;
1919

20-
import jakarta.annotation.Resource;
21-
2220
@RestController
2321
@RequestMapping("/cloudvendor")
2422
public class CloudBackendController {
@@ -74,13 +72,13 @@ public ResourcesController(ResourcesService resourcesService) {
7472
}
7573

7674
@PostMapping("/save")
77-
public String saveCloudVendor(@RequestBody Resources resources){
75+
public String saveCloudVendor(@RequestBody List<Resources> resources){
7876
// System.out.println(resources.getPricePerHour());
7977
return resourcesService.saveResource(resources);
8078
}
8179

8280
@PostMapping("/update")
83-
public String updateCloudVendor(@RequestBody Resources resources){
81+
public String updateCloudVendor(@RequestBody List<Resources> resources){
8482
return resourcesService.updateResurces(resources);
8583
}
8684

src/main/java/com/godmode/rest/service/ResourcesService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import com.godmode.rest.model.Resources;
55

66
public interface ResourcesService {
7-
public String saveResource(Resources resources);
7+
public String saveResource(List<Resources> resourcesList);
88
public String removeResurces(String id);
9-
public String updateResurces(Resources resources);
9+
public String updateResurces(List<Resources> resources);
1010
public String getTotalPrice(String user_id);
1111
public List<String> getListOfUseresForSpecificVendorId(String resource_id);
1212
public List<Resources> getResourcesBasedOnUser_id(String user_id);

src/main/java/com/godmode/rest/service/implement/CloudBackendServiceImplementation.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,6 @@ class ResourcesServiceImplementation implements ResourcesService{
8282

8383
@Autowired
8484
ResourcesRepository resourcesRepository;
85-
@Autowired
86-
CloudVendorRepository cloudVendorRepository;
87-
88-
@Override
89-
public String saveResource(Resources resources) {
90-
try{
91-
92-
if(!cloudVendorRepository.findById(resources.getVendor_id()).isEmpty())
93-
resourcesRepository.save(resources);
94-
else
95-
throw new CloudVendorNotFoundException("Id Not found");
96-
}
97-
catch(CloudVendorNotFoundException e){
98-
throw new CloudVendorNotFoundException(e.getMessage());
99-
}
100-
101-
return "Data saved Successfully";
102-
}
10385

10486
@Override
10587
public String removeResurces(@PathVariable String id) {
@@ -109,7 +91,7 @@ public String removeResurces(@PathVariable String id) {
10991
}
11092

11193
@Override
112-
public String updateResurces(Resources resources) {
94+
public String updateResurces(List<Resources> resources) {
11395
saveResource(resources);
11496
return "data Updated Successfully";
11597
}
@@ -158,7 +140,15 @@ public List<Resources> getResourcesBasedOnUser_id(String user_id) {
158140
}
159141

160142
return resourcesList;
161-
}
162-
143+
}
163144

145+
@Override
146+
public String saveResource(List<Resources> resourcesList) {
147+
try {
148+
resourcesRepository.saveAll(resourcesList);
149+
} catch (CloudVendorNotFoundException e) {
150+
throw new CloudVendorNotFoundException("Cloud vendor not found: " + e.getMessage());
151+
}
152+
return "Data saved successfully";
153+
}
164154
}

src/main/resources/static/index.html

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ <h5 class="card-title">Bandwidth</h5>
7979
</div>
8080
</div>
8181

82-
<div id="vmDiv">
83-
<table id="vendorTable" border="1">
84-
<thead>
85-
<tr>
86-
<th>Select</th>
87-
<th>Vendor ID</th>
88-
<th>Vendor Name</th>
89-
<th>Vendor Address</th>
90-
<th>Phone Number</th>
91-
<th>Quantity</th>
92-
<th>Price per Hour</th>
93-
</tr>
94-
</thead>
95-
<tbody>
96-
<!-- Rows will be appended here -->
97-
</tbody>
98-
</table>
99-
</div>
100-
10182
<div class="updateDetails">
10283
<div class="update card">
10384
<form id="updateForm">
@@ -119,6 +100,30 @@ <h5 class="card-title">Bandwidth</h5>
119100
<button class="back-button" id="backBtn">Back</button>
120101
</div>
121102

103+
104+
<div id="vmDiv">
105+
<table id="vendorTable" border="1">
106+
<thead>
107+
<tr>
108+
<th>Select</th>
109+
<th>Vendor ID</th>
110+
<th>Vendor Name</th>
111+
<th>Vendor Address</th>
112+
<th>Phone Number</th>
113+
<th>Quantity</th>
114+
<th>Price per Hour</th>
115+
</tr>
116+
</thead>
117+
<tbody>
118+
<!-- Rows will be appended here -->
119+
</tbody>
120+
</table>
121+
<div>
122+
<button id="purchaseBtn" class="btn">Purchase</button>
123+
<button id="backBtnnnnn" class="btn">Back</button>
124+
</div>
125+
</div>
126+
122127
<script src="script.js"></script>
123128
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
124129
</body>

src/main/resources/static/script.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,61 @@ $("#billingBtn").on("click", function() {
290290
});
291291
});
292292

293+
$('#purchaseBtn').click(function() {
294+
let selectedData = [];
295+
296+
$('#vendorTable tbody tr').each(function() {
297+
let row = $(this);
298+
let isSelected = row.find('input[type="checkbox"]').is(':checked');
299+
300+
if (isSelected) {
301+
let resourceData = {
302+
resource_id: Math.floor(100000 + Math.random() * 900000).toString(), // Generate a random 6-digit number as a string
303+
vendor_id: row.find('td:eq(1)').text(),
304+
user_id: $("#fetchUser_Id").text(), // Assuming you have a user ID stored somewhere
305+
typeOfResource: row.find('td:eq(2)').text(), // Assuming you want to use vendorName as the type of resource
306+
quantity: row.find('td:eq(5)').text(),
307+
pricePerHour: row.find('td:eq(6)').text(),
308+
totalNoOfHoursUsed: Math.floor(Math.random() * 41) + 10 // Random number between 10 and 50
309+
};
310+
selectedData.push(resourceData);
311+
}
312+
});
313+
314+
if (selectedData.length === 0) {
315+
alert("No items selected!");
316+
return; // Prevent the request from being sent if no items are selected
317+
}
318+
319+
let jsonData = JSON.stringify(selectedData, null, 2);
320+
console.log(jsonData);
321+
322+
// Send the POST request
323+
$.ajax({
324+
url: '/resources/save', // Replace with your actual server endpoint
325+
type: 'POST',
326+
contentType: 'application/json',
327+
data: jsonData, // Send the JSON data
328+
success: function(response) {
329+
console.log('Server Response:', response);
330+
alert("Data Updated Successfully!");
331+
$("#vmDiv").hide();
332+
$(".afterlogin").show();
333+
},
334+
error: function(xhr, status, error) {
335+
console.error('Error:', error);
336+
alert("Failed to update data: " + error);
337+
}
338+
});
339+
});
340+
293341

342+
$('#backBtnnnnn').click(() => {
343+
// console.log("Back button clicked");
344+
$("#vmDiv").hide();
345+
// console.log("vmDiv hidden");
346+
$(".afterlogin").show();
347+
// console.log("afterlogin shown");
348+
});
294349

295350
});

src/main/resources/static/style.css

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,109 @@ h1 {
435435
#vendorTable tbody tr:last-of-type {
436436
border-bottom: 2px solid #573b8a;
437437
}
438+
439+
440+
body {
441+
margin: 0;
442+
padding: 0;
443+
display: flex;
444+
justify-content: center;
445+
align-items: center;
446+
min-height: 100vh;
447+
font-family: 'Jost', sans-serif;
448+
background: linear-gradient(to bottom, #0f0c29, #302b63, #24243e);
449+
}
450+
451+
#vmDiv {
452+
margin: 20px;
453+
padding: 10px;
454+
background-color: #f9f9f9;
455+
border-radius: 8px;
456+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
457+
}
458+
459+
#vendorTable {
460+
width: 90%;
461+
margin: 25px auto;
462+
font-family: 'Arial', sans-serif;
463+
border-collapse: collapse;
464+
border-radius: 8px;
465+
overflow: hidden;
466+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
467+
background-color: #ffffff;
468+
text-align: center;
469+
}
470+
471+
#vendorTable thead tr {
472+
background-color: #573b8a;
473+
color: #ffffff;
474+
}
475+
476+
#vendorTable th,
477+
#vendorTable td {
478+
padding: 15px 20px;
479+
text-align: center;
480+
font-weight: normal;
481+
color: #333333;
482+
}
483+
484+
#vendorTable th {
485+
font-weight: bold;
486+
text-transform: uppercase;
487+
letter-spacing: 0.1em;
488+
}
489+
490+
#vendorTable tbody tr {
491+
border-bottom: 1px solid #dddddd;
492+
}
493+
494+
#vendorTable tbody tr:nth-of-type(even) {
495+
background-color: #f3f3f3;
496+
}
497+
498+
#vendorTable tbody tr:hover {
499+
background-color: #f1f1f1;
500+
cursor: pointer;
501+
}
502+
503+
#vendorTable tbody tr:last-of-type {
504+
border-bottom: 2px solid #573b8a;
505+
}
506+
507+
#purchaseBtn {
508+
width: 150px;
509+
padding: 10px;
510+
margin: 20px auto;
511+
display: block;
512+
color: #fff;
513+
background: #573b8a;
514+
border: none;
515+
border-radius: 5px;
516+
font-size: 1em;
517+
font-weight: bold;
518+
cursor: pointer;
519+
transition: background 0.2s ease-in;
520+
}
521+
522+
#purchaseBtn:hover {
523+
background: #6d44b8;
524+
}
525+
526+
#backBtnnnnn{
527+
width: 150px;
528+
padding: 10px;
529+
margin: 20px auto;
530+
display: block;
531+
color: #fff;
532+
background: #573b8a;
533+
border: none;
534+
border-radius: 5px;
535+
font-size: 1em;
536+
font-weight: bold;
537+
cursor: pointer;
538+
transition: background 0.2s ease-in;
539+
}
540+
541+
#backBtnnnnn:hover {
542+
background: #6d44b8;
543+
}

0 commit comments

Comments
 (0)