Got the api working for getting notes
This commit is contained in:
17
pom.xml
17
pom.xml
@@ -26,16 +26,32 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- Web / REST -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JPA + Hibernate (managed by Boot) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- PostgreSQL driver -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>42.7.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Testing -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -44,7 +60,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
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;
|
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 {
|
public class Notes {
|
||||||
private String content;
|
|
||||||
private String authorName;
|
@Id
|
||||||
private Date createdAt;
|
@GeneratedValue
|
||||||
private Long id;
|
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() {
|
public Notes() {
|
||||||
this.createdAt = new Date(System.currentTimeMillis());
|
this.createdAt = new Date(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(String content) {
|
public void setContent(String content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthorName() {
|
public String getAuthorName() {
|
||||||
return authorName;
|
return authorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthorName(String authorName) {
|
public void setAuthorName(String authorName) {
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
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