Skip to content

Commit 301b7d6

Browse files
Refactor: Fix checkstyle lint warnings
1 parent 7aa1d95 commit 301b7d6

25 files changed

+343
-361
lines changed

src/main/java/com/ecommerce/order/OrderApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
@SpringBootApplication
77
public class OrderApplication {
88

9-
public static void main(String[] args) {
10-
SpringApplication.run(OrderApplication.class, args);
11-
}
9+
public static void main(String[] args) {
10+
SpringApplication.run(OrderApplication.class, args);
11+
}
1212

1313
}
Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.ecommerce.order.controller;
22

3+
import com.ecommerce.order.dto.CreateCustomerDto;
4+
import com.ecommerce.order.dto.UpdateCustomerDto;
5+
import com.ecommerce.order.exception.EntityNotFoundException;
6+
import com.ecommerce.order.model.Customer;
7+
import com.ecommerce.order.service.CustomerService;
8+
import jakarta.validation.Valid;
39
import java.util.List;
4-
510
import org.springframework.beans.factory.annotation.Autowired;
611
import org.springframework.web.bind.annotation.DeleteMapping;
712
import org.springframework.web.bind.annotation.GetMapping;
@@ -12,43 +17,37 @@
1217
import org.springframework.web.bind.annotation.RequestMapping;
1318
import org.springframework.web.bind.annotation.RestController;
1419

15-
import com.ecommerce.order.dto.CreateCustomerDto;
16-
import com.ecommerce.order.dto.UpdateCustomerDto;
17-
import com.ecommerce.order.exception.EntityNotFoundException;
18-
import com.ecommerce.order.model.Customer;
19-
import com.ecommerce.order.service.CustomerService;
20-
21-
import jakarta.validation.Valid;
22-
2320
@RestController
2421
@RequestMapping(path = "/customers")
2522
public class CustomerController {
26-
@Autowired
27-
private CustomerService customerService;
28-
29-
@GetMapping("/")
30-
public List<Customer> findAll() {
31-
return customerService.findAll();
32-
}
33-
34-
@GetMapping("/{id}")
35-
public Customer findOne(@PathVariable Integer id) throws EntityNotFoundException {
36-
return customerService.findOne(id);
37-
}
38-
39-
@PostMapping("/")
40-
public Customer create(@Valid @RequestBody CreateCustomerDto customerDto) {
41-
return customerService.create(customerDto);
42-
}
43-
44-
@PutMapping("/{id}")
45-
public Customer update(@PathVariable Integer id, @Valid @RequestBody UpdateCustomerDto customerDto)
46-
throws EntityNotFoundException {
47-
return customerService.update(id, customerDto);
48-
}
49-
50-
@DeleteMapping("/{id}")
51-
public void delete(@PathVariable Integer id) throws EntityNotFoundException {
52-
customerService.delete(id);
53-
}
23+
24+
@Autowired
25+
private CustomerService customerService;
26+
27+
@GetMapping("/")
28+
public List<Customer> findAll() {
29+
return customerService.findAll();
30+
}
31+
32+
@GetMapping("/{id}")
33+
public Customer findOne(@PathVariable Integer id) throws EntityNotFoundException {
34+
return customerService.findOne(id);
35+
}
36+
37+
@PostMapping("/")
38+
public Customer create(@Valid @RequestBody CreateCustomerDto customerDto) {
39+
return customerService.create(customerDto);
40+
}
41+
42+
@PutMapping("/{id}")
43+
public Customer update(@PathVariable Integer id,
44+
@Valid @RequestBody UpdateCustomerDto customerDto) throws EntityNotFoundException {
45+
return customerService.update(id, customerDto);
46+
}
47+
48+
@DeleteMapping("/{id}")
49+
public void delete(@PathVariable Integer id) throws EntityNotFoundException {
50+
customerService.delete(id);
51+
}
52+
5453
}

