few improvements
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package _11.asktpk.artisanconnectbackend.Controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.Repository.NoticeRepository;
|
||||
import _11.asktpk.artisanconnectbackend.Service.PostgresDatabase;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("/api/v1")
|
||||
@RestController
|
||||
public class ArtisanConnectController {
|
||||
@Autowired
|
||||
private PostgresDatabase postgresDatabase;
|
||||
|
||||
@GetMapping("/notices/all")
|
||||
public List<Notice> getAllNotices() {
|
||||
return postgresDatabase.get();
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@PostMapping("/notices/add")
|
||||
public void addNotice(@RequestBody Notice notice) {
|
||||
postgresDatabase.add(notice);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package _11.asktpk.artisanconnectbackend.Model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.sql.Blob;
|
||||
|
||||
@Entity
|
||||
public class Notice {
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
private String title;
|
||||
|
||||
@Column
|
||||
private String username;
|
||||
|
||||
@Column
|
||||
private String description;
|
||||
|
||||
public Notice() {
|
||||
this.title = "";
|
||||
this.username = "";
|
||||
this.description = "";
|
||||
}
|
||||
|
||||
public Notice(String nTitle, String nUsername, String nDescription) {
|
||||
this.title = nTitle;
|
||||
this.username = nUsername;
|
||||
this.description = nDescription;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String user) {
|
||||
this.username = user;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package _11.asktpk.artisanconnectbackend.Repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface NoticeRepository extends JpaRepository<Notice, Long> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package _11.asktpk.artisanconnectbackend.Service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IDatabase {
|
||||
void add(Notice newNotice);
|
||||
List<Notice> get();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package _11.asktpk.artisanconnectbackend.Service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.Repository.NoticeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PostgresDatabase implements IDatabase{
|
||||
@Autowired
|
||||
private NoticeRepository noticeRepository;
|
||||
|
||||
@Override
|
||||
public void add(Notice newNotice) {
|
||||
noticeRepository.save(newNotice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Notice> get() {
|
||||
return noticeRepository.findAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user