build_app

This commit is contained in:
risadmin_prod 2024-09-04 09:37:56 +00:00
parent 04353499a4
commit 3ec3887350
8 changed files with 749 additions and 0 deletions

View File

@ -68,6 +68,9 @@ public class BuilderService {
public void callotherService() {
// ADD OTHER SERVICE
addCustomMenu( "Formatest", "Transcations");
executeDump(true, "dump.sql");

View File

@ -0,0 +1,98 @@
package com.realnet.basicp1.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.web.bind.annotation.CrossOrigin;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.realnet.config.EmailService;
import com.realnet.users.entity1.AppUser;
import com.realnet.users.service1.AppUserServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.beans.factory.annotation.*;
import com.realnet.basicp1.Entity.Formatest;
import com.realnet.basicp1.Services.FormatestService ;
@RequestMapping(value = "/Formatest")
@CrossOrigin("*")
@RestController
public class FormatestController {
@Autowired
private FormatestService Service;
@Value("${projectPath}")
private String projectPath;
@PostMapping("/Formatest")
public Formatest Savedata(@RequestBody Formatest data) {
Formatest save = Service.Savedata(data) ;
System.out.println("data saved..." + save);
return save;
}
@PutMapping("/Formatest/{id}")
public Formatest update(@RequestBody Formatest data,@PathVariable Integer id ) {
Formatest update = Service.update(data,id);
System.out.println("data update..." + update);
return update;
}
// get all with pagination
@GetMapping("/Formatest/getall/page")
public Page<Formatest> getall(@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size) {
Pageable paging = PageRequest.of(page, size);
Page<Formatest> get = Service.getAllWithPagination(paging);
return get;
}
@GetMapping("/Formatest")
public List<Formatest> getdetails() {
List<Formatest> get = Service.getdetails();
return get;
}
// get all without authentication
@GetMapping("/token/Formatest")
public List<Formatest> getallwioutsec() {
List<Formatest> get = Service.getdetails();
return get;
}
@GetMapping("/Formatest/{id}")
public Formatest getdetailsbyId(@PathVariable Integer id ) {
Formatest get = Service.getdetailsbyId(id);
return get;
}
@DeleteMapping("/Formatest/{id}")
public void delete_by_id(@PathVariable Integer id ) {
Service.delete_by_id(id);
}
}

View File

@ -0,0 +1,50 @@
package com.realnet.basicp1.Entity;
import lombok.*;
import com.realnet.WhoColumn.Extension;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.*;
@Entity
@Data
public class Formatest extends Extension {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String sname;
private int rollno;
private String contact;
@Column(length = 2000)
private String parag;
private String pass;
@Transient
private String confirmpass;
@Column(length = 2000)
private String textas;
}

View File

@ -0,0 +1,27 @@
package com.realnet.basicp1.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.*;
import com.realnet.basicp1.Entity.Formatest;
@Repository
public interface FormatestRepository extends JpaRepository<Formatest, Integer> {
}

View File

@ -0,0 +1,100 @@
package com.realnet.basicp1.Services;
import com.realnet.basicp1.Repository.FormatestRepository;
import com.realnet.basicp1.Entity.Formatest;import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.realnet.SequenceGenerator.Service.SequenceService;
import com.realnet.Notification.Entity.NotificationService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.realnet.users.service1.AppUserServiceImpl;
import com.realnet.users.entity1.AppUser;
import org.springframework.stereotype.Service;
@Service
public class FormatestService {
@Autowired
private FormatestRepository Repository;
@Autowired
private AppUserServiceImpl userService;
public Formatest Savedata(Formatest data) {
Formatest save = Repository.save(data);
return save;
}
// get all with pagination
public Page<Formatest> getAllWithPagination(Pageable page) {
return Repository.findAll(page);
}
public List<Formatest> getdetails() {
return (List<Formatest>) Repository.findAll();
}
public Formatest getdetailsbyId(Integer id) {
return Repository.findById(id).get();
}
public void delete_by_id(Integer id) {
Repository.deleteById(id);
}
public Formatest update(Formatest data,Integer id) {
Formatest old = Repository.findById(id).get();
old.setSname(data.getSname());
old.setRollno(data.getRollno());
old.setContact(data.getContact());
old.setParag(data.getParag());
old.setPass(data.getPass());
old.setTextas(data.getTextas());
final Formatest test = Repository.save(old);
return test;}
public AppUser getUser() {
AppUser user = userService.getLoggedInUser();
return user;
}}

View File

@ -0,0 +1,2 @@
CREATE TABLE db.Formatest(id BIGINT NOT NULL AUTO_INCREMENT, Textas VARCHAR(400), Parag VARCHAR(400), Pass VARCHAR(400), sname VARCHAR(400), contact VARCHAR(400), rollno VARCHAR(400), PRIMARY KEY (id));

View File

@ -1,3 +1,5 @@
import Formatest from "./Components/BuilderComponents/basicp1/Formatest/Formatest";
import Stt from "./Components/BuilderComponents/feedback_formn/Stt/Stt";
import React from "react";
@ -44,6 +46,9 @@ function App() {
<Route path="/Extension" element={<Extension/>} />
{/* buildercomponents */}
<Route path="/Formatest" element={<Formatest />} />
<Route path="/Stt" element={<Stt />} />

View File

@ -0,0 +1,464 @@
import React, { useEffect, useState } from "react";
import axios from "axios";
import { Modal, Button, Form, Pagination } from "react-bootstrap";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import Table from "react-bootstrap/Table";
const API_URL = `${process.env.REACT_APP_API_URL}/Formatest/Formatest`;
const EntityTable = () => {
const [data, setData] = useState([]);
const [filteredData, setFilteredData] = useState([]);
const [newEntity, setNewEntity] = useState({
sname: "",
rollno: "",
contact: "",
parag: "",
pass: "",
textas: "",
});
const [editEntity, setEditEntity] = useState(null);
const [showEditModal, setShowEditModal] = useState(false);
const [showAddModal, setShowAddModal] = useState(false);
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [deleteEntityId, setDeleteEntityId] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const [itemsPerPage] = useState(5); // Adjust this value as needed
const [searchQuery, setSearchQuery] = useState("");
useEffect(() => {
fetchData();
}, []);
useEffect(() => {
handleSearch();
}, [searchQuery, data]);
const fetchData = async () => {
try {
const response = await axios.get(API_URL, {
headers: { Authorization: `Bearer ${process.env.REACT_APP_API_TOKEN}` },
});
setData(response.data);
} catch (error) {
console.error("Error fetching data:", error);
}
};
const handleDelete = async () => {
try {
await axios.delete(`${API_URL}/${deleteEntityId}`, {
headers: { Authorization: `Bearer ${process.env.REACT_APP_API_TOKEN}` },
});
fetchData();
toast.success("Successfully deleted!");
setShowDeleteModal(false);
} catch (error) {
console.error("Error deleting data:", error);
}
};
const handleAdd = async () => {
try {
await axios.post(API_URL, newEntity, {
headers: { Authorization: `Bearer ${process.env.REACT_APP_API_TOKEN}` },
});
fetchData();
setNewEntity({
sname: "",
rollno: "",
contact: "",
parag: "",
pass: "",
textas: "",
});
setShowAddModal(false);
toast.success("Successfully added!");
} catch (error) {
console.error("Error adding data:", error);
}
};
const handleChange = (e) => {
const { name, value } = e.target;
setNewEntity({ ...newEntity, [name]: value });
};
const handleEditChange = (e) => {
const { name, value } = e.target;
setEditEntity({ ...editEntity, [name]: value });
};
const handleEdit = (entity) => {
setEditEntity(entity);
setShowEditModal(true);
};
const handleUpdate = async () => {
try {
await axios.put(`${API_URL}/${editEntity.id}`, editEntity, {
headers: { Authorization: `Bearer ${process.env.REACT_APP_API_TOKEN}` },
});
fetchData();
setShowEditModal(false);
toast.success("Successfully updated!");
} catch (error) {
console.error("Error updating data:", error);
}
};
const handleSearch = () => {
const filtered = data.filter(
(entity) =>
entity.sname.toLowerCase().includes(searchQuery.toLowerCase()) ||
entity.rollno.toLowerCase().includes(searchQuery.toLowerCase()) ||
entity.contact.toLowerCase().includes(searchQuery.toLowerCase()) ||
entity.parag.toLowerCase().includes(searchQuery.toLowerCase()) ||
entity.pass.toLowerCase().includes(searchQuery.toLowerCase()) ||
entity.textas.toLowerCase().includes(searchQuery.toLowerCase()) );
setFilteredData(filtered);
};
const handlePageChange = (pageNumber) => {
setCurrentPage(pageNumber);
};
// Calculate items for current page
const indexOfLastItem = currentPage * itemsPerPage;
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
const currentItems = filteredData.slice(indexOfFirstItem, indexOfLastItem);
return (
<div className="container mt-5">
<ToastContainer />
<h1 className="mb-4">Entity Table</h1>
<div className="d-flex justify-content-between mb-3">
<Button variant="primary" onClick={() => setShowAddModal(true)}>
Add Entity
</Button>
<Form.Control
type="text"
className="w-25"
placeholder="Search..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
</div>
<Table striped bordered hover responsive variant="dark">
<thead>
<tr>
<th>sname</th>
<th>rollno</th>
<th>contact</th>
<th>parag</th>
<th>pass</th>
<th>textas</th>
</tr>
</thead>
<tbody >
{currentItems.map((entity) => (
<tr key={entity.id}>
<td>{entity.sname}</td>
<td>{entity.rollno}</td>
<td>{entity.contact}</td>
<td>{entity.parag}</td>
<td>{entity.pass}</td>
<td>{entity.textas}</td>
<td>
<Button
variant="warning"
size="sm"
className="me-2"
onClick={() => handleEdit(entity)}
>
Update
</Button>
<Button
variant="danger"
size="sm"
onClick={() => {
setDeleteEntityId(entity.id);
setShowDeleteModal(true);
}}
>
Delete
</Button>
</td>
</tr>
))}
</tbody>
</Table>
<Pagination className="d-flex justify-content-center mt-4">
{Array.from(
{ length: Math.ceil(filteredData.length / itemsPerPage) },
(_, index) => (
<Pagination.Item
key={index + 1}
active={index + 1 === currentPage}
onClick={() => handlePageChange(index + 1)}
>
{index + 1}
</Pagination.Item>
)
)}
</Pagination>
<Modal show={showEditModal} onHide={() => setShowEditModal(false)}>
<Modal.Header closeButton>
<Modal.Title>Edit Entity</Modal.Title>
</Modal.Header>
<Modal.Body>
{editEntity && (
<Form className="bg-dark p-3 text-light rounded">
<div className="form-group">
<label htmlFor="sname">sname</label>
<input
type="text"
className="form-control"
id="sname"
name="sname"
value={formData.sname}
onChange={handleChange}
required
/>
</div>
<Form.Group className="mb-3">
<Form.Label>rollno</Form.Label>
<Form.Control
type="text"
name="rollno"
value={editEntity.rollno}
onChange={handleEditChange}
className="bg-secondary text-light"
/>
</Form.Group>
<div className="form-group">
<label htmlFor="contact">contact</label>
<input
type="tel"
className="form-control"
id="contact"
name="contact"
value={formData.contact}
onChange={handleChange}
required
/>
</div>
<Form.Group className="mb-3">
<Form.Label>Parag</Form.Label>
<Form.Control
type="text"
name="parag"
value={editEntity.parag}
onChange={handleEditChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Pass</Form.Label>
<Form.Control
type="text"
name="pass"
value={editEntity.pass}
onChange={handleEditChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Textas</Form.Label>
<Form.Control
type="text"
name="textas"
value={editEntity.textas}
onChange={handleEditChange}
className="bg-secondary text-light"
/>
</Form.Group>
</Form>
)}
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShowEditModal(false)}>
Close
</Button>
<Button variant="primary" onClick={handleUpdate}>
Save changes
</Button>
</Modal.Footer>
</Modal>
<Modal show={showAddModal} onHide={() => setShowAddModal(false)}>
<Modal.Header closeButton>
<Modal.Title>Add New Entity</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form className="bg-dark p-3 text-light rounded">
<Form.Group className="mb-3">
<Form.Label>sname</Form.Label>
<Form.Control
type="text"
name="sname"
value={newEntity.sname}
onChange={handleChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>rollno</Form.Label>
<Form.Control
type="text"
name="rollno"
value={newEntity.rollno}
onChange={handleChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>contact</Form.Label>
<Form.Control
type="text"
name="contact"
value={newEntity.contact}
onChange={handleChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Parag</Form.Label>
<Form.Control
type="text"
name="parag"
value={newEntity.parag}
onChange={handleChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Pass</Form.Label>
<Form.Control
type="text"
name="pass"
value={newEntity.pass}
onChange={handleChange}
className="bg-secondary text-light"
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Textas</Form.Label>
<Form.Control
type="text"
name="textas"
value={newEntity.textas}
onChange={handleChange}
className="bg-secondary text-light"
/>
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShowAddModal(false)}>
Close
</Button>
<Button variant="primary" onClick={handleAdd}>
Add Entity
</Button>
</Modal.Footer>
</Modal>
<Modal show={showDeleteModal} onHide={() => setShowDeleteModal(false)}>
<Modal.Header closeButton>
<Modal.Title>Confirm Delete</Modal.Title>
</Modal.Header>
<Modal.Body>Are you sure you want to delete this entity?</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShowDeleteModal(false)}>
Cancel
</Button>
<Button variant="danger" onClick={handleDelete}>
Delete
</Button>
</Modal.Footer>
</Modal>
</div>
);
};
export default EntityTable;