Merge branch 'develop' of https://bitbucket-student.it.hs-heilbronn.de/scm/labswp19/labswp_2019_sose_geocaching into develop
This commit is contained in:
commit
d5e3bfc566
16
.idea/checkstyle-idea.xml
generated
Normal file
16
.idea/checkstyle-idea.xml
generated
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CheckStyle-IDEA">
|
||||
<option name="configuration">
|
||||
<map>
|
||||
<entry key="checkstyle-version" value="8.16" />
|
||||
<entry key="copy-libs" value="false" />
|
||||
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
|
||||
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
|
||||
<entry key="scan-before-checkin" value="false" />
|
||||
<entry key="scanscope" value="JavaOnly" />
|
||||
<entry key="suppress-errors" value="false" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel>
|
||||
<module name="de.hhn.labsw.BuGaGeocaching.main" target="1.8" />
|
||||
<module name="de.hhn.labsw.BuGaGeocaching.test" target="1.8" />
|
||||
<module name="de.hhn.labsw.labswp_2019_sose_geocaching.main" target="1.8" />
|
||||
<module name="de.hhn.labsw.labswp_2019_sose_geocaching.test" target="1.8" />
|
||||
<module name="labswp_2019_sose_geocaching.de.hhn.labsw.labswp_2019_sose_geocaching.main" target="1.8" />
|
||||
<module name="labswp_2019_sose_geocaching.de.hhn.labsw.labswp_2019_sose_geocaching.test" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/misc.xml
generated
Normal file
9
.idea/misc.xml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,13 +1,13 @@
|
||||
package hhn.labsw.bugageocaching.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import hhn.labsw.bugageocaching.repositories.CacheRepository;
|
||||
import hhn.labsw.bugageocaching.repositories.RewardRepository;
|
||||
import hhn.labsw.bugageocaching.repositories.StationRepository;
|
||||
import hhn.labsw.bugageocaching.entities.*;
|
||||
import hhn.labsw.bugageocaching.exceptions.IllegalParameterException;
|
||||
import hhn.labsw.bugageocaching.repositories.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
public class Controller {
|
||||
@ -21,10 +21,70 @@ public class Controller {
|
||||
@Autowired
|
||||
StationRepository stationRepository;
|
||||
|
||||
@RequestMapping("/allCaches")
|
||||
@Autowired
|
||||
BearbeitetRepository bearbeitetRepository;
|
||||
|
||||
@Autowired
|
||||
CacheAccesDefinitionRepository cacheAccesDefinitionRepository;
|
||||
|
||||
@Autowired
|
||||
TeamRepository teamRepository;
|
||||
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
|
||||
@RequestMapping("/api/allCaches")
|
||||
@ResponseBody
|
||||
public String getAllCaches(){
|
||||
public String getAllCaches() {
|
||||
return new Gson().toJson(cacheRepository.findAll());
|
||||
}
|
||||
|
||||
@RequestMapping("/api/startCache")
|
||||
public @ResponseBody
|
||||
String startCache(@RequestParam(value = "userID", defaultValue = "-1") String userID,
|
||||
@RequestParam String cacheID) throws IllegalParameterException {
|
||||
|
||||
if (!userID.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben)
|
||||
|
||||
Bearbeitet bearbeitet = new Bearbeitet();
|
||||
|
||||
Optional<User> userOptional = userRepository.findById(Integer.valueOf(userID));
|
||||
if (userOptional.isPresent()) {
|
||||
User user = userOptional.get();
|
||||
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);
|
||||
} 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);
|
||||
} else {
|
||||
throw new IllegalParameterException("There is no cacheAccesDefinition with the ID " + 1);
|
||||
}
|
||||
|
||||
bearbeitetRepository.save(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package hhn.labsw.bugageocaching.entities;
|
||||
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class Bearbeitet {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@OneToOne
|
||||
private User user;
|
||||
|
||||
@OneToOne
|
||||
private Cache cache;
|
||||
|
||||
@OneToOne
|
||||
private CacheAccesDefinition cacheAccesDefinition;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Cache getCache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void setCache(Cache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public CacheAccesDefinition getCacheAccesDefinition() {
|
||||
return cacheAccesDefinition;
|
||||
}
|
||||
|
||||
public void setCacheAccesDefinition(CacheAccesDefinition cacheAccesDefinition) {
|
||||
this.cacheAccesDefinition = cacheAccesDefinition;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package hhn.labsw.bugageocaching.entities;
|
||||
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class CacheAccesDefinition {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
private String description;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
41
src/main/java/hhn/labsw/bugageocaching/entities/Team.java
Normal file
41
src/main/java/hhn/labsw/bugageocaching/entities/Team.java
Normal file
@ -0,0 +1,41 @@
|
||||
package hhn.labsw.bugageocaching.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class Team {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
private int rankingPoints;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getRankingPoints() {
|
||||
return rankingPoints;
|
||||
}
|
||||
|
||||
public void setRankingPoints(int rankingPoints) {
|
||||
this.rankingPoints = rankingPoints;
|
||||
}
|
||||
}
|
||||
104
src/main/java/hhn/labsw/bugageocaching/entities/User.java
Normal file
104
src/main/java/hhn/labsw/bugageocaching/entities/User.java
Normal file
@ -0,0 +1,104 @@
|
||||
package hhn.labsw.bugageocaching.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String username;
|
||||
private int rankingPointsSum;
|
||||
private String discriminator; //should be Admin or Cacher
|
||||
private String email;
|
||||
private String password;
|
||||
private String salt;
|
||||
|
||||
@ManyToOne
|
||||
private Team team;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public int getRankingPointsSum() {
|
||||
return rankingPointsSum;
|
||||
}
|
||||
|
||||
public void setRankingPointsSum(int rankingPointsSum) {
|
||||
this.rankingPointsSum = rankingPointsSum;
|
||||
}
|
||||
|
||||
public String getDiscriminator() {
|
||||
return discriminator;
|
||||
}
|
||||
|
||||
public void setDiscriminator(String discriminator) {
|
||||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public Team getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
public void setTeam(Team team) {
|
||||
this.team = team;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.Bearbeitet;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface BearbeitetRepository extends CrudRepository<Bearbeitet, Integer> {
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.CacheAccesDefinition;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface CacheAccesDefinitionRepository extends CrudRepository<CacheAccesDefinition, Integer> {
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.Team;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface TeamRepository extends CrudRepository<Team, Integer> {
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.User;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user