New Text Document
New Text Document
RestController;
import com.template.Class.Constants;
import com.template.Class.Util;
import com.template.Controller.BaseController;
import com.template.Exception.InvalidInputException;
import com.template.ImageProcessing.PropImageQualityChecker;
import com.template.Projection.PropIndexProjection;
import com.template.Service.Table.CompanyXmlsService;
import com.template.Service.Table.PropertyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import com.template.Class.ApiResponse;
import com.template.Model.Table.Property;
import com.template.Model.Table.PropertyImages;
import com.template.Repository.Table.PropertyImagesRep;
import com.template.Repository.Table.PropertyRep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.template.Class.Constants;
import com.template.Class.UserInformation;
import com.template.Class.Util;
import com.template.Controller.BaseController;
import com.template.Controller.Table.PropertyController;
import com.template.Exception.InvalidInputException;
import com.template.ImageProcessing.PropImageQualityChecker;
import com.template.Projection.PropIndexProjection;
import com.template.Service.Table.PropertyService;
import jakarta.xml.bind.DatatypeConverter;
@RestController
public class PropertyRestControler extends BaseController {
private static final Logger logger =
LoggerFactory.getLogger(PropertyRestControler.class);
private String name = "property";
@Autowired
PropertyService propertyService;
@Autowired
CompanyXmlsService companyXmlsService;
PropertyRep propertyRep;
@Autowired
PropertyImagesRep propertyImagesRep;
@PostMapping("/quality")
public ResponseEntity<String> checkImageQuality(@RequestParam("file")
MultipartFile file) {
PropImageQualityChecker propImageQualityChecker = null;
if (qualityCheck) {
logger.info("Image quality is acceptable.");
@GetMapping("/property/agentIndex")
public List<PropIndexProjection> index(Model model, @RequestParam("id") int
agentId) {
logger.info("Fetching {} Index for Agent ID - {}- {}", name, agentId,
userInformationService.getLoginUserID());
List<PropIndexProjection> propertyList = new
ArrayList<PropIndexProjection>();
Page<PropIndexProjection> properties = null;
String result = null;
if (Util.isNotZeroNullNumber(agentId)) {
propertyList = propertyService.getAgentProperties(agentId);
// if (properties.getContent() != null &&
properties.getContent().size() > 0) {
// PropertyList = properties.getContent();
// }
model.addAttribute("list", propertyList);
model.addAttribute("flag", Constants.AGENT_FLAG);
// model.addAttribute("page", PropertyList);
} else {
logger.error("Agent ID Is Null OR Zero");
throw new InvalidInputException("Agent ID Is Null OR Zero");
}
@PostMapping("/property/ddd")
public ResponseEntity<String> deleteRecords(@RequestBody List<Long>
selectedIds) {
System.err.println("******************************************");
try {
selectedIds.forEach(id -> {
System.err.println("Deleting record with ID: " + id);
});
@PostMapping("/companyXmls/deleterecords")
public ResponseEntity<String> deleteRecordsCompanyXmls(@RequestBody
List<Long> selectedIds) {
System.err.println("******************************************");
try {
selectedIds.forEach(id -> {
companyXmlsService.deleteCompanyXmls(Math.toIntExact(id));
System.err.println("Deleting record with ID: " + id);
});
boolean qualityCheck =
propImageQualityChecker.checkImageQuality(tempFile);
if (qualityCheck) {
logger.info("Image quality is acceptable.");
Property prop = propertyRep.findById(id).orElseThrow(() -> new
RuntimeException("Property not found"));
List<PropertyImages> propertyImages =
propertyService.saveProImages(imageFiles, prop);
List<PropertyImages> images =
propertyImagesRep.findByProperty_IDAndIsDeleted(propertyId, 0);
if (images.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new ApiResponse<>("error", "No images found for
the property.", null));
}
int order = 1;
for (Integer imageId : imageIds) {
if (imagesMap.containsKey(imageId)) {
PropertyImages image = imagesMap.get(imageId);
image.setOrder(order++);
propertyImagesRep.save(image);
}
}
Optional<PropertyImages> propertyImageOpt =
propertyImagesRep.findById(id);
if (propertyImageOpt.isPresent()) {
PropertyImages propertyImage = propertyImageOpt.get();
propertyImage.setIs_deleted(1);
propertyImagesRep.save(propertyImage);
return ResponseEntity.ok(new ApiResponse<>(
"success",
"Image marked as deleted.",
null
));
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(
new ApiResponse<>(
"error",
"Image not found.",
null
)
);
}
}
@GetMapping("/activeImages")
public ResponseEntity<ApiResponse<List<PropertyImages>>>
getActiveImagesByPropertyId(@RequestParam("property_id") int propertyId) {
List<PropertyImages> activeImages =
propertyImagesRep.findActiveImagesByPropertyId(propertyId);
if (!activeImages.isEmpty()) {
return ResponseEntity.ok(new ApiResponse<>(
"success",
"Active images retrieved successfully.",
activeImages
));
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(
new ApiResponse<>(
"error",
"No active images found for the specified
property.",
null
)
);
}
}