Skip to content

Commit

Permalink
feat : delomok
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 17, 2024
1 parent 787830e commit 0497335
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 39 deletions.

This file was deleted.

5 changes: 0 additions & 5 deletions jpa/keyset-pagination/boot-data-window-pagination/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.example.keysetpagination.config;

import jakarta.validation.Valid;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.validation.annotation.Validated;

@Data
@ConfigurationProperties("application")
@Validated
public class ApplicationProperties {
Expand All @@ -15,12 +13,59 @@ public class ApplicationProperties {
@Valid
private Cors cors = new Cors();

@Data
public Cors getCors() {
return cors;
}

public void setCors(Cors cors) {
this.cors = cors;
}

public static class Cors {
private String pathPattern = "/api/**";
private String allowedMethods = "*";
private String allowedHeaders = "*";
private String allowedOriginPatterns = "*";
private boolean allowCredentials = true;

public boolean isAllowCredentials() {
return allowCredentials;
}

public void setAllowCredentials(boolean allowCredentials) {
this.allowCredentials = allowCredentials;
}

public String getAllowedHeaders() {
return allowedHeaders;
}

public void setAllowedHeaders(String allowedHeaders) {
this.allowedHeaders = allowedHeaders;
}

public String getAllowedMethods() {
return allowedMethods;
}

public void setAllowedMethods(String allowedMethods) {
this.allowedMethods = allowedMethods;
}

public String getAllowedOriginPatterns() {
return allowedOriginPatterns;
}

public void setAllowedOriginPatterns(String allowedOriginPatterns) {
this.allowedOriginPatterns = allowedOriginPatterns;
}

public String getPathPattern() {
return pathPattern;
}

public void setPathPattern(String pathPattern) {
this.pathPattern = pathPattern;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.example.keysetpagination.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
class Initializer implements CommandLineRunner {

private static final Logger log = LoggerFactory.getLogger(Initializer.class);
private final ApplicationProperties properties;

Check warning on line 12 in jpa/keyset-pagination/boot-data-window-pagination/src/main/java/com/example/keysetpagination/config/Initializer.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field can be local

Field can be converted to a local variable

Initializer(ApplicationProperties properties) {
this.properties = properties;
}

@Override
public void run(String... args) {
log.info("Running Initializer.....");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.example.keysetpagination.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
class WebMvcConfig implements WebMvcConfigurer {
private final ApplicationProperties properties;

WebMvcConfig(ApplicationProperties properties) {
this.properties = properties;
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(properties.getCors().getPathPattern())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.Hibernate;

@Entity
@Table(name = "animals", schema = "public")
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Animal extends Auditable {

@Id
Expand All @@ -36,28 +29,54 @@ public class Animal extends Auditable {
@Version
private Short version;

public Animal() {}

public Animal(Long id, String name, String type, String habitat, Short version) {
this.id = id;
this.name = name;
this.type = type;
this.habitat = habitat;
this.version = version;
}

public Long getId() {
return id;
}

public Animal setId(Long id) {
this.id = id;
return this;
}

public String getName() {
return name;
}

public Animal setName(String name) {
this.name = name;
return this;
}

public String getType() {
return type;
}

public Animal setType(String type) {
this.type = type;
return this;
}

public String getHabitat() {
return habitat;
}

public Animal setHabitat(String habitat) {
this.habitat = habitat;
return this;
}

public void setCreated(LocalDateTime created) {
this.created = created;
public Short getVersion() {
return version;
}

public Animal setVersion(Short version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
@Setter
@Getter
public abstract class Auditable {

@CreatedDate
@Column(nullable = false, updatable = false)
protected LocalDateTime created;

public LocalDateTime getCreated() {
return created;
}

public void setCreated(LocalDateTime created) {
this.created = created;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor

public class SearchCriteria {

@NotNull(message = "Operator cannot be null") private QueryOperator queryOperator;
Expand All @@ -24,4 +16,36 @@ public class SearchCriteria {
@NotNull(message = "Values list cannot be null") @Size(min = 1, message = "Values list cannot be empty")
@Valid
private List<String> values;

public SearchCriteria() {}

public SearchCriteria(QueryOperator queryOperator, String field, List<String> values) {
this.queryOperator = queryOperator;
this.field = field;
this.values = values;
}

public QueryOperator getQueryOperator() {
return queryOperator;
}

public void setQueryOperator(QueryOperator queryOperator) {
this.queryOperator = queryOperator;
}

public String getField() {
return field;
}

public void setField(String field) {
this.field = field;
}

public List<String> getValues() {
return values;
}

public void setValues(List<String> values) {
this.values = values;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import jakarta.validation.constraints.Min;
import java.net.URI;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Window;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -34,12 +33,15 @@

@RestController
@RequestMapping("/api/animals")
@RequiredArgsConstructor
@Validated
class AnimalController {

private final AnimalService animalService;

public AnimalController(AnimalService animalService) {
this.animalService = animalService;
}

@GetMapping
PagedResult<AnimalResponse> getAllAnimals(
@RequestParam(value = "pageNo", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false)
Expand Down

0 comments on commit 0497335

Please sign in to comment.