Got the api working for getting notes
This commit is contained in:
32
src/main/java/org/zaine/app/controller/NotesController.java
Normal file
32
src/main/java/org/zaine/app/controller/NotesController.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package org.zaine.app.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.zaine.app.model.Notes;
|
||||
import org.zaine.app.repositories.NotesRepository;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class NotesController {
|
||||
@Autowired
|
||||
private NotesRepository notesRepository;
|
||||
|
||||
@GetMapping("/notes")
|
||||
public List<Notes> getAllNotes() {
|
||||
return notesRepository.findAll();
|
||||
}
|
||||
|
||||
@PostMapping("/notes")
|
||||
public Notes createNote(@RequestBody Notes note) {
|
||||
return notesRepository.save(note);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,43 +1,59 @@
|
||||
package org.zaine.app.model;
|
||||
|
||||
import java.sql.Date;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import org.hibernate.annotations.UuidGenerator;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "public_notes")
|
||||
public class Notes {
|
||||
private String content;
|
||||
private String authorName;
|
||||
private Date createdAt;
|
||||
private Long id;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private UUID id;
|
||||
|
||||
@Column(name="content")
|
||||
private String content;
|
||||
|
||||
@Column(name="author_name")
|
||||
private String authorName;
|
||||
|
||||
@Column(name="created_at")
|
||||
private Date createdAt;
|
||||
|
||||
|
||||
public Notes() {
|
||||
this.createdAt = new Date(System.currentTimeMillis());
|
||||
this.createdAt = new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getAuthorName() {
|
||||
return authorName;
|
||||
return authorName;
|
||||
}
|
||||
|
||||
public void setAuthorName(String authorName) {
|
||||
this.authorName = authorName;
|
||||
this.authorName = authorName;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.zaine.app.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.UUID;
|
||||
import org.zaine.app.model.Notes;
|
||||
|
||||
public interface NotesRepository extends JpaRepository<Notes, UUID> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user