Skip to content

Commit

Permalink
polish : remove public where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jun 19, 2024
1 parent 7af86c8 commit 97d518d
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 48 deletions.
9 changes: 0 additions & 9 deletions .gitpod.Dockerfile

This file was deleted.

3 changes: 1 addition & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.

image:
file: .gitpod.Dockerfile
image: gitpod/workspace-java21

vscode:
extensions:
Expand Down
2 changes: 1 addition & 1 deletion spring-modulith-outbox-pattern/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.38.0</version>
<version>2.47.0</version>
</palantirJavaFormat>
<importOrder/>
<removeUnusedImports/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class Initializer implements CommandLineRunner {
class Initializer implements CommandLineRunner {

private final ApplicationProperties properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Aspect
@Component
public class LoggingAspect {
class LoggingAspect {

private final Logger log = LoggerFactory.getLogger(this.getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

@Configuration(proxyBeanMethods = false)
@OpenAPIDefinition(info = @Info(title = "spring-modulith-outbox-pattern", version = "v1"), servers = @Server(url = "/"))
public class SwaggerConfig {}
class SwaggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

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 {
class WebMvcConfig implements WebMvcConfigurer {
private final ApplicationProperties properties;

@Override
public void addCorsMappings(CorsRegistry registry) {
public void addCorsMappings(@NonNull CorsRegistry registry) {
registry.addMapping(properties.getCors().getPathPattern())
.allowedMethods(properties.getCors().getAllowedMethods())
.allowedHeaders(properties.getCors().getAllowedHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
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 @@ -2,9 +2,9 @@

import com.example.outboxpattern.config.Loggable;
import com.example.outboxpattern.order.OrderRecord;
import com.example.outboxpattern.order.internal.query.FindOrdersQuery;
import com.example.outboxpattern.order.internal.request.OrderRequest;
import com.example.outboxpattern.order.internal.response.PagedResult;
import com.example.outboxpattern.order.internal.domain.query.FindOrdersQuery;
import com.example.outboxpattern.order.internal.domain.request.OrderRequest;
import com.example.outboxpattern.order.internal.domain.response.PagedResult;
import com.example.outboxpattern.utils.AppConstants;
import jakarta.validation.Valid;
import java.net.URI;
Expand All @@ -26,12 +26,12 @@
@RequestMapping("/api/orders")
@RequiredArgsConstructor
@Loggable
public class OrderController {
class OrderController {

private final OrderService orderService;

@GetMapping
public PagedResult<OrderRecord> getAllOrders(
PagedResult<OrderRecord> getAllOrders(
@RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false) int pageNo,
@RequestParam(defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false) int pageSize,
@RequestParam(defaultValue = AppConstants.DEFAULT_SORT_BY, required = false) String sortBy,
Expand All @@ -41,12 +41,12 @@ public PagedResult<OrderRecord> getAllOrders(
}

@GetMapping("/{id}")
public ResponseEntity<OrderRecord> getOrderById(@PathVariable Long id) {
ResponseEntity<OrderRecord> getOrderById(@PathVariable Long id) {
return orderService.findOrderById(id).map(ResponseEntity::ok).orElseThrow(() -> new OrderNotFoundException(id));
}

@PostMapping
public ResponseEntity<OrderRecord> createOrder(@RequestBody @Validated OrderRequest orderRequest) {
ResponseEntity<OrderRecord> createOrder(@RequestBody @Validated OrderRequest orderRequest) {
OrderRecord response = orderService.saveOrder(orderRequest);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/api/orders/{id}")
Expand All @@ -56,13 +56,12 @@ public ResponseEntity<OrderRecord> createOrder(@RequestBody @Validated OrderRequ
}

@PutMapping("/{id}")
public ResponseEntity<OrderRecord> updateOrder(
@PathVariable Long id, @RequestBody @Valid OrderRequest orderRequest) {
ResponseEntity<OrderRecord> updateOrder(@PathVariable Long id, @RequestBody @Valid OrderRequest orderRequest) {
return ResponseEntity.ok(orderService.updateOrder(id, orderRequest));
}

@DeleteMapping("/{id}")
public ResponseEntity<OrderRecord> deleteOrder(@PathVariable Long id) {
ResponseEntity<OrderRecord> deleteOrder(@PathVariable Long id) {
return orderService
.findOrderById(id)
.map(order -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.example.outboxpattern.config.Loggable;
import com.example.outboxpattern.order.OrderItemRecord;
import com.example.outboxpattern.order.OrderRecord;
import com.example.outboxpattern.order.internal.domain.request.OrderItemRequest;
import com.example.outboxpattern.order.internal.domain.request.OrderRequest;
import com.example.outboxpattern.order.internal.entities.Order;
import com.example.outboxpattern.order.internal.entities.OrderItem;
import com.example.outboxpattern.order.internal.request.OrderItemRequest;
import com.example.outboxpattern.order.internal.request.OrderRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.example.outboxpattern.exception.ResourceNotFoundException;

public class OrderNotFoundException extends ResourceNotFoundException {
class OrderNotFoundException extends ResourceNotFoundException {

public OrderNotFoundException(Long id) {
OrderNotFoundException(Long id) {
super("Order with Id '%d' Not found".formatted(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.example.outboxpattern.config.Loggable;
import com.example.outboxpattern.order.OrderRecord;
import com.example.outboxpattern.order.internal.domain.query.FindOrdersQuery;
import com.example.outboxpattern.order.internal.domain.request.OrderRequest;
import com.example.outboxpattern.order.internal.domain.response.PagedResult;
import com.example.outboxpattern.order.internal.entities.Order;
import com.example.outboxpattern.order.internal.query.FindOrdersQuery;
import com.example.outboxpattern.order.internal.request.OrderRequest;
import com.example.outboxpattern.order.internal.response.PagedResult;
import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +17,8 @@
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.Assert;

@Service
@Transactional(readOnly = true)
Expand All @@ -26,6 +29,12 @@ class OrderService {
private final OrderRepository orderRepository;
private final OrderMapper orderMapper;
private final ApplicationEventPublisher events;
private final TransactionTemplate transactionTemplate;

@PostConstruct
void setPropagation() {
transactionTemplate.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
}

PagedResult<OrderRecord> findAllOrders(FindOrdersQuery findOrdersQuery) {

Expand Down Expand Up @@ -61,16 +70,16 @@ OrderRecord saveOrder(OrderRequest orderRequest) {
return orderRecord;
}

@Transactional
OrderRecord updateOrder(Long id, OrderRequest orderRequest) {
Order order = orderRepository.findOrderById(id).orElseThrow(() -> new OrderNotFoundException(id));

// Update the order object with data from orderRequest
orderMapper.mapOrderWithRequest(order, orderRequest);

// Save the updated order object
Order updatedOrder = orderRepository.save(order);
Order updatedOrder = transactionTemplate.execute(status -> orderRepository.save(order));

Assert.notNull(updatedOrder, () -> "UpdatedOrder cant be Null");
return orderMapper.toResponse(updatedOrder);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.example.outboxpattern.order.internal.query;
package com.example.outboxpattern.order.internal.domain.query;

public record FindOrdersQuery(int pageNo, int pageSize, String sortBy, String sortDir) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.outboxpattern.order.internal.request;
package com.example.outboxpattern.order.internal.domain.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.outboxpattern.order.internal.request;
package com.example.outboxpattern.order.internal.domain.request;

import jakarta.validation.constraints.NotEmpty;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.outboxpattern.order.internal.response;
package com.example.outboxpattern.order.internal.domain.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.modulith.events.ApplicationModuleListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional
@RequiredArgsConstructor
public class Producer {
class Producer {

@ApplicationModuleListener
void onOrderResponseEvent(OrderRecord orderRecord) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.outboxpattern;

import com.example.outboxpattern.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.modulith.core.ApplicationModules;

class ApplicationTest extends AbstractIntegrationTest {

@Test
void contextLoads() {
ApplicationModules applicationModules = ApplicationModules.of(Application.class);

applicationModules.verify();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

import com.example.outboxpattern.common.AbstractIntegrationTest;
import com.example.outboxpattern.common.listener.OrderListener;
import com.example.outboxpattern.order.internal.domain.request.OrderItemRequest;
import com.example.outboxpattern.order.internal.domain.request.OrderRequest;
import com.example.outboxpattern.order.internal.entities.Order;
import com.example.outboxpattern.order.internal.entities.OrderItem;
import com.example.outboxpattern.order.internal.request.OrderItemRequest;
import com.example.outboxpattern.order.internal.request.OrderRequest;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import com.example.outboxpattern.common.ContainersConfig;
import com.example.outboxpattern.order.OrderRecord;
import com.example.outboxpattern.order.internal.request.OrderItemRequest;
import com.example.outboxpattern.order.internal.request.OrderRequest;
import com.example.outboxpattern.order.internal.domain.request.OrderItemRequest;
import com.example.outboxpattern.order.internal.domain.request.OrderRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down

0 comments on commit 97d518d

Please sign in to comment.