Merge remote-tracking branch 'origin/master' into controllerAndControllerServiceRefactor
# Conflicts: # src/main/java/mops/gruppen2/controller/WebController.java # src/main/java/mops/gruppen2/service/ControllerService.java # src/test/java/mops/gruppen2/service/ControllerServiceTest.java
This commit is contained in:
@ -2,6 +2,7 @@ package mops.gruppen2;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
@ -14,6 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
import java.util.Collections;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
@EnableSwagger2
|
||||
public class Gruppen2Application {
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.service.APIFormatterService;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -28,14 +30,16 @@ public class APIController {
|
||||
|
||||
private final EventService eventService;
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
|
||||
public APIController(EventService eventService, GroupService groupService) {
|
||||
public APIController(EventService eventService, GroupService groupService, UserService userService) {
|
||||
this.eventService = eventService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
//@Secured("ROLE_api_user")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
@ -44,16 +48,16 @@ public class APIController {
|
||||
}
|
||||
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
//@Secured("ROLE_api_user")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
|
||||
return eventService.findGroupIdsByUser(teilnehmer).stream()
|
||||
.map(UUID::toString)
|
||||
.collect(Collectors.toList());
|
||||
return userService.getUserGroups(teilnehmer).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
//@Secured("ROLE_api_user")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
|
||||
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));
|
||||
|
||||
@ -3,15 +3,18 @@ package mops.gruppen2.controller;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -39,13 +42,15 @@ public class WebController {
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
|
||||
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService) {
|
||||
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService, InviteService inviteService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +60,6 @@ public class WebController {
|
||||
* @param model tolles model
|
||||
* @return index.html
|
||||
*/
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("")
|
||||
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||
@ -80,6 +84,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/createOrga")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@ -111,6 +116,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_studentin"})
|
||||
@PostMapping("/createStudent")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@ -130,6 +136,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/addUsersFromCsv")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
|
||||
@ -162,6 +169,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/changeMetadata")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postChangeMetadata(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@ -189,12 +197,17 @@ public class WebController {
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", groups);
|
||||
model.addAttribute("inviteService", inviteService);
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") String groupId) throws EventException {
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String groupId) throws EventException {
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
@ -222,13 +235,14 @@ public class WebController {
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
|
||||
if (validationService.checkIfAdmin(group, user)) {
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
|
||||
}
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -267,22 +281,46 @@ public class WebController {
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
//TODO: Muss post-mapping sein
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{groupId}")
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model, @PathVariable String groupId) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
Model model,
|
||||
@PathVariable("link") String link) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("group", group);
|
||||
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
|
||||
|
||||
//controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), group.getId());
|
||||
|
||||
if (group.getVisibility() == Visibility.PUBLIC) {
|
||||
return "redirect:/gruppen2/details/" + group.getId();
|
||||
}
|
||||
|
||||
return "joinprivate";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/acceptinvite")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postAcceptInvite(KeycloakAuthenticationToken token,
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account acc = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
||||
|
||||
if (!validationService.checkIfUserInGroup(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
||||
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
||||
}
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/leaveGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -295,6 +333,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/deleteGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pDeleteGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -327,6 +366,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/changeRole")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
@ -348,6 +388,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/changeMaximum")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeMaxSize(@RequestParam("maximum") Long maximum,
|
||||
@RequestParam("group_id") String groupId,
|
||||
KeycloakAuthenticationToken token) {
|
||||
@ -362,6 +403,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/deleteUser")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String deleteUser(@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId,
|
||||
KeycloakAuthenticationToken token) throws EventException {
|
||||
|
||||
@ -11,8 +11,8 @@ import lombok.NoArgsConstructor;
|
||||
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
||||
public class User {
|
||||
|
||||
private String id;
|
||||
private String givenname;
|
||||
private String familyname;
|
||||
private String email;
|
||||
private String id;
|
||||
private String givenname;
|
||||
private String familyname;
|
||||
private String email;
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import org.springframework.data.relational.core.mapping.Table;
|
||||
public class InviteLinkDTO {
|
||||
|
||||
@Id
|
||||
Long link_id;
|
||||
Long invite_id;
|
||||
String group_id;
|
||||
String invite_link;
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class InvalidInviteException extends EventException {
|
||||
|
||||
public InvalidInviteException(String info) {
|
||||
super(HttpStatus.NOT_FOUND, "Der Einladungslink ist ungültig.", info);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class NoInviteExistException extends EventException {
|
||||
|
||||
public NoInviteExistException(String info) {
|
||||
super(HttpStatus.NOT_FOUND, "Für diese Gruppe existiert kein Link.", info);
|
||||
}
|
||||
}
|
||||
@ -12,15 +12,12 @@ import java.util.List;
|
||||
//TODO Rename Queries + Formatting
|
||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@Query("select distinct group_id from event where user_id =:id")
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE user_id = :id")
|
||||
List<String> findGroup_idsWhereUser_id(@Param("id") String userId);
|
||||
|
||||
@Query("select * from event where group_id =:id")
|
||||
@Query("SELECT * FROM event WHERE group_id = :id")
|
||||
List<EventDTO> findEventDTOByGroup_id(@Param("id") String groupId);
|
||||
|
||||
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
||||
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
|
||||
List<String> findNewEventSinceStatus(@Param("status") Long status);
|
||||
|
||||
|
||||
22
src/main/java/mops/gruppen2/repository/InviteRepository.java
Normal file
22
src/main/java/mops/gruppen2/repository/InviteRepository.java
Normal file
@ -0,0 +1,22 @@
|
||||
package mops.gruppen2.repository;
|
||||
|
||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import org.springframework.data.jdbc.repository.query.Modifying;
|
||||
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 InviteRepository extends CrudRepository<InviteLinkDTO, Long> {
|
||||
|
||||
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
|
||||
String findGroupIdByLink(@Param("link") String link);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM invite WHERE group_id = :group")
|
||||
void deleteLinkOfGroup(@Param("group") String group);
|
||||
|
||||
@Query("SELECT invite_link FROM invite WHERE group_id = :group")
|
||||
String findLinkByGroupId(@Param("group") String group);
|
||||
}
|
||||
@ -63,15 +63,8 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/h2-console/**")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
|
||||
http.csrf().disable();
|
||||
http.headers().frameOptions().disable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -15,6 +15,7 @@ import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -24,6 +25,7 @@ import java.io.CharConversionException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
@ -37,12 +39,14 @@ public class ControllerService {
|
||||
private final EventService eventService;
|
||||
private final UserService userService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final Logger logger;
|
||||
|
||||
public ControllerService(EventService eventService, UserService userService, ValidationService validationService) {
|
||||
this.eventService = eventService;
|
||||
this.userService = userService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||
}
|
||||
|
||||
@ -66,6 +70,8 @@ public class ControllerService {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
inviteService.createLink(groupId);
|
||||
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
|
||||
addUser(account, groupId);
|
||||
@ -248,6 +254,7 @@ public class ControllerService {
|
||||
|
||||
public void deleteGroupEvent(String userId, UUID groupId) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
|
||||
inviteService.destroyLink(groupId);
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +115,6 @@ public class EventService {
|
||||
return translateEventDTOs(eventDTOList);
|
||||
}
|
||||
|
||||
//TODO: Nur AddUserEvents betrachten
|
||||
public List<UUID> findGroupIdsByUser(String userId) {
|
||||
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||
.map(UUID::fromString)
|
||||
|
||||
@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -77,6 +78,7 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
@ -100,6 +102,7 @@ public class GroupService {
|
||||
*
|
||||
* @return List of groups
|
||||
*/
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllLecturesWithVisibilityPublic() {
|
||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
@ -124,6 +127,7 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//Todo Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
if (search.isEmpty()) {
|
||||
return getAllGroupWithVisibilityPublic(account.getName());
|
||||
|
||||
47
src/main/java/mops/gruppen2/service/InviteService.java
Normal file
47
src/main/java/mops/gruppen2/service/InviteService.java
Normal file
@ -0,0 +1,47 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import mops.gruppen2.domain.exception.InvalidInviteException;
|
||||
import mops.gruppen2.domain.exception.NoInviteExistException;
|
||||
import mops.gruppen2.repository.InviteRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class InviteService {
|
||||
|
||||
private final InviteRepository inviteRepository;
|
||||
|
||||
public InviteService(InviteRepository inviteRepository) {
|
||||
this.inviteRepository = inviteRepository;
|
||||
}
|
||||
|
||||
public void createLink(UUID groupId) {
|
||||
inviteRepository.save(new InviteLinkDTO(null, groupId.toString(), UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
public void destroyLink(UUID groupId) {
|
||||
inviteRepository.deleteLinkOfGroup(groupId.toString());
|
||||
}
|
||||
|
||||
public UUID getGroupIdFromLink(String link) {
|
||||
try {
|
||||
return UUID.fromString(inviteRepository.findGroupIdByLink(link));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new InvalidInviteException(link);
|
||||
}
|
||||
|
||||
public String getLinkByGroupId(UUID groupId) {
|
||||
try {
|
||||
return inviteRepository.findLinkByGroupId(groupId.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new NoInviteExistException(groupId.toString());
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -25,6 +26,7 @@ public class UserService {
|
||||
|
||||
//Test nötig??
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(User user) throws EventException {
|
||||
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
@ -41,6 +43,11 @@ public class UserService {
|
||||
return newGroups;
|
||||
}
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, null, null, null));
|
||||
}
|
||||
|
||||
public Group getGroupById(UUID groupId) throws EventException {
|
||||
List<UUID> groupIds = new ArrayList<>();
|
||||
groupIds.add(groupId);
|
||||
|
||||
Reference in New Issue
Block a user