Merge remote-tracking branch 'origin/master' into group-invite-links
# Conflicts: # src/main/java/mops/gruppen2/controller/Gruppen2Controller.java # src/main/java/mops/gruppen2/repository/EventRepository.java # src/main/java/mops/gruppen2/service/ControllerService.java # src/main/java/mops/gruppen2/service/GroupService.java
This commit is contained in:
@ -34,31 +34,51 @@ public class ControllerService {
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
||||
Long groupID = eventService.checkGroup();
|
||||
Long group_id = eventService.checkGroup();
|
||||
Visibility visibility1;
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
createInviteLink(groupID);
|
||||
createInviteLink(group_id);
|
||||
}
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
Collections.addAll(eventList, new CreateGroupEvent(groupID, account.getName(), null, GroupType.LECTURE, visibility1),
|
||||
new AddUserEvent(groupID, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()),
|
||||
new UpdateRoleEvent(groupID, account.getName(), Role.ADMIN),
|
||||
new UpdateGroupTitleEvent(groupID, account.getName(), title),
|
||||
new UpdateGroupDescriptionEvent(groupID, account.getName(), description),
|
||||
new UpdateRoleEvent(groupID, account.getName(), Role.ADMIN));
|
||||
|
||||
eventService.saveEventList(eventList);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, group_id);
|
||||
updateTitle(account, group_id, title);
|
||||
updateDescription(account, group_id, description);
|
||||
updateRole(account, group_id);
|
||||
}
|
||||
|
||||
private void createInviteLink(Long group_id) {
|
||||
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
|
||||
}
|
||||
|
||||
public void addUser(Account account, Group group) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), group.getId(), account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
|
||||
public void addUser(Account account, Long group_id){
|
||||
AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
public void updateTitle(Account account, Long group_id, String title){
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
}
|
||||
|
||||
public void updateDescription(Account account, Long group_id, String description){
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(group_id,account.getName(),description);
|
||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||
}
|
||||
|
||||
public void updateRole(Account account,Long group_id){
|
||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(group_id,account.getName(),Role.ADMIN);
|
||||
eventService.saveEvent(updateRoleEvent);
|
||||
}
|
||||
|
||||
public void deleteUser(Account account, Long group_id){
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
||||
eventService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -31,11 +32,10 @@ public class GroupService {
|
||||
*/
|
||||
public List<Event> getGroupEvents(List<Long> group_ids) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
List<Event> events = new ArrayList<>();
|
||||
for (Long group_id: group_ids) {
|
||||
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
|
||||
}
|
||||
return events = eventService.translateEventDTOs(eventDTOS);
|
||||
return eventService.translateEventDTOs(eventDTOS);
|
||||
}
|
||||
|
||||
/** Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
|
||||
@ -49,7 +49,8 @@ public class GroupService {
|
||||
Map<Long, Group> groupMap = new HashMap<>();
|
||||
|
||||
for (Event event : events) {
|
||||
getOrCreateGroup(groupMap, event.getGroup_id()).applyEvent(event);
|
||||
Group group = getOrCreateGroup(groupMap, event.getGroup_id());
|
||||
event.apply(group);
|
||||
}
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
@ -76,8 +77,13 @@ public class GroupService {
|
||||
* @return
|
||||
* @throws EventException
|
||||
*/
|
||||
|
||||
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
|
||||
return projectEventList(eventService.translateEventDTOs(eventRepository.findEventDTOByVisibility(Boolean.TRUE)));
|
||||
List<Long> group_ids = eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE);
|
||||
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
|
||||
List<Event> events = eventService.translateEventDTOs(eventDTOS);
|
||||
List<Group> groups = projectEventList(events);
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
||||
@ -91,7 +97,7 @@ public class GroupService {
|
||||
public List<Group> findGroupWith(String search) throws EventException {
|
||||
List<Group> groups = new ArrayList<>();
|
||||
for (Group group: getAllGroupWithVisibilityPublic()) {
|
||||
if (group.getTitle().contains(search)){
|
||||
if (group.getTitle().contains(search)|| group.getDescription().contains(search)){
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,14 @@ package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//Hallo
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
@ -22,10 +23,17 @@ public class UserService {
|
||||
|
||||
//Test nötig??
|
||||
|
||||
public List<Group> getUserGroups(String user_id) throws EventException {
|
||||
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
||||
public List<Group> getUserGroups(User user) throws EventException {
|
||||
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user.getUser_id());
|
||||
List<Event> events = groupService.getGroupEvents(group_ids);
|
||||
return groupService.projectEventList(events);
|
||||
List<Group> groups = groupService.projectEventList(events);
|
||||
List<Group> newGroups = new ArrayList<>();
|
||||
for (Group group: groups) {
|
||||
if(group.getMembers().contains(user)){
|
||||
newGroups.add(group);
|
||||
}
|
||||
}
|
||||
return newGroups;
|
||||
}
|
||||
|
||||
public Group getGroupById(Long group_id) throws EventException {
|
||||
|
||||
Reference in New Issue
Block a user