File tree Expand file tree Collapse file tree 12 files changed +147
-32
lines changed
java/dev/pradeep/SirmaAssignment
test/java/dev/pradeep/SirmaAssignment Expand file tree Collapse file tree 12 files changed +147
-32
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import dev .pradeep .SirmaAssignment .Dto .ErrorResponseDto ;
4
4
import dev .pradeep .SirmaAssignment .Exceptions .ProjectNotFoundException ;
5
+ import jakarta .validation .ConstraintViolationException ;
5
6
import lombok .extern .slf4j .Slf4j ;
6
7
import org .springframework .http .HttpStatus ;
7
8
import org .springframework .http .ResponseEntity ;
13
14
@ Slf4j
14
15
public class ControllerAdvisor {
15
16
16
- @ ExceptionHandler (value = {IllegalArgumentException .class , MethodArgumentNotValidException .class })
17
+ @ ExceptionHandler (
18
+ value = {
19
+ ConstraintViolationException .class ,
20
+ IllegalArgumentException .class ,
21
+ MethodArgumentNotValidException .class
22
+ })
17
23
public ResponseEntity <ErrorResponseDto > handleBadRequestException (Exception exception ) {
18
24
log .error ("handleBadRequestException" , exception );
19
25
ErrorResponseDto errorResponseDto = new ErrorResponseDto ();
Original file line number Diff line number Diff line change 8
8
import dev .pradeep .SirmaAssignment .Model .Project ;
9
9
import dev .pradeep .SirmaAssignment .Services .ProjectService ;
10
10
import jakarta .validation .Valid ;
11
+ import java .util .List ;
11
12
import lombok .RequiredArgsConstructor ;
12
13
import org .springframework .web .bind .annotation .*;
13
14
@@ -39,4 +40,9 @@ public ProjectCreatedResponse createProject(
39
40
public Project readProject (@ PathVariable Long projectId ) {
40
41
return projectService .findProject (projectId );
41
42
}
43
+
44
+ @ GetMapping ("/find-all-projects" )
45
+ public List <Project > findAllProjects () {
46
+ return projectService .findAllProjects ();
47
+ }
42
48
}
Original file line number Diff line number Diff line change 3
3
public class ErrorResponseDto {
4
4
private String message ;
5
5
6
+ public ErrorResponseDto (final String message ) {
7
+ this .message = message ;
8
+ }
9
+
10
+ public ErrorResponseDto () {}
11
+
6
12
public String getMessage () {
7
13
return this .message ;
8
14
}
@@ -44,10 +50,4 @@ public int hashCode() {
44
50
public String toString () {
45
51
return "ErrorResponseDto(message=" + this .getMessage () + ")" ;
46
52
}
47
-
48
- public ErrorResponseDto (final String message ) {
49
- this .message = message ;
50
- }
51
-
52
- public ErrorResponseDto () {}
53
53
}
Original file line number Diff line number Diff line change 4
4
import jakarta .validation .constraints .*;
5
5
import java .time .LocalDate ;
6
6
import java .util .List ;
7
+ import lombok .Builder ;
7
8
import lombok .Data ;
8
9
9
10
@ Data
11
+ @ Builder
10
12
public class CreateProjectDto {
11
13
12
14
@ NotBlank (message = "Name is required" )
Original file line number Diff line number Diff line change 4
4
import jakarta .validation .constraints .NotNull ;
5
5
import java .time .LocalDate ;
6
6
import java .util .List ;
7
+ import lombok .Builder ;
7
8
import lombok .Data ;
8
9
9
10
@ Data
11
+ @ Builder
10
12
public class UpdateProjectDto {
11
13
@ NotNull (message = "Project id is required" )
12
14
private Long projectId ;
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ public class BaseEntity implements Serializable {
19
19
@ Column (name = "updated_at" )
20
20
private LocalDateTime updatedAt ;
21
21
22
+ public BaseEntity () {}
23
+
22
24
@ PrePersist
23
25
void createDate () {
24
26
if (this .createdAt == null ) {
@@ -52,22 +54,22 @@ public Long getId() {
52
54
return this .id ;
53
55
}
54
56
55
- public LocalDateTime getCreatedAt () {
56
- return this .createdAt ;
57
- }
58
-
59
- public LocalDateTime getUpdatedAt () {
60
- return this .updatedAt ;
61
- }
62
-
63
57
public void setId (final Long id ) {
64
58
this .id = id ;
65
59
}
66
60
61
+ public LocalDateTime getCreatedAt () {
62
+ return this .createdAt ;
63
+ }
64
+
67
65
public void setCreatedAt (final LocalDateTime createdAt ) {
68
66
this .createdAt = createdAt ;
69
67
}
70
68
69
+ public LocalDateTime getUpdatedAt () {
70
+ return this .updatedAt ;
71
+ }
72
+
71
73
public void setUpdatedAt (final LocalDateTime updatedAt ) {
72
74
this .updatedAt = updatedAt ;
73
75
}
@@ -82,6 +84,4 @@ public String toString() {
82
84
+ this .getUpdatedAt ()
83
85
+ ")" ;
84
86
}
85
-
86
- public BaseEntity () {}
87
87
}
Original file line number Diff line number Diff line change 7
7
import jakarta .persistence .Table ;
8
8
import java .time .LocalDate ;
9
9
import java .util .List ;
10
- import lombok .Getter ;
11
- import lombok .RequiredArgsConstructor ;
12
- import lombok .Setter ;
13
- import lombok .ToString ;
10
+ import lombok .*;
14
11
import org .hibernate .annotations .JdbcTypeCode ;
15
12
import org .hibernate .type .SqlTypes ;
16
13
17
- /*
18
- I'd defined in base entity where other metadata is also defined
19
- like created at and updated at
20
- */
21
14
@ Getter
22
15
@ Setter
23
16
@ ToString
24
17
@ RequiredArgsConstructor
25
18
@ Entity
26
19
@ Table (name = "projects" )
27
20
public class Project extends BaseEntity {
21
+ /*
22
+ I'd defined in base entity where other metadata is also defined
23
+ like created at and updated at
24
+ id autoincrement
25
+ */
28
26
private String name ;
29
27
private String description ;
30
28
private LocalDate startDate ;
Original file line number Diff line number Diff line change 3
3
import dev .pradeep .SirmaAssignment .Dao .ProjectDao ;
4
4
import dev .pradeep .SirmaAssignment .Exceptions .ProjectNotFoundException ;
5
5
import dev .pradeep .SirmaAssignment .Model .Project ;
6
+ import java .util .List ;
6
7
import lombok .RequiredArgsConstructor ;
7
8
import lombok .extern .slf4j .Slf4j ;
8
9
import org .springframework .stereotype .Repository ;
@@ -24,4 +25,8 @@ public Project findById(Long projectId) {
24
25
public void deleteById (Long projectId ) {
25
26
projectDao .deleteById (projectId );
26
27
}
28
+
29
+ public List <Project > findAll () {
30
+ return (List <Project >) projectDao .findAll ();
31
+ }
27
32
}
Original file line number Diff line number Diff line change 8
8
import dev .pradeep .SirmaAssignment .Mapper .ProjectMapper ;
9
9
import dev .pradeep .SirmaAssignment .Model .Project ;
10
10
import dev .pradeep .SirmaAssignment .Repository .ProjectRepository ;
11
+ import java .util .List ;
11
12
import lombok .RequiredArgsConstructor ;
12
13
import lombok .extern .slf4j .Slf4j ;
13
14
import org .springframework .stereotype .Service ;
@@ -42,4 +43,8 @@ public ProjectDeletedResponse deleteProject(Long projectId) {
42
43
public Project findProject (Long projectId ) {
43
44
return projectRepository .findById (projectId );
44
45
}
46
+
47
+ public List <Project > findAllProjects () {
48
+ return projectRepository .findAll ();
49
+ }
45
50
}
Original file line number Diff line number Diff line change 1
-
2
1
spring.datasource.url =jdbc:h2:mem:sirma
3
2
spring.datasource.driverClassName =org.h2.Driver
4
3
spring.datasource.username =root
5
4
spring.datasource.password =root
6
5
spring.jpa.database-platform =org.hibernate.dialect.H2Dialect
7
-
8
6
# Hibernate properties
9
7
spring.jpa.hibernate.ddl-auto =update
10
8
spring.jpa.show-sql =true
11
9
logging.level.org.hibernate.sql =DEBUG
12
10
logging.level.org.hibernate.type.descriptor.sql.BasicBinder =TRACE
13
-
14
11
spring.h2.console.enabled =true
You can’t perform that action at this time.
0 commit comments