src/main/java/com/ecommerce/order/controller/HealthController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
@RequestMapping("/health")
1111
public class HealthController {
1212

13-
@GetMapping("/")
14-
public ResponseEntity<String> healthCheck() {
15-
return new ResponseEntity<String>("Order management service is up", HttpStatus.OK);
16-
}
13+
@GetMapping("/")
14+
public ResponseEntity<String> healthCheck() {
15+
return new ResponseEntity<String>("Order management service is up", HttpStatus.OK);
16+
}
1717
}
Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.ecommerce.order.controller;
22

3+
import com.ecommerce.order.dto.CreateOrderDto;
4+
import com.ecommerce.order.dto.UpdateOrderDto;
5+
import com.ecommerce.order.model.Order;
6+
import com.ecommerce.order.service.OrderService;
7+
import jakarta.validation.Valid;
38
import org.springframework.beans.factory.annotation.Autowired;
49
import org.springframework.data.domain.Page;
510
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -11,42 +16,35 @@
1116
import org.springframework.web.bind.annotation.RequestMapping;
1217
import org.springframework.web.bind.annotation.RestController;
1318

14-
import com.ecommerce.order.dto.CreateOrderDto;
15-
import com.ecommerce.order.dto.UpdateOrderDto;
16-
import com.ecommerce.order.model.Order;
17-
import com.ecommerce.order.service.OrderService;
18-
19-
import jakarta.validation.Valid;
20-
2119
@RestController
2220
@RequestMapping(path = "/orders")
2321
public class OrderController {
2422

25-
@Autowired
26-
private OrderService orderService;
27-
28-
@GetMapping("/")
29-
public Page<Order> findAll() {
30-
return orderService.findAll(0, 5);
31-
}
32-
33-
@GetMapping("/{id}")
34-
public Order findOne(@PathVariable Integer id) {
35-
return orderService.findOne(id);
36-
}
37-
38-
@PostMapping("/")
39-
public Order create(@Valid @RequestBody CreateOrderDto orderDto) {
40-
return orderService.create(orderDto);
41-
}
42-
43-
@PutMapping("/{id}")
44-
public Order update(@PathVariable Integer id, @Valid @RequestBody UpdateOrderDto orderDto) {
45-
return orderService.update(id, orderDto);
46-
}
47-
48-
@DeleteMapping("/{id}")
49-
public void delete(@PathVariable Integer id) {
50-
orderService.delete(id);
51-
}
23+
@Autowired
24+
private OrderService orderService;
25+
26+
@GetMapping("/")
27+
public Page<Order> findAll() {
28+
return orderService.findAll(0, 5);
29+
}
30+
31+
@GetMapping("/{id}")
32+
public Order findOne(@PathVariable Integer id) {
33+
return orderService.findOne(id);
34+
}
35+
36+
@PostMapping("/")
37+
public Order create(@Valid @RequestBody CreateOrderDto orderDto) {
38+
return orderService.create(orderDto);
39+
}
40+
41+
@PutMapping("/{id}")
42+
public Order update(@PathVariable Integer id, @Valid @RequestBody UpdateOrderDto orderDto) {
43+
return orderService.update(id, orderDto);
44+
}
45+
46+
@DeleteMapping("/{id}")
47+
public void delete(@PathVariable Integer id) {
48+
orderService.delete(id);
49+
}
5250
}

