Skip to content
Merged
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
10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

51 changes: 50 additions & 1 deletion src/main/java/com/example/demo/controller/MessageController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
package com.example.demo.controller;

import com.example.demo.models.Message;
import com.example.demo.repository.MessageRepo;
import com.example.demo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/message")
public class MessageController {
}

private MessageService messageService;

@Autowired
public MessageController(MessageService messageService) {
this.messageService = messageService;

}

@PostMapping(value = "/create")
public ResponseEntity<Message> create(@RequestBody Message message) {
return new ResponseEntity<>(messageService.create(message), HttpStatus.CREATED);
}

@GetMapping(value = "/read/{id}")
public ResponseEntity<Message> read(@PathVariable Long id ){
return new ResponseEntity<>(messageService.read(id), HttpStatus.OK);

}

@GetMapping(value = "/all")
public ResponseEntity<List<Message>> readAll(){
return new ResponseEntity<>(messageService.readAll(), HttpStatus.OK);
}

@PutMapping(value = "/update{id}")
public ResponseEntity<Message> update (@PathVariable Long id, @RequestBody Message newMessageData){
return new ResponseEntity<>(messageService.update(id, newMessageData), HttpStatus.OK);
}

@DeleteMapping(value = "delete{id}")
public ResponseEntity<Message> delete(@PathVariable Long id ){
return new ResponseEntity<>(messageService.delete(id), HttpStatus.OK);
}


}
45 changes: 0 additions & 45 deletions src/main/java/com/example/demo/models/Channel.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
package com.example.demo.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.List;

@Entity
public class Channel {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private List<Profile> profileList;
private List<Message> messages;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Profile> getProfileList() {
return profileList;
}

public void setProfileList(List<Profile> profileList) {
this.profileList = profileList;
}

public List<Message> getMessages() {
return messages;
}

public void setMessages(List<Message> messages) {
this.messages = messages;
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/example/demo/models/Message.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
package com.example.demo.models;

import org.apache.catalina.User;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;

@Entity
public class Message {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
Profile profile;
String body;
Date timestamp;


public Message() {
}

public Message(Long id, Profile profile, String body, Date timestamp) {
this.id = id;
this.profile = profile;
this.body = body;
this.timestamp = timestamp;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Profile getProfile() {
return profile;
}

public void setProfile(Profile profile) {
this.profile = profile;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

public Date getTimestamp() {
return timestamp;
}

public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}

}
8 changes: 7 additions & 1 deletion src/main/java/com/example/demo/repository/MessageRepo.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.example.demo.repository;

public class MessageRepo {
import com.example.demo.models.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface MessageRepo extends JpaRepository<Message, Long> {

}
48 changes: 48 additions & 0 deletions src/main/java/com/example/demo/service/MessageService.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
package com.example.demo.service;

import com.example.demo.models.Message;
import com.example.demo.repository.MessageRepo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class MessageService {
private MessageRepo messageRepo;


@Autowired
public MessageService(MessageRepo messageRepo){
this.messageRepo = messageRepo;
}


public Message create (Message message){
return messageRepo.save(message);
}

public Message read(Long id){
return messageRepo.getById(id);
}

public List<Message> readAll(){
return messageRepo.findAll();
}

public Message update(Long id, Message newMessageData){
Message messageInDB = read(id);
messageInDB.setBody(newMessageData.getBody());
messageInDB.setProfile(newMessageData.getProfile());
messageInDB.setTimestamp(newMessageData.getTimestamp());
messageRepo.save(messageInDB);
return messageInDB;
}

public Message delete(Long id){
Message messageInDB = read(id);
messageRepo.delete(messageInDB);
return messageInDB;
}

public void deleteAll(){
messageRepo.deleteAll();
}



}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added target/classes/com/example/demo/models/Profile.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.