Merge branch 'master' into edit-User
This commit is contained in:
@ -7,13 +7,13 @@ import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.service.APIFormatterService;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.SerializationService;
|
||||
import mops.gruppen2.service.*;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -36,7 +36,7 @@ public class APIController {
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
|
||||
|
||||
@ -46,17 +46,18 @@ public class APIController {
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||
public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException {
|
||||
public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException {
|
||||
return eventService.getGroupsOfUser(teilnehmer);
|
||||
}
|
||||
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation(value = "Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException{
|
||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException {
|
||||
List<Event> eventList = eventService.getEventsOfGroup(groupId);
|
||||
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@ package mops.gruppen2.controller;
|
||||
import mops.gruppen2.config.Gruppen2Config;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.security.Account;
|
||||
@ -18,14 +18,15 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
@ -39,13 +40,15 @@ public class Gruppen2Controller {
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
||||
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.eventService = eventService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,18 +58,40 @@ public class Gruppen2Controller {
|
||||
* @param model tolles model
|
||||
* @return index.html
|
||||
*/
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("")
|
||||
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||
model.addAttribute("user",user);
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@GetMapping("/createLecture")
|
||||
public String createLecture(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
return "createLecture";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/createLecture")
|
||||
public String pCreateLecture(KeycloakAuthenticationToken token,
|
||||
@RequestParam(value = "title") String title,
|
||||
@RequestParam(value = "beschreibung") String beschreibung,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("file") MultipartFile file) throws IOException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
visibility = visibility == null;
|
||||
controllerService.createLecture(account, title, beschreibung, visibility, userList);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/createGroup")
|
||||
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
||||
@ -74,18 +99,21 @@ public class Gruppen2Controller {
|
||||
return "create";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groupse = new ArrayList<>();
|
||||
if(suchbegriff!=null) {
|
||||
groupse = groupService.findGroupWith(suchbegriff);
|
||||
if (suchbegriff != null) {
|
||||
groupse = groupService.findGroupWith(suchbegriff,account);
|
||||
}
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("gruppen",groupse);
|
||||
model.addAttribute("gruppen", groupse);
|
||||
return "search";
|
||||
}
|
||||
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/createGroup")
|
||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam(value = "title") String title,
|
||||
@ -93,11 +121,7 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
if (visibility == null) {
|
||||
visibility = true;
|
||||
} else {
|
||||
visibility = false;
|
||||
}
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, beschreibung, visibility);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
@ -106,11 +130,12 @@ public class Gruppen2Controller {
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable (value="id") Long id) throws EventException, ResponseStatusException {
|
||||
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(id);
|
||||
Account account = keyCloakService.createAccountFromPrincipal (token);
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
if(group!= null) {
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
@ -120,7 +145,7 @@ public class Gruppen2Controller {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
@ -132,19 +157,31 @@ public class Gruppen2Controller {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/detailsSearch")
|
||||
public String showGroupDetailsNoMember (KeycloakAuthenticationToken token, Model model, @RequestParam (value="id") Long id) throws EventException {
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(id);
|
||||
if (group!=null) {
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String link) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(inviteLinkRepositoryService.findGroupIdByInvite(link));
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
|
||||
}
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/leaveGroup")
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -182,5 +219,10 @@ public class Gruppen2Controller {
|
||||
@RequestParam (value = "user_id") String user_id) throws EventException {
|
||||
controllerService.deleteUser(user_id, group_id);
|
||||
return "redirect:/gruppen2/details/members/" + group_id;
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() {
|
||||
return "errorRenameLater";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
public class MopsController {
|
||||
|
||||
@GetMapping("")
|
||||
public String redirect(){
|
||||
public String redirect() {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
|
||||
@ -3,10 +3,11 @@ package mops.gruppen2.domain;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Value
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
||||
public class User {
|
||||
String user_id;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.domain;
|
||||
package mops.gruppen2.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
16
src/main/java/mops/gruppen2/domain/dto/InviteLinkDTO.java
Normal file
16
src/main/java/mops/gruppen2/domain/dto/InviteLinkDTO.java
Normal file
@ -0,0 +1,16 @@
|
||||
package mops.gruppen2.domain.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
@Table("invite")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class InviteLinkDTO {
|
||||
@Id
|
||||
Long link_id;
|
||||
Long group_id;
|
||||
String invite_link;
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
package mops.gruppen2.repository;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@ -30,4 +30,7 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@Query("SELECT MAX(event_id) FROM event")
|
||||
public Long getHighesEvent_ID();
|
||||
|
||||
@Query("SELECT MAX(group_id) FROM event")
|
||||
public Long getMaxGroupID();
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package mops.gruppen2.repository;
|
||||
|
||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface InviteLinkRepository extends CrudRepository<InviteLinkDTO, Long> {
|
||||
|
||||
//@Query("SELECT invite_link FROM invite WHERE group_id = :id")
|
||||
//String findLinkByGroupID(@Param("id") Long GroupID);
|
||||
|
||||
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
|
||||
Long findGroupIdByLink(@Param("link") String link);
|
||||
}
|
||||
@ -1,20 +1,33 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.*;
|
||||
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.event.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import mops.gruppen2.domain.event.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@Service
|
||||
public class ControllerService {
|
||||
|
||||
private final EventService eventService;
|
||||
private final UserService userService;
|
||||
|
||||
public ControllerService(EventService eventService, UserService userService) {
|
||||
private final UserService userService;
|
||||
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
||||
|
||||
public ControllerService(EventService eventService, InviteLinkRepositoryService inviteLinkRepositoryService) {
|
||||
this.eventService = eventService;
|
||||
this.userService = userService;
|
||||
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,9 +47,10 @@ public class ControllerService {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
createInviteLink(group_id);
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.SIMPLE, visibility1);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
|
||||
@ -46,11 +60,23 @@ public class ControllerService {
|
||||
updateRole(user.getUser_id(), group_id);
|
||||
}
|
||||
|
||||
private void createInviteLink(Long group_id) {
|
||||
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
|
||||
}
|
||||
|
||||
|
||||
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 addUserList(List<User> users, Long group_id) {
|
||||
for (User user : users) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(group_id, user.getUser_id(), user.getGivenname(), user.getFamilyname(), user.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);
|
||||
@ -87,9 +113,30 @@ public class ControllerService {
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id, user.getUser_id());
|
||||
eventService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
|
||||
|
||||
public void deleteGroupEvent(User user, Long group_id) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(group_id, user.getUser_id());
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
|
||||
|
||||
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) {
|
||||
Visibility visibility1;
|
||||
Long group_id = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
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);
|
||||
addUserList(users, group_id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/java/mops/gruppen2/service/CsvService.java
Normal file
24
src/main/java/mops/gruppen2/service/CsvService.java
Normal file
@ -0,0 +1,24 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||
import mops.gruppen2.domain.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CsvService {
|
||||
|
||||
public static List<User> read(InputStream stream) throws IOException {
|
||||
CsvMapper mapper = new CsvMapper();
|
||||
|
||||
CsvSchema schema = mapper.schemaFor(User.class).withHeader().withColumnReordering(true);
|
||||
ObjectReader reader = mapper.readerFor(User.class).with(schema);
|
||||
|
||||
return reader.<User>readValues(stream).readAll();
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
@ -59,22 +59,17 @@ public class EventService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorgt dafür die Group_id immer um 1 zu erhöhen
|
||||
* Gibt die nächst höhere groupID zurück die belegt werden kann.
|
||||
* Gibt 1 zurück, falls keine Gruppe vorhanden ist.
|
||||
*
|
||||
* @return Gibt Long zurück
|
||||
*/
|
||||
public Long checkGroup() {
|
||||
Long tmpId = 1L;
|
||||
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
||||
for (EventDTO event : eventDTOS) {
|
||||
if (event.getGroup_id() == null) {
|
||||
return tmpId;
|
||||
}
|
||||
if (tmpId <= event.getGroup_id()) {
|
||||
tmpId++;
|
||||
}
|
||||
Long maxGroupID = eventStore.getMaxGroupID();
|
||||
if (maxGroupID == null) {
|
||||
return 1L;
|
||||
}
|
||||
return tmpId;
|
||||
return maxGroupID + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -71,15 +72,21 @@ public class GroupService {
|
||||
return groups.get(group_id);
|
||||
}
|
||||
|
||||
private List<Long> removeUserGroups(List<Long> group_ids, List<Long> user_groups) {
|
||||
for (Long group_id: user_groups) {
|
||||
group_ids.remove(group_id);
|
||||
}
|
||||
return group_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* sucht alle Zeilen in der DB wo die Visibility gleich true ist und wandelt diese in
|
||||
* eine Liste von Gruppen
|
||||
* sucht alle Zeilen in der DB wo die Visibility true ist und entfernt alle Gruppen des Users.
|
||||
* Erstellt eine Liste aus Gruppen.
|
||||
* @return
|
||||
* @throws EventException
|
||||
*/
|
||||
|
||||
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
|
||||
List<Long> group_ids = eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE);
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String user_id) throws EventException {
|
||||
List<Long> group_ids = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(user_id));
|
||||
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
|
||||
List<Event> events = eventService.translateEventDTOs(eventDTOS);
|
||||
List<Group> groups = projectEventList(events);
|
||||
@ -94,10 +101,10 @@ public class GroupService {
|
||||
* @return
|
||||
* @throws EventException
|
||||
*/
|
||||
public List<Group> findGroupWith(String search) throws EventException {
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
List<Group> groups = new ArrayList<>();
|
||||
for (Group group: getAllGroupWithVisibilityPublic()) {
|
||||
if (group.getTitle().contains(search)|| group.getDescription().contains(search)){
|
||||
for (Group group: getAllGroupWithVisibilityPublic(account.getName())) {
|
||||
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())){
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import mops.gruppen2.repository.InviteLinkRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class InviteLinkRepositoryService {
|
||||
|
||||
private final InviteLinkRepository inviteLinkRepository;
|
||||
|
||||
public InviteLinkRepositoryService(InviteLinkRepository inviteLinkRepository) {
|
||||
this.inviteLinkRepository = inviteLinkRepository;
|
||||
}
|
||||
|
||||
public long findGroupIdByInvite(String link) {
|
||||
return inviteLinkRepository.findGroupIdByLink(link);
|
||||
}
|
||||
|
||||
public void saveInvite(Long group_id, UUID link) {
|
||||
inviteLinkRepository.save(new InviteLinkDTO(null, group_id, link.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,6 @@ package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@ -1,23 +1,21 @@
|
||||
server.port=8080
|
||||
application.name=gruppen2
|
||||
|
||||
logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n
|
||||
|
||||
spring.datasource.url=jdbc:h2:mem:blogdb
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
|
||||
spring.h2.console.enabled=true
|
||||
logging.level.org.springframework.jdbc.core=DEBUG
|
||||
keycloak.principal-attribute=preferred_username
|
||||
keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth
|
||||
keycloak.realm=MOPS
|
||||
|
||||
hhu_keycloak.token-uri=https://keycloak.cs.hhu.de/auth/realms/MOPS/protocol/openid-connect/token
|
||||
keycloak.resource=gruppenfindung
|
||||
keycloak.credentials.secret= fc6ebf10-8c63-4e71-a667-4eae4e8209a1
|
||||
keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
|
||||
keycloak.verify-token-audience=true
|
||||
keycloak.use-resource-role-mappings=true
|
||||
|
||||
keycloak.autodetect-bearer-only=true
|
||||
keycloak.confidential-port= 443
|
||||
keycloak.confidential-port= 443
|
||||
|
||||
@ -10,3 +10,12 @@ CREATE TABLE event
|
||||
event_payload VARCHAR(2500),
|
||||
visibility BOOLEAN
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS invite;
|
||||
|
||||
CREATE TABLE invite
|
||||
(
|
||||
link_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
group_id INT NOT NULL,
|
||||
invite_link varchar(255) NOT NULL
|
||||
);
|
||||
|
||||
@ -22,6 +22,9 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
@ -64,4 +67,4 @@
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
70
src/main/resources/templates/createLecture.html
Normal file
70
src/main/resources/templates/createLecture.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
||||
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
|
||||
xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Gruppenerstellung</title>
|
||||
<th:block th:fragment="headcontent">
|
||||
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||
</th:block>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<ul>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}" class="active">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Veranstaltung erstellen</h1>
|
||||
<div class="shadow p-2" style=" border: 10px solid aliceblue; background: aliceblue">
|
||||
<form method="post" action="/gruppen2/createLecture" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label for="titel">Titel</label>
|
||||
<input type="text" class="form-control" id="titel" th:name="title" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="beschreibung">Beschreibung</label>
|
||||
<textarea th:name="beschreibung" class="form-control" id="beschreibung" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input type="checkbox" id="visibility" class="custom-control-input" th:name="visibility">
|
||||
<label class="custom-control-label" for="visibility">Private Gruppe</label>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="file" th:name="file">
|
||||
<label class="custom-file-label" for="file">CSV Datei von Mitgliedern hochladen</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<button class="btn btn-primary" type="submit" style="background: #52a1eb; border-style: none">Erstellen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@ -21,6 +21,9 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -21,7 +21,13 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
</ul>--
|
||||
</ul>
|
||||
<!-- Fix double point -->
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
<li class="active">
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.EventDTO;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.AddUserEvent;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
@ -14,7 +14,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -28,21 +28,6 @@ class EventServiceTest {
|
||||
eventService = new EventService(mock(SerializationService.class), eventRepositoryMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkGroupTest() {
|
||||
EventDTO eventDTO = new EventDTO();
|
||||
EventDTO eventDTO1 = new EventDTO();
|
||||
eventDTO1.setGroup_id(1L);
|
||||
eventDTO.setUser_id("realer");
|
||||
eventDTO.setUser_id("faker");
|
||||
eventDTO.setGroup_id(0L);
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
eventDTOS.add(eventDTO);
|
||||
eventDTOS.add(eventDTO1);
|
||||
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
|
||||
assertEquals(eventDTO1.getGroup_id() + 1, eventService.checkGroup());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMaxID() {
|
||||
when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L);
|
||||
@ -52,14 +37,7 @@ class EventServiceTest {
|
||||
|
||||
@Test
|
||||
void checkGroupReturnNextValue() {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
EventDTO eventDTO1 = new EventDTO();
|
||||
EventDTO eventDTO2 = new EventDTO();
|
||||
eventDTO1.setGroup_id(1L);
|
||||
eventDTO2.setGroup_id(2L);
|
||||
eventDTOS.add(eventDTO1);
|
||||
eventDTOS.add(eventDTO2);
|
||||
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
|
||||
when(eventRepositoryMock.getMaxGroupID()).thenReturn(2L);
|
||||
|
||||
assertEquals(eventService.checkGroup(), 3L);
|
||||
}
|
||||
@ -86,4 +64,4 @@ class EventServiceTest {
|
||||
assertEquals(eventDTO.isVisibility(), false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user