base
This commit is contained in:
		| @ -0,0 +1,8 @@ | ||||
| package ovh.herisson.Clyde.Repositories; | ||||
|  | ||||
| import org.springframework.data.repository.CrudRepository; | ||||
|  | ||||
| import ovh.herisson.Clyde.Tables.Notification; | ||||
|  | ||||
| interface NotificationRepository extends CrudRepository<Notification, Long> {} | ||||
|  | ||||
| @ -17,6 +17,8 @@ import org.springframework.stereotype.Service; | ||||
| import com.fasterxml.jackson.databind.util.JSONPObject; | ||||
|  | ||||
| import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository; | ||||
| import ovh.herisson.Clyde.Services.UserService; | ||||
| import ovh.herisson.Clyde.Tables.Notification; | ||||
| import ovh.herisson.Clyde.Tables.User; | ||||
| import ovh.herisson.Clyde.Tables.Msg.Discussion; | ||||
| import ovh.herisson.Clyde.Tables.Msg.Message; | ||||
| @ -26,6 +28,8 @@ public class DiscussionService { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private DiscussionRepository discRepo; | ||||
| 	@Autowired | ||||
| 	private UserService userServ; | ||||
|  | ||||
| 	public Discussion create(String name, User author){ | ||||
| 		return discRepo.save(new Discussion(name, author)); | ||||
| @ -42,6 +46,9 @@ public class DiscussionService { | ||||
| 	 * Create a message and link it to it's discussion | ||||
| 	 */ | ||||
| 	public Discussion CreateMessage(Discussion disc, Message msg){ | ||||
| 		for(User u: disc.getMembers()){ | ||||
| 			userServ.Notify(u, new Notification("msg.notification.new", msg.getContent(), "/#/msg")); | ||||
| 		} | ||||
| 		disc.addMessage(msg); | ||||
| 		return discRepo.save(disc); | ||||
| 	} | ||||
|  | ||||
| @ -0,0 +1,9 @@ | ||||
| package ovh.herisson.Clyde.Services; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| @Service | ||||
| public class NotificationService { | ||||
|  | ||||
| } | ||||
| @ -3,6 +3,7 @@ package ovh.herisson.Clyde.Services; | ||||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||||
| import org.springframework.stereotype.Service; | ||||
| import ovh.herisson.Clyde.Repositories.UserRepository; | ||||
| import ovh.herisson.Clyde.Tables.Notification; | ||||
| import ovh.herisson.Clyde.Tables.Role; | ||||
| import ovh.herisson.Clyde.Tables.User; | ||||
| import java.util.*; | ||||
| @ -131,4 +132,10 @@ public class UserService { | ||||
|     public void delete(User user) { | ||||
|         userRepo.delete(user); | ||||
|     } | ||||
|  | ||||
| 	public void Notify(User u, Notification n){ | ||||
| 		n.setUser(u); | ||||
| 		u.getNotifications().add(n); | ||||
| 		userRepo.save(u); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -4,12 +4,17 @@ import java.util.Date; | ||||
|  | ||||
| import org.hibernate.annotations.CreationTimestamp; | ||||
|  | ||||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||||
|  | ||||
| import jakarta.annotation.Nullable; | ||||
| import jakarta.persistence.Entity; | ||||
| import jakarta.persistence.Id; | ||||
| import jakarta.persistence.ManyToOne; | ||||
| import lombok.Data; | ||||
| import lombok.NoArgsConstructor; | ||||
|  | ||||
| @Data | ||||
| @NoArgsConstructor | ||||
| @Entity | ||||
| public class Notification { | ||||
|  | ||||
| @ -21,11 +26,11 @@ public class Notification { | ||||
| 	@Id | ||||
| 	private int id; | ||||
| 	 | ||||
| 	private String Subject; | ||||
| 	private String subject; | ||||
|  | ||||
| 	private String body; | ||||
|  | ||||
| 	private Status status; | ||||
| 	private Status status = Status.Unread; | ||||
|  | ||||
| 	private String link; | ||||
|  | ||||
| @ -34,4 +39,10 @@ public class Notification { | ||||
|  | ||||
| 	@CreationTimestamp | ||||
| 	private Date creation; | ||||
|  | ||||
| 	public Notification(String subject, @Nullable String body, @Nullable String link){ | ||||
| 		this.subject = subject; | ||||
| 		this.body = body; | ||||
| 		this.link = link; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -2,15 +2,19 @@ package ovh.herisson.Clyde.Tables; | ||||
|  | ||||
| import jakarta.persistence.*; | ||||
| import lombok.Data; | ||||
| import lombok.NoArgsConstructor; | ||||
| import ovh.herisson.Clyde.Tables.Msg.Discussion; | ||||
| import ovh.herisson.Clyde.Tables.Msg.Message; | ||||
|  | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||||
|  | ||||
|  | ||||
| @Entity | ||||
| @Table(name = "Users") | ||||
| @NoArgsConstructor | ||||
| @Data | ||||
| public class User { | ||||
|     @Id | ||||
| @ -24,19 +28,23 @@ public class User { | ||||
|     private String country; | ||||
|     private Date birthDate; | ||||
|     private String profilePictureUrl; | ||||
|     private ovh.herisson.Clyde.Tables.Role role; | ||||
|     private Role role; | ||||
| 	@JsonIgnore | ||||
|     private String password; | ||||
|  | ||||
| 	@OneToMany(mappedBy = "user") | ||||
| 	@JsonIgnore | ||||
| 	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL) | ||||
| 	private List<Notification> notifications;  | ||||
|  | ||||
| 	////// Extension Messagerie ///// | ||||
| 	@JsonIgnore | ||||
| 	@OneToMany(mappedBy = "author", cascade = CascadeType.ALL) | ||||
| 	private List<Message> msgs; | ||||
| 	///////////////////////////////// | ||||
|  | ||||
| 	@JsonIgnore | ||||
| 	@ManyToMany( mappedBy = "members" ) | ||||
| 	private List<Discussion> discussions; | ||||
| 	///////////////////////////////// | ||||
|  | ||||
|     public User(String lastName, String firstName, String email, String address, | ||||
|                 String country, Date birthDate, String profilePictureUrl, Role role, String password) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user