Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Aug 19, 2024
1 parent db6d45c commit be49cb4
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.*;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.job.builder.JobBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Order(Ordered.HIGHEST_PRECEDENCE)
@ControllerAdvice
public class GlobalExceptionHandler {
class GlobalExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class Initializer implements CommandLineRunner {
class Initializer implements CommandLineRunner {

private final CustomerRepository customerRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
@OpenAPIDefinition(
info = @Info(title = "batch-boot-jpa", version = "v1"),
servers = @Server(url = "/"))
public class SwaggerConfig {}
class SwaggerConfig {}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.example.bootbatchjpa.config;

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

@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {
private final ApplicationProperties properties;
@Configuration(proxyBeanMethods = false)
class WebMvcConfig implements WebMvcConfigurer {
private final ApplicationProperties applicationProperties;

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

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(properties.getCors().getPathPattern())
.allowedMethods(properties.getCors().getAllowedMethods())
.allowedHeaders(properties.getCors().getAllowedHeaders())
.allowedOriginPatterns(properties.getCors().getAllowedOriginPatterns())
.allowCredentials(properties.getCors().isAllowCredentials());
public void addCorsMappings(@NonNull CorsRegistry registry) {
ApplicationProperties.Cors propertiesCors = applicationProperties.getCors();
registry.addMapping(propertiesCors.getPathPattern())
.allowedMethods(propertiesCors.getAllowedMethods())
.allowedHeaders(propertiesCors.getAllowedHeaders())
.allowedOriginPatterns(propertiesCors.getAllowedOriginPatterns())
.allowCredentials(propertiesCors.isAllowCredentials());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.example.bootbatchjpa.model.response.PagedResult;
import com.example.bootbatchjpa.services.CustomerService;
import com.example.bootbatchjpa.utils.AppConstants;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -21,13 +20,16 @@

@RestController
@RequestMapping("/api/customers")
@RequiredArgsConstructor
public class CustomerController {
class CustomerController {

private final CustomerService customerService;

CustomerController(CustomerService customerService) {
this.customerService = customerService;
}

@GetMapping
public PagedResult<Customer> getAllCustomers(
PagedResult<Customer> getAllCustomers(
@RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false)
int pageNo,
@RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false)
Expand All @@ -40,7 +42,7 @@ public PagedResult<Customer> getAllCustomers(
}

@GetMapping("/{id}")
public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {
ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {
return customerService
.findCustomerById(id)
.map(ResponseEntity::ok)
Expand All @@ -49,13 +51,12 @@ public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Customer createCustomer(@RequestBody @Validated Customer customer) {
Customer createCustomer(@RequestBody @Validated Customer customer) {
return customerService.saveCustomer(customer);
}

@PutMapping("/{id}")
public ResponseEntity<Customer> updateCustomer(
@PathVariable Long id, @RequestBody Customer customer) {
ResponseEntity<Customer> updateCustomer(@PathVariable Long id, @RequestBody Customer customer) {
return customerService
.findCustomerById(id)
.map(
Expand All @@ -67,7 +68,7 @@ public ResponseEntity<Customer> updateCustomer(
}

@DeleteMapping("/{id}")
public ResponseEntity<Customer> deleteCustomer(@PathVariable Long id) {
ResponseEntity<Customer> deleteCustomer(@PathVariable Long id) {
return customerService
.findCustomerById(id)
.map(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package com.example.bootbatchjpa.web.controllers;

import com.example.bootbatchjpa.config.logging.Loggable;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Loggable
public class JobInvokerController {
@RequestMapping("/api/job")
class JobInvokerController {

private final JobLauncher jobLauncher;

// Declared in BatchConfig
private final Job allCustomersJob;

@GetMapping("/run-allCustomers-job")
public String allCustomersJobHandle(@RequestParam Long minId, @RequestParam Long maxId)
JobInvokerController(JobLauncher jobLauncher, Job allCustomersJob) {
this.jobLauncher = jobLauncher;
this.allCustomersJob = allCustomersJob;
}

@GetMapping("/customers")
String allCustomersJobHandle(@RequestParam Long minId, @RequestParam Long maxId)
throws Exception {

JobParameters jobParameters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface TestContainersConfig {

@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.3-alpine"));
new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("16.4-alpine"));
}

0 comments on commit be49cb4

Please sign in to comment.