query
This commit is contained in:
parent
00c562660f
commit
ee27a75ecf
@ -0,0 +1,85 @@
|
|||||||
|
package com.realnet.fnd.controller1;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.realnet.exceptions.ResourceNotFoundException;
|
||||||
|
import com.realnet.fnd.entity1.Query;
|
||||||
|
import com.realnet.fnd.repository1.QueryRepository;
|
||||||
|
import com.realnet.users.entity1.AppUser;
|
||||||
|
import com.realnet.users.service1.AppUserServiceImpl;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/FndQuery", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
@RestController
|
||||||
|
public class QueryController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QueryRepository queryRepository;
|
||||||
|
@Autowired
|
||||||
|
private AppUserServiceImpl userService;
|
||||||
|
|
||||||
|
// ADD DATA
|
||||||
|
@PostMapping("/query")
|
||||||
|
public ResponseEntity<?> add(@RequestBody Query query) {
|
||||||
|
AppUser loggedInUser = userService.getLoggedInUser();
|
||||||
|
query.setAccountId(loggedInUser.getAccount().getAccount_id());
|
||||||
|
query.setCreatedBy(loggedInUser.getUserId());
|
||||||
|
|
||||||
|
Query save = queryRepository.save(query);
|
||||||
|
return new ResponseEntity<>(save, HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET BY ID
|
||||||
|
@GetMapping("/query/{id}")
|
||||||
|
public ResponseEntity<?> get(@PathVariable Long id) {
|
||||||
|
Query query = queryRepository.findById(id).orElseThrow(null);
|
||||||
|
return new ResponseEntity<>(query, HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET ALL
|
||||||
|
@GetMapping("/query")
|
||||||
|
public ResponseEntity<?> getall() {
|
||||||
|
List<Query> query = queryRepository.findAll();
|
||||||
|
return new ResponseEntity<>(query, HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UPDATE BY ID
|
||||||
|
@PutMapping("/query/{id}")
|
||||||
|
public ResponseEntity<?> updateMenuGRPAccess(@PathVariable Long id, @RequestBody Query q) {
|
||||||
|
Query query = queryRepository.findById(id).orElseThrow(null);
|
||||||
|
if (query == null) {
|
||||||
|
throw new ResourceNotFoundException("no resource found");
|
||||||
|
}
|
||||||
|
query.setSql_query(q.getSql_query());
|
||||||
|
query.setQueryname(q.getQueryname());
|
||||||
|
|
||||||
|
Query a = queryRepository.save(query);
|
||||||
|
return new ResponseEntity<>(a, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete BY ID
|
||||||
|
@DeleteMapping("/query/{id}")
|
||||||
|
public void deleteGrpMenuAccess(@PathVariable Long id) {
|
||||||
|
Query query = queryRepository.findById(id).orElseThrow(null);
|
||||||
|
if (Objects.isNull(query))
|
||||||
|
throw new ResourceNotFoundException("no resource found");
|
||||||
|
|
||||||
|
queryRepository.delete(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
28
backend/src/main/java/com/realnet/fnd/entity1/Query.java
Normal file
28
backend/src/main/java/com/realnet/fnd/entity1/Query.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.realnet.fnd.entity1;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import com.realnet.Dashboard1.Entity.dashbord_Who_collumn;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class Query extends dashbord_Who_collumn{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String queryname;
|
||||||
|
private String sql_query;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.realnet.fnd.repository1;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.realnet.fnd.entity1.Query;
|
||||||
|
@Repository
|
||||||
|
public interface QueryRepository extends JpaRepository<Query, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven Integration for Eclipse
|
#Generated by Maven Integration for Eclipse
|
||||||
#Wed Mar 26 23:36:36 IST 2025
|
#Thu Mar 27 17:01:14 IST 2025
|
||||||
artifactId=app
|
artifactId=app
|
||||||
groupId=com.realnet
|
groupId=com.realnet
|
||||||
m2e.projectLocation=/Users/Gaurav Kumar/Desktop/Workspace/Workspace 2/app_builder/build_backend/cns-portal/code-extractor/builders/11096/index/demot1/demot1-test2-b/authsec_springboot/backend
|
m2e.projectLocation=/Users/Gaurav Kumar/Desktop/Workspace/Workspace 2/app_builder/build_backend/cns-portal/code-extractor/builders/11096/index/demot1/demot1-test2-b/authsec_springboot/backend
|
||||||
|
|||||||
Binary file not shown.
BIN
backend/target/classes/com/realnet/fnd/entity1/Query.class
Normal file
BIN
backend/target/classes/com/realnet/fnd/entity1/Query.class
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user