mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2025-12-22 14:41:57 +00:00
various updates
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -4,7 +4,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
17
.run/TimekeepBackendApplication.run.xml
Normal file
17
.run/TimekeepBackendApplication.run.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TimekeepBackendApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
|
||||
<module name="timekeep-backend.main" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="de.pnreichmuth.timekeep_backend.TimekeepBackendApplication" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="de.pnreichmuth.timekeep_backend.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="resources/compose.yaml: Compose Deployment" run_configuration_type="docker-deploy" />
|
||||
<option name="Make" enabled="true" />
|
||||
<option name="ToolBeforeRunTask" enabled="true" actionId="Tool_External Tools_delay 2s" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -36,11 +36,11 @@ publishing {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>() {
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType<Javadoc>() {
|
||||
tasks.withType<Javadoc> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,42 @@
|
||||
package de.pnreichmuth.timekeep_backend.controllers;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import de.pnreichmuth.timekeep_backend.repositories.TeamRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import de.pnreichmuth.timekeep_backend.services.TeamService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.rmi.NoSuchObjectException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/teams")
|
||||
@Slf4j
|
||||
public class TeamRestController {
|
||||
@Autowired
|
||||
private TeamRepository teamRepository;
|
||||
|
||||
TeamService teamService;
|
||||
@PostMapping("createTeam")
|
||||
public Team createTeam(){
|
||||
Team team = new Team();
|
||||
teamRepository.save(team);
|
||||
public Team createTeam(@RequestBody Team team){
|
||||
teamService.createTeam(team);
|
||||
return team;
|
||||
}
|
||||
|
||||
@GetMapping("all")
|
||||
public List<Team> findAllTeams(){
|
||||
return teamRepository.findAll();
|
||||
return teamService.getTeams();
|
||||
}
|
||||
|
||||
@DeleteMapping("all")
|
||||
public void deleteAllTeams(){
|
||||
teamRepository.deleteAll();
|
||||
teamService.deleteAllTeams();
|
||||
}
|
||||
|
||||
@DeleteMapping("deleteTeam")
|
||||
public void deleteTeam(@RequestBody Team team){
|
||||
try{
|
||||
teamService.deleteTeam(team.getTeamName());
|
||||
} catch (NoSuchObjectException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import lombok.Setter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package de.pnreichmuth.timekeep_backend.repositories;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Racer;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Repository
|
||||
public interface RacerRepository extends JpaRepository<Racer, UUID> {
|
||||
public interface RacerRepository extends JpaRepository<@NonNull Racer,@NonNull UUID> {
|
||||
Racer findByName(String name);
|
||||
List<Racer> findAllByName(String name);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package de.pnreichmuth.timekeep_backend.repositories;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Station;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface StationRepository extends JpaRepository<Station, UUID> {
|
||||
public Station findByLocation(String location);
|
||||
public Station findByName(String name);
|
||||
public Station findByPasswordHash(String passwordHash);
|
||||
public interface StationRepository extends JpaRepository<@NonNull Station, @NonNull UUID> {
|
||||
Station findByLocation(String location);
|
||||
Station findByName(String name);
|
||||
Station findByPasswordHash(String passwordHash);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.pnreichmuth.timekeep_backend.repositories;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Station;
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -9,9 +10,11 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface TeamRepository extends JpaRepository<Team, UUID> {
|
||||
Team getTeamById(UUID id);
|
||||
public interface TeamRepository extends JpaRepository<@NonNull Team, @NonNull UUID> {
|
||||
Team getTeamByTeamName(String name);
|
||||
List<Team> getTeamsByFirstSemesterTeamIsTrue();
|
||||
List<Team> getTeamsByPassedStationsContains(Station station);
|
||||
void deleteTeamByTeamName(String name);
|
||||
|
||||
boolean existsByTeamName(String name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package de.pnreichmuth.timekeep_backend.services;
|
||||
|
||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||
import de.pnreichmuth.timekeep_backend.repositories.TeamRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.rmi.NoSuchObjectException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("LoggingSimilarMessage")
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TeamService {
|
||||
private final TeamRepository teamRepository;
|
||||
|
||||
public Team getTeam(UUID id){
|
||||
return teamRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Team getTeam(String name){
|
||||
return teamRepository.getTeamByTeamName(name);
|
||||
}
|
||||
|
||||
public List<Team> getTeams(){
|
||||
return teamRepository.findAll();
|
||||
}
|
||||
|
||||
public void createTeam(){
|
||||
Team team = new Team();
|
||||
teamRepository.save(team);
|
||||
log.info("Team created: {}", team);
|
||||
}
|
||||
|
||||
public void createTeam(Team team){
|
||||
teamRepository.save(team);
|
||||
log.info("Team created: {}", team);
|
||||
}
|
||||
|
||||
public void createTeam(String name){
|
||||
Team tempTeam = new Team();
|
||||
tempTeam.setTeamName(name);
|
||||
teamRepository.save(tempTeam);
|
||||
log.info("Team created: {}", tempTeam);
|
||||
}
|
||||
|
||||
public void deleteTeam(UUID id) throws NoSuchObjectException{
|
||||
if(!teamRepository.existsById(id)) throw new NoSuchObjectException("Team not found");
|
||||
teamRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public void deleteTeam(String name) throws NoSuchObjectException{
|
||||
if(!teamRepository.existsByTeamName(name)) throw new NoSuchObjectException("Team not found");
|
||||
teamRepository.deleteTeamByTeamName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* DANGER ZONE
|
||||
*/
|
||||
public void deleteAllTeams(){
|
||||
teamRepository.deleteAll();
|
||||
log.warn("All teams deleted. Database is now empty.");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.pnreichmuth.timekeep_backend;
|
||||
package de.pnreichmuth.timekeep_backend.spring_configs;
|
||||
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
@@ -1,13 +1,8 @@
|
||||
package de.pnreichmuth.timekeep_backend;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class TimekeepBackendApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user