0% found this document useful (0 votes)
4 views

TodoRepository

The document defines a Todo application using Spring Boot, including a Todo entity and a repository interface for database operations. The Todo class includes fields for id, username, description, target date, and completion status, along with validation for the description length. The TodoRepository interface extends JpaRepository to provide methods for accessing Todo records, specifically allowing retrieval by username.

Uploaded by

David Pavlovski
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

TodoRepository

The document defines a Todo application using Spring Boot, including a Todo entity and a repository interface for database operations. The Todo class includes fields for id, username, description, target date, and completion status, along with validation for the description length. The TodoRepository interface extends JpaRepository to provide methods for accessing Todo records, specifically allowing retrieval by username.

Uploaded by

David Pavlovski
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.davidpavlovski.springboot.todoApp.

todo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TodoRepository extends JpaRepository<Todo, Integer> {
List<Todo> findByUsername(String username);
}
package com.davidpavlovski.springboot.todoApp.todo;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Size;
import org.springframework.context.annotation.Primary;

import java.time.LocalDate;

@Table
@Entity
public class Todo {
@Id
@GeneratedValue
private int id;
private String username;
@Size(min = 5, message = "Description must be at least 5 characters")
private String description;
private LocalDate targetDate;
private boolean completed;

public Todo() {
super();
}

public Todo(String username, String description, LocalDate targetDate, boolean


completed) {
this.username = username;
this.description = description;
this.targetDate = targetDate;
this.completed = completed;
}

@Override
public String toString() {
return "Todo{" +
"id=" + id +
", username='" + username + '\'' +
", description='" + description + '\'' +
", targetDate=" + targetDate +
", completed=" + completed +
'}';
}

public void toggleComplete() {


completed = !completed;
}

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public String getUsername() {


return username;
}

public void setUsername(String username) {


this.username = username;
}

public String getDescription() {


return description;
}

public void setDescription(String description) {


this.description = description;
}

public LocalDate getTargetDate() {


return targetDate;
}

public void setTargetDate(LocalDate targetDate) {


this.targetDate = targetDate;
}

public boolean isCompleted() {


return completed;
}

public void setCompleted(boolean completed) {


this.completed = completed;
}

You might also like