Merge branch 'develop' into backend/max
This commit is contained in:
commit
22bf31bfe8
@ -2,6 +2,7 @@ package hhn.labsw.bugageocaching.controller;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import hhn.labsw.bugageocaching.entities.*;
|
import hhn.labsw.bugageocaching.entities.*;
|
||||||
|
import hhn.labsw.bugageocaching.exceptions.IllegalParameterException;
|
||||||
import hhn.labsw.bugageocaching.repositories.*;
|
import hhn.labsw.bugageocaching.repositories.*;
|
||||||
import hhn.labsw.bugageocaching.service.SecurityService;
|
import hhn.labsw.bugageocaching.service.SecurityService;
|
||||||
import hhn.labsw.bugageocaching.service.UserService;
|
import hhn.labsw.bugageocaching.service.UserService;
|
||||||
@ -54,28 +55,51 @@ public class Controller {
|
|||||||
|
|
||||||
@RequestMapping("/startCache")
|
@RequestMapping("/startCache")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
Bearbeitet startCache(@RequestParam String userID,
|
String startCache(@RequestParam(value = "userID", defaultValue = "-1") String userID,
|
||||||
@RequestParam String cacheID,
|
@RequestParam String cacheID) throws IllegalParameterException {
|
||||||
@RequestParam String cacheAccesDefinitionID) {
|
|
||||||
|
|
||||||
Optional<User> userOptional = userRepository.findById(Integer.valueOf(userID));
|
if (!userID.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben)
|
||||||
User user = userOptional.get();
|
|
||||||
|
|
||||||
Optional<Cache> cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
|
|
||||||
Cache cache = cacheOptional.get();
|
|
||||||
|
|
||||||
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional =
|
|
||||||
cacheAccesDefinitionRepository.findById(Integer.valueOf(cacheAccesDefinitionID));
|
|
||||||
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
|
||||||
|
|
||||||
Bearbeitet bearbeitet = new Bearbeitet();
|
Bearbeitet bearbeitet = new Bearbeitet();
|
||||||
|
|
||||||
|
Optional<User> userOptional = userRepository.findById(Integer.valueOf(userID));
|
||||||
|
if (userOptional.isPresent()) {
|
||||||
|
User user = userOptional.get();
|
||||||
bearbeitet.setUser(user);
|
bearbeitet.setUser(user);
|
||||||
|
} else {
|
||||||
|
throw new IllegalParameterException("There is no user with the ID " + userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Cache> cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
|
||||||
|
if (cacheOptional.isPresent()) {
|
||||||
|
Cache cache = cacheOptional.get();
|
||||||
bearbeitet.setCache(cache);
|
bearbeitet.setCache(cache);
|
||||||
|
} else {
|
||||||
|
throw new IllegalParameterException( "There is no cache with the ID " + cacheID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional =
|
||||||
|
cacheAccesDefinitionRepository.findById(1); // bearbeitet
|
||||||
|
if (cacheAccesDefinitionOptional.isPresent()) {
|
||||||
|
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
||||||
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
||||||
|
} else {
|
||||||
|
throw new IllegalParameterException("There is no cacheAccesDefinition with the ID " + 1);
|
||||||
|
}
|
||||||
|
|
||||||
bearbeitetRepository.save(bearbeitet);
|
bearbeitetRepository.save(bearbeitet);
|
||||||
|
|
||||||
return bearbeitet;
|
return new Gson().toJson(bearbeitet);
|
||||||
|
|
||||||
|
} else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben)
|
||||||
|
Optional<Cache> cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
|
||||||
|
if (cacheOptional.isPresent()) {
|
||||||
|
Cache cache = cacheOptional.get();
|
||||||
|
return new Gson().toJson(cache);
|
||||||
|
} else {
|
||||||
|
throw new IllegalParameterException( "There is no cache with the ID " + cacheID);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/securityCheck")
|
@RequestMapping("/securityCheck")
|
||||||
|
|||||||
@ -0,0 +1,65 @@
|
|||||||
|
package hhn.labsw.bugageocaching.exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown to indicate that a method has been passed an illegal or inappropriate argument.
|
||||||
|
* This matches the IllegalArgumentException, but is no RuntimeException. This forces the
|
||||||
|
* developer to catch it.
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
public class IllegalParameterException extends Exception {
|
||||||
|
/**
|
||||||
|
* Constructs a new exception with {@code null} as its detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public IllegalParameterException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new exception with the specified detail message. The
|
||||||
|
* cause is not initialized, and may subsequently be initialized by
|
||||||
|
* a call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public IllegalParameterException(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new exception with the specified detail message and
|
||||||
|
* cause. <p>Note that the detail message associated with
|
||||||
|
* {@code cause} is <i>not</i> automatically incorporated in
|
||||||
|
* this exception's detail message.
|
||||||
|
*
|
||||||
|
* @param message the detail message (which is saved for later retrieval
|
||||||
|
* by the {@link #getMessage()} method).
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
|
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||||
|
* permitted, and indicates that the cause is nonexistent or
|
||||||
|
* unknown.)
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public IllegalParameterException(final String message, final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new exception with the specified cause and a detail
|
||||||
|
* message of <tt>(cause==null ? null : cause.toString())</tt> (which
|
||||||
|
* typically contains the class and detail message of <tt>cause</tt>).
|
||||||
|
* This constructor is useful for exceptions that are little more than
|
||||||
|
* wrappers for other throwables.
|
||||||
|
*
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
|
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||||
|
* permitted, and indicates that the cause is nonexistent or
|
||||||
|
* unknown.)
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public IllegalParameterException(final Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user