There cant be two bearbeitet entities in the db featuring the same cache and user

This commit is contained in:
Maximilian Leopold 2019-04-09 16:49:17 +02:00
parent 40661fb689
commit 283f56e02d
2 changed files with 9 additions and 1 deletions

View File

@ -126,7 +126,6 @@ public class Controller {
.setSigningKey(key)
.parseClaimsJws(token).getBody();
User user = userRepository.findByUsername(claims.getSubject());
if (user == null) {
return ResponseEntity.status(404).body("User was not found");
@ -136,6 +135,12 @@ public class Controller {
Optional<Cache> cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
if (cacheOptional.isPresent()) {
Cache cache = cacheOptional.get();
if(bearbeitetRepository.findByUserAndCache(user, cache) != null){
Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache);
return ResponseEntity.status(400).body(bearbeitet1.getAktuelleStation());
}
bearbeitet.setCache(cache);
Station startStation = cache.getStationen().get(0);

View File

@ -1,8 +1,11 @@
package hhn.labsw.bugageocaching.repositories;
import hhn.labsw.bugageocaching.entities.Bearbeitet;
import hhn.labsw.bugageocaching.entities.Cache;
import hhn.labsw.bugageocaching.entities.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
public interface BearbeitetRepository extends JpaRepository<Bearbeitet, Integer> {
Bearbeitet findByUserAndCache(User user, Cache cache);
}