signing and commenting
This commit is contained in:
		@ -1,5 +1,13 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.DTO.Msg;
 | 
					package ovh.herisson.Clyde.DTO.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file DiscussionDTO.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * File to format a discussion using messageDTO 
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.stream.Collectors;
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,13 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.DTO.Msg;
 | 
					package ovh.herisson.Clyde.DTO.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file MessagesDTO.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * File to Format the response adding the sender field
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import lombok.AllArgsConstructor;
 | 
					import lombok.AllArgsConstructor;
 | 
				
			||||||
import lombok.Data;
 | 
					import lombok.Data;
 | 
				
			||||||
import ovh.herisson.Clyde.Tables.User;
 | 
					import ovh.herisson.Clyde.Tables.User;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,13 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.EndPoints.Msg;
 | 
					package ovh.herisson.Clyde.EndPoints.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file MessagesController.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Entry point for the messages application
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.http.HttpStatus;
 | 
					import org.springframework.http.HttpStatus;
 | 
				
			||||||
import org.springframework.http.ResponseEntity;
 | 
					import org.springframework.http.ResponseEntity;
 | 
				
			||||||
@ -48,6 +56,10 @@ public class MessagesController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	@GetMapping("/discussion/{id}")
 | 
						@GetMapping("/discussion/{id}")
 | 
				
			||||||
	public ResponseEntity<DiscussionDTO> getDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
						public ResponseEntity<DiscussionDTO> getDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
				
			||||||
 | 
							User user = authServ.getUserFromToken(token);
 | 
				
			||||||
 | 
							if(user == null || !discServ.hasDiscussion(user, id) ){
 | 
				
			||||||
 | 
								return new UnauthorizedResponse<>(null);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return new ResponseEntity<>(DiscussionDTO.construct(discRepo.findById(id).orElse(null), authServ.getUserFromToken(token)), HttpStatus.OK);
 | 
							return new ResponseEntity<>(DiscussionDTO.construct(discRepo.findById(id).orElse(null), authServ.getUserFromToken(token)), HttpStatus.OK);
 | 
				
			||||||
	} 
 | 
						} 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,14 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.Repositories.Msg;
 | 
					package ovh.herisson.Clyde.Repositories.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file DiscussionRepository.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Repository of Discussion allowing to fetch discussion by user 
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.data.jpa.repository.Query;
 | 
					import org.springframework.data.jpa.repository.Query;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,14 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.Repositories.Msg;
 | 
					package ovh.herisson.Clyde.Repositories.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file MessageRepository.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.data.repository.CrudRepository;
 | 
					import org.springframework.data.repository.CrudRepository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ovh.herisson.Clyde.Tables.Msg.Message;
 | 
					import ovh.herisson.Clyde.Tables.Msg.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface MessageRepository extends CrudRepository<Message, Long> {
 | 
					public interface MessageRepository extends CrudRepository<Message, Long> {}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,16 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.Services.Msg;
 | 
					package ovh.herisson.Clyde.Services.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file DiscussionService.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Various function utilised by the messages application
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,12 +31,27 @@ public class DiscussionService {
 | 
				
			|||||||
		return discRepo.save(new Discussion(name, author));
 | 
							return discRepo.save(new Discussion(name, author));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * list discussions owned by a certain user
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
	public Iterable<Discussion> getOwned(User author){
 | 
						public Iterable<Discussion> getOwned(User author){
 | 
				
			||||||
		return discRepo.findByMembership(author.getRegNo());
 | 
							return discRepo.findByMembership(author.getRegNo());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Create a message and link it to it's discussion
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
	public Discussion CreateMessage(Discussion disc, Message msg){
 | 
						public Discussion CreateMessage(Discussion disc, Message msg){
 | 
				
			||||||
		disc.addMessage(msg);
 | 
							disc.addMessage(msg);
 | 
				
			||||||
		return discRepo.save(disc);
 | 
							return discRepo.save(disc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Check if a user is in a discussion
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
					    public boolean hasDiscussion(User user, long id) {
 | 
				
			||||||
 | 
							Discussion disc = discRepo.findById(id).orElse(null);
 | 
				
			||||||
 | 
							List<User> members = disc.getMembers();
 | 
				
			||||||
 | 
							return members.contains(user);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,15 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.Tables.Msg;
 | 
					package ovh.herisson.Clyde.Tables.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file Discussion.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Discussion allow to regroupe multiple user in and message together
 | 
				
			||||||
 | 
					 * for the messages application to work
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import jakarta.persistence.CascadeType;
 | 
					import jakarta.persistence.CascadeType;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,14 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.Tables.Msg;
 | 
					package ovh.herisson.Clyde.Tables.Msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/******************************************************
 | 
				
			||||||
 | 
					 * @file Message.java
 | 
				
			||||||
 | 
					 * @author Anthony Debucquoy
 | 
				
			||||||
 | 
					 * @scope Extension messagerie
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Represent a message sent to a discussion
 | 
				
			||||||
 | 
					 ******************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.hibernate.annotations.CreationTimestamp;
 | 
					import org.hibernate.annotations.CreationTimestamp;
 | 
				
			||||||
import org.hibernate.annotations.UpdateTimestamp;
 | 
					import org.hibernate.annotations.UpdateTimestamp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user