fixing ref files
This commit is contained in:
@@ -17,15 +17,16 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import com.realnet.io8ref.Xyz.Entity.Xyz;
|
||||
import com.realnet.io8ref.Xyz.Services.XyzService;
|
||||
|
||||
@RequestMapping(value = "/xyz")
|
||||
@RequestMapping(value = { "/Xyz", "/xyz" })
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
public class XyzController {
|
||||
|
||||
@Autowired
|
||||
private XyzService Service;
|
||||
|
||||
// add data
|
||||
@PostMapping("/Xyz")
|
||||
@PostMapping({ "/Xyz", "/xyz" })
|
||||
public Xyz Savedata(@RequestBody Xyz data) {
|
||||
Xyz save = Service.Savedata(data);
|
||||
|
||||
@@ -33,7 +34,7 @@ public class XyzController {
|
||||
}
|
||||
|
||||
// get all
|
||||
@GetMapping("/Xyz")
|
||||
@GetMapping({ "/Xyz", "/xyz" })
|
||||
public List<Xyz> getdetails() {
|
||||
List<Xyz> get = Service.getdetails();
|
||||
|
||||
@@ -41,7 +42,7 @@ public class XyzController {
|
||||
}
|
||||
|
||||
// getby id
|
||||
@GetMapping("/Xyz/{id}")
|
||||
@GetMapping({ "/Xyz/{id}", "/xyz/{id}" })
|
||||
public Xyz getdetailsbyId(@PathVariable Long id) {
|
||||
Xyz get = Service.getdetailsbyId(id);
|
||||
|
||||
@@ -49,7 +50,7 @@ public class XyzController {
|
||||
}
|
||||
|
||||
// update by id
|
||||
@PutMapping("/Xyz/{id}")
|
||||
@PutMapping({ "/Xyz/{id}", "/xyz/{id}" })
|
||||
public Xyz update(@RequestBody Xyz data, @PathVariable Long id) {
|
||||
Xyz update = Service.update(data, id);
|
||||
|
||||
@@ -57,7 +58,7 @@ public class XyzController {
|
||||
}
|
||||
|
||||
// delete by id
|
||||
@DeleteMapping("/Xyz/{id}")
|
||||
@DeleteMapping({ "/Xyz/{id}", "/xyz/{id}" })
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Long id) {
|
||||
Service.delete_by_id(id);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.realnet.io8ref.Xyz.Repository.XyzRepository;
|
||||
import com.realnet.io8ref.Xyz.Entity.Xyz;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -21,7 +22,7 @@ public class XyzService {
|
||||
}
|
||||
|
||||
public Xyz getdetailsbyId(Long id) {
|
||||
return Repository.findById(id).get();
|
||||
return Repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public void delete_by_id(Long id) {
|
||||
@@ -29,19 +30,11 @@ public class XyzService {
|
||||
}
|
||||
|
||||
public Xyz update(Xyz data, Long id) {
|
||||
Xyz old = Repository.findById(id).get();
|
||||
old.setName(data.getName());
|
||||
old.setDescription(data.getDescription());
|
||||
old.setEmail(data.getEmail());
|
||||
old.setPrice(data.getPrice());
|
||||
old.setQuantity(data.getQuantity());
|
||||
old.setDob(data.getDob());
|
||||
old.setCreatedAt(data.getCreatedAt());
|
||||
old.setActive(data.getActive());
|
||||
old.setStatus(data.getStatus());
|
||||
old.setTags(data.getTags());
|
||||
old.setPhoto(data.getPhoto());
|
||||
old.setCategoryId(data.getCategoryId());
|
||||
return Repository.save(old);
|
||||
Xyz old = Repository.findById(id).orElse(null);
|
||||
if (old != null) {
|
||||
BeanUtils.copyProperties(data, old, "id");
|
||||
return Repository.save(old);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user