Skip to content

Commit a6caa79

Browse files
committed
refactor code
1 parent 5e3701b commit a6caa79

17 files changed

+275
-295
lines changed

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Advisor/ControllerAdvisor.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,19 @@
1313
@Slf4j
1414
public class ControllerAdvisor {
1515

16-
@ExceptionHandler(
17-
value = {IllegalArgumentException.class,
18-
MethodArgumentNotValidException.class})
19-
public ResponseEntity<ErrorResponseDto> handleBadRequestException(Exception exception) {
20-
log.error("handleBadRequestException", exception);
21-
ErrorResponseDto errorResponseDto = new ErrorResponseDto();
22-
errorResponseDto.setMessage(exception.getMessage());
23-
return new ResponseEntity<>(errorResponseDto, HttpStatus.BAD_REQUEST);
24-
}
16+
@ExceptionHandler(value = {IllegalArgumentException.class, MethodArgumentNotValidException.class})
17+
public ResponseEntity<ErrorResponseDto> handleBadRequestException(Exception exception) {
18+
log.error("handleBadRequestException", exception);
19+
ErrorResponseDto errorResponseDto = new ErrorResponseDto();
20+
errorResponseDto.setMessage(exception.getMessage());
21+
return new ResponseEntity<>(errorResponseDto, HttpStatus.BAD_REQUEST);
22+
}
2523

26-
@ExceptionHandler(
27-
value = {
28-
ProjectNotFoundException.class
29-
})
30-
public ResponseEntity<ErrorResponseDto> handleNotFoundException(Exception exception) {
31-
log.error("handleNotFoundException", exception);
32-
ErrorResponseDto errorResponseDto = new ErrorResponseDto();
33-
errorResponseDto.setMessage(exception.getMessage());
34-
return new ResponseEntity<>(errorResponseDto, HttpStatus.NOT_FOUND);
35-
}
24+
@ExceptionHandler(value = {ProjectNotFoundException.class})
25+
public ResponseEntity<ErrorResponseDto> handleNotFoundException(Exception exception) {
26+
log.error("handleNotFoundException", exception);
27+
ErrorResponseDto errorResponseDto = new ErrorResponseDto();
28+
errorResponseDto.setMessage(exception.getMessage());
29+
return new ResponseEntity<>(errorResponseDto, HttpStatus.NOT_FOUND);
30+
}
3631
}

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Controllers/ProjectController.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@
1616
@RequestMapping("/projects")
1717
public class ProjectController {
1818

19-
private final ProjectService projectService;
19+
private final ProjectService projectService;
2020

21-
@DeleteMapping("/delete-project/{projectId}")
22-
public ProjectDeletedResponse deleteProject(@PathVariable Long projectId) {
23-
return projectService.deleteProject(projectId);
24-
}
21+
@DeleteMapping("/delete-project/{projectId}")
22+
public ProjectDeletedResponse deleteProject(@PathVariable Long projectId) {
23+
return projectService.deleteProject(projectId);
24+
}
2525

26-
@PostMapping("update-project")
27-
public ProjectUpdatedResponse updateProject(@RequestBody @Valid UpdateProjectDto updateProjectDto) {
28-
return projectService.updateProject(updateProjectDto);
29-
}
26+
@PostMapping("update-project")
27+
public ProjectUpdatedResponse updateProject(
28+
@RequestBody @Valid UpdateProjectDto updateProjectDto) {
29+
return projectService.updateProject(updateProjectDto);
30+
}
3031

31-
@PostMapping("/create-project")
32-
public ProjectCreatedResponse createProject(@RequestBody @Valid CreateProjectDto createProjectDto) {
33-
return projectService.createProject(createProjectDto);
34-
}
32+
@PostMapping("/create-project")
33+
public ProjectCreatedResponse createProject(
34+
@RequestBody @Valid CreateProjectDto createProjectDto) {
35+
return projectService.createProject(createProjectDto);
36+
}
3537

36-
@GetMapping("/read-project/{projectId}")
37-
public Project readProject(@PathVariable Long projectId) {
38-
return projectService.findProject(projectId);
39-
}
38+
@GetMapping("/read-project/{projectId}")
39+
public Project readProject(@PathVariable Long projectId) {
40+
return projectService.findProject(projectId);
41+
}
4042
}
Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,53 @@
11
package dev.pradeep.SirmaAssignment.Dto;
22

