Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 113 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath/>
</parent>
<groupId>com.emobile</groupId>
<artifactId>SpringToDo</artifactId>
Expand All @@ -21,14 +21,99 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>

<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.20.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql </artifactId>
</dependency>
</dependencies>

<build>
Expand All @@ -37,6 +122,32 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>10.0.0</version>
<configuration>
<url>jdbc:postgresql://localhost:5432/todo_db</url>
<user>postgres</user>
<password>1</password>
<cleanDisabled>false</cleanDisabled>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.web.config.EnableSpringDataWebSupport;

import static org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO;

@SpringBootApplication
@EnableCaching
@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
public class SpringToDoApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.emobile.springtodo.controller;


import com.emobile.springtodo.model.Todo;
import com.emobile.springtodo.service.ToDoService;
import com.emobile.springtodo.swagger.ITodoController;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@CrossOrigin
public class TodoController implements ITodoController {

private final ToDoService toDoService;


@Override
public void addToDo(Todo toDo) {


toDoService.createTodo(toDo);

}

@Override
public void updateToDoById(Todo todo, Long id) {
toDoService.updateToDoById(todo, id);
}


@Override
public List<Todo> findAllToDo() {
return toDoService.findAllToDo();
}

@Override
public ResponseEntity<Page<Todo>> getToDo(Todo toDo, int size, int page) {
Pageable pageable = PageRequest.of(page, size);
return new ResponseEntity<>(toDoService.findAllToDoByFilter(toDo, pageable),HttpStatus.OK);
}


@Override
public void deleteToDoById(Long id) {
toDoService.deleteById(id);
}

@Override
public void deleteAllToDo() {
toDoService.deleteAll();
}





}
16 changes: 16 additions & 0 deletions src/main/java/com/emobile/springtodo/exception/AppError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.emobile.springtodo.exception;

import lombok.Data;

@Data
public class AppError {

private int httpStatus;
private String message;

public AppError(int httpStatus, String message) {
this.httpStatus = httpStatus;
this.message = message;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.emobile.springtodo.exception;


import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лушче Implementиться от Rest исключений, т.к. тут ты почти никакие не покрыл


@ExceptionHandler(TodoException.class)
public ResponseEntity<AppError> todoException(TodoException ex)
{
return new ResponseEntity<>(new AppError(HttpStatus.NOT_FOUND.value(),ex.getMessage()),HttpStatus.BAD_REQUEST);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.emobile.springtodo.exception;

public class TodoException extends RuntimeException{

public TodoException(String message)
{
super(message);
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/emobile/springtodo/mapper/TodoMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.emobile.springtodo.mapper;

import com.emobile.springtodo.model.Todo;
import com.emobile.springtodo.model.TodoPriority;
import com.emobile.springtodo.model.TodoStatus;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class TodoMapper implements RowMapper<Todo> {
@Override
public Todo mapRow(ResultSet rs, int rowNum) throws SQLException {
Todo toDo = new Todo();
toDo.setId(rs.getLong("id"));
toDo.setToDoTitle((rs.getString("todo_title")));
toDo.setDescription(rs.getString("description"));
toDo.setToDoPriority(TodoPriority.valueOf(rs.getString("todo_priority")));
toDo.setToDoStatus(TodoStatus.valueOf(rs.getString("todo_status")));
return toDo;
}


}
17 changes: 17 additions & 0 deletions src/main/java/com/emobile/springtodo/model/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.emobile.springtodo.model;


import lombok.*;

import java.io.Serializable;

@Data
public class Todo implements Serializable {

private Long id;
private String toDoTitle;
private String description;
private TodoPriority toDoPriority;
private TodoStatus toDoStatus;
private String comment;
}
8 changes: 8 additions & 0 deletions src/main/java/com/emobile/springtodo/model/TodoPriority.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.emobile.springtodo.model;

public enum TodoPriority {
HIGH,MEDIUM,LOW
}



6 changes: 6 additions & 0 deletions src/main/java/com/emobile/springtodo/model/TodoStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.emobile.springtodo.model;

public enum TodoStatus {
PENDING,IN_PROGRESS,
COMPLETED
}
Loading