src/main/java/com/ecommerce/order/dto/CreateCustomerDto.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,35 @@
1111
@Setter
1212
public class CreateCustomerDto {
1313

14-
@NotEmpty
15-
@NotNull
16-
@Size(min = 2, message = "Name must have at least 2 characters")
17-
private String name;
18-
19-
@NotEmpty
20-
@NotNull
21-
private String phone;
22-
23-
@NotEmpty
24-
@NotNull
25-
@Email
26-
private String email;
27-
28-
@NotNull
29-
@NotEmpty
30-
@Size(min = 2, message = "Street must have at least 2 characters")
31-
private String street;
32-
33-
@NotNull
34-
@NotEmpty
35-
@Size(min = 2, message = "City must have at least 2 characters")
36-
private String city;
37-
38-
@NotNull
39-
@NotEmpty
40-
@Size(min = 2, message = "State must have at least 2 characters")
41-
private String state;
42-
43-
private String profilePic;
14+
@NotEmpty
15+
@NotNull
16+
@Size(min = 2, message = "Name must have at least 2 characters")
17+
private String name;
18+
19+
@NotEmpty
20+
@NotNull
21+
private String phone;
22+
23+
@NotEmpty
24+
@NotNull
25+
@Email
26+
private String email;
27+
28+
@NotNull
29+
@NotEmpty
30+
@Size(min = 2, message = "Street must have at least 2 characters")
31+
private String street;
32+
33+
@NotNull
34+
@NotEmpty
35+
@Size(min = 2, message = "City must have at least 2 characters")
36+
private String city;
37+
38+
@NotNull
39+
@NotEmpty
40+
@Size(min = 2, message = "State must have at least 2 characters")
41+
private String state;
42+
43+
private String profilePic;
44+
4445
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.ecommerce.order.dto;
22

3-
import java.util.List;
4-
53
import jakarta.validation.Valid;
64
import jakarta.validation.constraints.NotEmpty;
75
import jakarta.validation.constraints.NotNull;
6+
import java.util.List;
87
import lombok.Builder;
98
import lombok.Getter;
109
import lombok.Setter;
@@ -13,10 +12,11 @@
1312
@Setter
1413
@Builder
1514
public class CreateOrderDto {
16-
@NotNull
17-
private Integer customerId;
15+
@NotNull
16+
private Integer customerId;
17+
18+
@NotEmpty
19+
@Valid
20+
private List<CreateOrderItemDto> orderItems;
1821

19-
@NotEmpty
20-
@Valid
21-
private List<CreateOrderItemDto> orderItems;
2222
}

src/main/java/com/ecommerce/order/dto/CreateOrderItemDto.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
@Builder
1212
public class CreateOrderItemDto {
1313

14-
@NotNull
15-
private Integer productId;
14+
@NotNull
15+
private Integer productId;
16+
17+
@NotNull
18+
@Min(1)
19+
private Integer quantity;
1620

17-
@NotNull
18-
@Min(1)
19-
private Integer quantity;
2021
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.ecommerce.order.dto;
22

33
import com.ecommerce.order.constants.OrderStatus;
4-
54
import jakarta.validation.constraints.NotNull;
65
import lombok.Getter;
76
import lombok.Setter;
87

98
@Getter
109
@Setter
1110
public class UpdateOrderDto {
12-
@NotNull
13-
private OrderStatus status;
11+
12+
@NotNull
13+
private OrderStatus status;
14+
1415
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.ecommerce.order.exception;
22

3-
import org.springframework.http.HttpStatusCode;
4-
53
import lombok.AllArgsConstructor;
64
import lombok.Getter;
5+
import org.springframework.http.HttpStatusCode;
76

87
@Getter
98
@AllArgsConstructor
109
public class CommonException extends RuntimeException {
11-
private final HttpStatusCode statusCode;
12-
private final String errorCode;
13-
private final String message;
14-
}
10+
11+
private final HttpStatusCode statusCode;
12+
private final String errorCode;
13+
private final String message;
14+
15+
}

src/main/java/com/ecommerce/order/exception/EntityNotFoundException.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
public class EntityNotFoundException extends CommonException {
66

7-
private static final long serialVersionUID = 1L;
7+
private static final long serialVersionUID = 1L;
88

9-
public <T> EntityNotFoundException(Class<T> entity) {
10-
super(HttpStatus.NOT_FOUND, ExceptionCodes.ENTITY_NOT_FOUND, entity.getSimpleName() + " not found");
11-
}
9+
public <T> EntityNotFoundException(Class<T> entity) {
10+
super(HttpStatus.NOT_FOUND, ExceptionCodes.ENTITY_NOT_FOUND,
11+
entity.getSimpleName() + " not found");
12+
}
1213

1314
}

0 commit comments

Comments
 (0)