33
public class ErrorResponseDto {
4-
private String message;
5-
6-
public String getMessage() {
7-
return this.message;
8-
}
9-
10-
public void setMessage(final String message) {
11-
this.message = message;
12-
}
13-
14-
public boolean equals(final Object o) {
15-
if (o == this) {
16-
return true;
17-
} else if (!(o instanceof ErrorResponseDto)) {
18-
return false;
19-
} else {
20-
ErrorResponseDto other = (ErrorResponseDto)o;
21-
if (!other.canEqual(this)) {
22-
return false;
23-
} else {
24-
Object this$message = this.getMessage();
25-
Object other$message = other.getMessage();
26-
if (this$message == null) {
27-
if (other$message != null) {
28-
return false;
29-
}
30-
} else if (!this$message.equals(other$message)) {
31-
return false;
32-
}
33-
34-
return true;
35-
}
36-
}
37-
}
38-
39-
protected boolean canEqual(final Object other) {
40-
return other instanceof ErrorResponseDto;
41-
}
42-
43-
public int hashCode() {
44-
boolean PRIME = true;
45-
int result = 1;
46-
Object $message = this.getMessage();
47-
result = result * 59 + ($message == null ? 43 : $message.hashCode());
48-
return result;
49-
}
50-
51-
public String toString() {
52-
return "ErrorResponseDto(message=" + this.getMessage() + ")";
53-
}
54-
55-
public ErrorResponseDto(final String message) {
56-
this.message = message;
57-
}
58-
59-
public ErrorResponseDto() {
60-
}
61-
}
4+
private String message;
5+
6+
public String getMessage() {
7+
return this.message;
8+
}
9+
10+
public void setMessage(final String message) {
11+
this.message = message;
12+
}
13+
14+
public boolean equals(final Object o) {
15+
if (o == this) {
16+
return true;
17+
} else if (!(o instanceof ErrorResponseDto other)) {
18+
return false;
19+
} else {
20+
if (!other.canEqual(this)) {
21+
return false;
22+
} else {
23+
Object this$message = this.getMessage();
24+
Object other$message = other.getMessage();
25+
if (this$message == null) {
26+
return other$message == null;
27+
} else return this$message.equals(other$message);
28+
}
29+
}
30+
}
31+
32+
protected boolean canEqual(final Object other) {
33+
return other instanceof ErrorResponseDto;
34+
}
35+
36+
public int hashCode() {
37+
boolean PRIME = true;
38+
int result = 1;
39+
Object $message = this.getMessage();
40+
result = result * 59 + ($message == null ? 43 : $message.hashCode());
41+
return result;
42+
}
43+
44+
public String toString() {
45+
return "ErrorResponseDto(message=" + this.getMessage() + ")";
46+
}
47+
48+
public ErrorResponseDto(final String message) {
49+
this.message = message;
50+
}
51+
52+
public ErrorResponseDto() {}
53+
}

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Dto/Request/CreateProjectDto.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,35 @@
22

33
import dev.pradeep.SirmaAssignment.Enum.ProjectStatus;
44
import jakarta.validation.constraints.*;
5-
import lombok.Data;
6-
7-
85
import java.time.LocalDate;
96
import java.util.List;
7+
import lombok.Data;
108

119
@Data
1210
public class CreateProjectDto {
1311

14-
@NotBlank(message = "Name is required")
15-
private String name;
12+
@NotBlank(message = "Name is required")
13+
private String name;
1614

17-
@NotBlank(message = "Description is required")
18-
@Size(min = 10, message = "Description must contain at least 10 characters")
19-
private String description;
15+
@NotBlank(message = "Description is required")
16+
@Size(min = 10, message = "Description must contain at least 10 characters")
17+
private String description;
2018

21-
@NotNull(message = "Start date is required")
22-
private LocalDate startDate;
19+
@NotNull(message = "Start date is required")
20+
private LocalDate startDate;
2321

24-
@NotNull(message = "End date is required")
25-
private LocalDate endDate;
22+
@NotNull(message = "End date is required")
23+
private LocalDate endDate;
2624

27-
@NotEmpty(message = "Technologies are required")
28-
private List<String> technologies;
25+
@NotEmpty(message = "Technologies are required")
26+
private List<String> technologies;
2927

30-
@NotEmpty(message = "Project requirements are required")
31-
private List<String> projectRequirements;
28+
@NotEmpty(message = "Project requirements are required")
29+
private List<String> projectRequirements;
3230

33-
@NotBlank(message = "Project type is required")
34-
private String projectType;
31+
@NotBlank(message = "Project type is required")
32+
private String projectType;
3533

36-
@NotNull(message = "Status is required")
37-
private ProjectStatus status;
34+
@NotNull(message = "Status is required")
35+
private ProjectStatus status;
3836
}

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Dto/Request/UpdateProjectDto.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
import dev.pradeep.SirmaAssignment.Enum.ProjectStatus;
44
import jakarta.validation.constraints.NotNull;
5-
import lombok.Data;
6-
75
import java.time.LocalDate;
86
import java.util.List;
7+
import lombok.Data;
98

109
@Data
1110
public class UpdateProjectDto {
12-
@NotNull(message = "Project id is required")
13-
private Long projectId;
14-
private String name;
15-
private String description;
16-
private LocalDate startDate;
17-
private LocalDate endDate;
18-
private List<String> technologies;
19-
private List<String> projectRequirements;
20-
private String projectType;
21-
private ProjectStatus status;
11+
@NotNull(message = "Project id is required")
12+
private Long projectId;
2213

14+
private String name;
15+
private String description;
16+
private LocalDate startDate;
17+
private LocalDate endDate;
18+
private List<String> technologies;
19+
private List<String> projectRequirements;
20+
private String projectType;
21+
private ProjectStatus status;
2322
}

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Dto/Response/ProjectCreatedResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
@Data
66
public class ProjectCreatedResponse {
7-
private String message = "Project created successfully";
7+
private String message = "Project created successfully";
88
}

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Dto/Response/ProjectDeletedResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
@Data
66
public class ProjectDeletedResponse {
7-
private String message = "Project deleted successfully";
7+
private String message = "Project deleted successfully";
88
}

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Dto/Response/ProjectUpdatedResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
@Data
66
public class ProjectUpdatedResponse {
7-
private String message = "Project updated successfully";
7+
private String message = "Project updated successfully";
88
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package dev.pradeep.SirmaAssignment.Enum;
22

33
public enum ProjectStatus {
4-
COMPLETED,
5-
CANCELLED,
6-
IN_PROGRESS
4+
COMPLETED,
5+
CANCELLED,
6+
IN_PROGRESS
77
}
8-

SirmaAssignment/src/main/java/dev/pradeep/SirmaAssignment/Exceptions/ProjectNotFoundException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import lombok.Data;
44

55
@Data
6-
public class ProjectNotFoundException extends RuntimeException{
7-
private final String message = "Project doesn't exist";
6+
public class ProjectNotFoundException extends RuntimeException {
7+
private final String message = "Project doesn't exist";
88
}

0 commit comments

Comments
 (0)