Refactor after merge with master
Co-Authored-By: Talha Caliskan <killerber4t@users.noreply.github.com>
This commit is contained in:
@ -13,7 +13,6 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
@ -82,6 +81,7 @@ public class WebController {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
List<User> userList = new ArrayList<>();
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
Group group = userService.getGroupById(controllerService.createOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID));
|
||||
userList = validationService.checkFile(file, userList, group.getId().toString(), group, account);
|
||||
controllerService.addUserList(userList, group.getId());
|
||||
@ -109,6 +109,7 @@ public class WebController {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@ -45,26 +45,6 @@ public class ControllerService {
|
||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft ob alle Felder richtig gesetzt sind.
|
||||
* @param description
|
||||
* @param title
|
||||
* @param userMaximum
|
||||
*/
|
||||
private void checkFields(String description, String title, Long userMaximum ) {
|
||||
if(description == null) {
|
||||
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if(title == null) {
|
||||
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (userMaximum == null) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
|
||||
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
|
||||
@ -80,13 +60,10 @@ public class ControllerService {
|
||||
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
|
||||
|
||||
if(maxInfiniteUsers) {
|
||||
if (maxInfiniteUsers) {
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
checkFields(description, title, userMaximum);
|
||||
|
||||
visibility = visibility == null;
|
||||
|
||||
if (visibility) {
|
||||
@ -105,15 +82,17 @@ public class ControllerService {
|
||||
}
|
||||
|
||||
public UUID createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException, IOException {
|
||||
List<User> userList = new ArrayList<>();
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
if(maxInfiniteUsers) {
|
||||
|
||||
if (maxInfiniteUsers) {
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
visibility = visibility == null;
|
||||
lecture = lecture != null;
|
||||
Visibility visibility1;
|
||||
UUID groupId = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
@ -127,11 +106,6 @@ public class ControllerService {
|
||||
groupType = GroupType.SIMPLE;
|
||||
}
|
||||
|
||||
|
||||
if(maxInfiniteUsers){
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, visibility1, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.swing.text.StyledEditorKit;
|
||||
import javax.validation.ValidationException;
|
||||
import java.io.CharConversionException;
|
||||
import java.io.File;
|
||||
@ -46,7 +47,7 @@ public class ValidationService {
|
||||
}
|
||||
|
||||
public void checkGroup(String title) {
|
||||
if(title == null) throw new GroupNotFoundException("@details");
|
||||
if (title == null) throw new GroupNotFoundException("@details");
|
||||
}
|
||||
|
||||
public boolean checkIfUserInGroup(Group group, User user) {
|
||||
@ -64,7 +65,7 @@ public class ValidationService {
|
||||
}
|
||||
|
||||
public void checkIfUserInGroupJoin(Group group, User user) {
|
||||
if(!group.getMembers().contains(user)){
|
||||
if (group.getMembers().contains(user)) {
|
||||
throw new UserAlreadyExistsException("@details");
|
||||
}
|
||||
}
|
||||
@ -114,4 +115,24 @@ public class ValidationService {
|
||||
}
|
||||
return userList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft ob alle Felder richtig gesetzt sind.
|
||||
* @param description
|
||||
* @param title
|
||||
* @param userMaximum
|
||||
*/
|
||||
public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) {
|
||||
if (description == null) {
|
||||
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (title == null) {
|
||||
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (userMaximum == null && maxInfiniteUsers == null) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user