adding ref files

This commit is contained in:
Azmat-7860
2026-10-22 23:13:02 +05:30
parent 147d52120c
commit 2045e9fdc1
231 changed files with 187 additions and 791 deletions
@@ -7,33 +7,52 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.realnet.logging.NoLogging;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Configuration
public class AppConfig {
// @Bean
// public HibernateJpaSessionFactoryBean sessionFactory() {
// return new HibernateJpaSessionFactoryBean();
// }
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("[MM/dd/yyyy][yyyy-MM-dd][dd/MM/yyyy]");
private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("[yyyy-MM-dd'T'HH:mm:ss][yyyy-MM-dd HH:mm:ss][MM/dd/yyyy HH:mm:ss]");
@NoLogging
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
private ObjectMapper configureMapper(ObjectMapper mapper) {
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DATE_FORMAT));
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("MM/dd/yyyy")));
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DATE_TIME_FORMAT));
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
mapper.registerModule(javaTimeModule);
return mapper;
}
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(mapper);
return converter;
ObjectMapper mapper = configureMapper(new ObjectMapper());
return new MappingJackson2HttpMessageConverter(mapper);
}
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
return configureMapper(new ObjectMapper());
}
}
@@ -0,0 +1,63 @@
package com.realnet.io8ref.Azzu.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
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.io8ref.Azzu.Entity.Azzu;
import com.realnet.io8ref.Azzu.Services.AzzuService;
@RequestMapping(value = { "/Azzu", "/azzu" })
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class AzzuController {
@Autowired
private AzzuService Service;
// add data
@PostMapping({ "/Azzu", "/azzu" })
public Azzu Savedata(@RequestBody Azzu data) {
Azzu save = Service.Savedata(data);
return save;
}
// get all
@GetMapping({ "/Azzu", "/azzu" })
public List<Azzu> getdetails() {
List<Azzu> get = Service.getdetails();
return get;
}
// getby id
@GetMapping({ "/Azzu/{id}", "/azzu/{id}" })
public Azzu getdetailsbyId(@PathVariable String id) {
Azzu get = Service.getdetailsbyId(id);
return get;
}
// update by id
@PutMapping({ "/Azzu/{id}", "/azzu/{id}" })
public Azzu update(@RequestBody Azzu data, @PathVariable String id) {
Azzu update = Service.update(data, id);
return update;
}
// delete by id
@DeleteMapping({ "/Azzu/{id}", "/azzu/{id}" })
public ResponseEntity<?> delete_by_id(@PathVariable String id) {
Service.delete_by_id(id);
return new ResponseEntity<>(HttpStatus.OK);
}
}
@@ -0,0 +1,39 @@
package com.realnet.io8ref.Azzu.Entity;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
//@Entity
@Data
@Document
public class Azzu {
@Id
private String id;
private String name;
private String description;
private String email;
private Double price;
private Long quantity;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy")
private LocalDate dob;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
private Boolean active;
private String status;
private String tags;
private String photo;
private Long categoryId;
}
@@ -0,0 +1,10 @@
package com.realnet.io8ref.Azzu.Repository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import com.realnet.io8ref.Azzu.Entity.Azzu;
@Repository
public interface AzzuRepository extends MongoRepository<Azzu, String> {
}
@@ -0,0 +1,42 @@
package com.realnet.io8ref.Azzu.Services;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.realnet.io8ref.Azzu.Entity.Azzu;
import com.realnet.io8ref.Azzu.Repository.AzzuRepository;
@Service
public class AzzuService {
@Autowired
private AzzuRepository Repository;
public Azzu Savedata(Azzu data) {
return Repository.save(data);
}
public List<Azzu> getdetails() {
return Repository.findAll();
}
public Azzu getdetailsbyId(String id) {
return Repository.findById(id).orElse(null);
}
public void delete_by_id(String id) {
Repository.deleteById(id);
}
public Azzu update(Azzu data, String id) {
Azzu old = Repository.findById(id).orElse(null);
if (old != null) {
BeanUtils.copyProperties(data, old, "id");
return Repository.save(old);
}
return null;
}
}