Skip to content

Commit

Permalink
Merge pull request #128 from 12urenloop/remove-code
Browse files Browse the repository at this point in the history
Remove some template code
  • Loading branch information
FKD13 authored Mar 29, 2024
2 parents 3a1953b + 7bd44a4 commit a61799e
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 228 deletions.
2 changes: 2 additions & 0 deletions src/main/java/telraam/api/AbstractListableResource.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package telraam.api;


import io.swagger.v3.oas.annotations.Operation;
import telraam.database.daos.DAO;

import java.util.List;
Expand All @@ -11,6 +12,7 @@ protected AbstractListableResource(DAO<T> dao) {
}

@Override
@Operation(summary = "Find all")
public List<T> getListOf() {
return dao.getAll();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/telraam/api/AbstractResource.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package telraam.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import org.checkerframework.checker.units.qual.C;
import telraam.database.daos.DAO;

import java.util.Optional;
Expand All @@ -19,12 +21,14 @@ protected AbstractResource(DAO<T> dao) {
}

@Override
@Operation(summary = "Add new to the database")
// TODO Validate model and return 405 for wrong input
public int create(@Parameter(required = true) T t) {
return dao.insert(t);
}

@Override
@Operation(summary = "Find by ID")
@ApiResponse(responseCode = "400", description = "Invalid or no ID supplied") // TODO validate ID, return 400 on wrong ID format
@ApiResponse(responseCode = "404", description = "Entity with specified ID not found")
public T get(@Parameter(description = "ID of entity that needs to be fetched", required = true) Optional<Integer> id) {
Expand All @@ -41,6 +45,7 @@ public T get(@Parameter(description = "ID of entity that needs to be fetched", r
}

@Override
@Operation(summary = "Update an existing")
@ApiResponse(responseCode = "400", description = "Invalid or no ID supplied") // TODO validate ID, return 400 on wrong ID format
@ApiResponse(responseCode = "404", description = "Entity with specified ID not found")
@ApiResponse(responseCode = "405", description = "Validation exception") // TODO validate input, 405 on wrong input
Expand All @@ -60,6 +65,7 @@ public T update(@Parameter(description = "Entity object that needs to be updated
}

@Override
@Operation(summary = "Delete an existing")
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "Invalid or no ID supplied"), // TODO validate ID, return 400 on wrong ID format
})
Expand Down
38 changes: 2 additions & 36 deletions src/main/java/telraam/api/BatonResource.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,18 @@
package telraam.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import telraam.database.daos.BatonDAO;
import telraam.database.daos.DAO;
import telraam.database.models.Baton;

import java.util.List;
import java.util.Optional;

@Path("/baton") // dropwizard
@Tag(name = "Baton")
@Produces(MediaType.APPLICATION_JSON)
public class BatonResource extends AbstractListableResource<Baton> {
public BatonResource(BatonDAO dao) {
public BatonResource(DAO<Baton> dao) {
super(dao);
}

@Override
@Operation(summary = "Find all batons")
public List<Baton> getListOf() {
return super.getListOf();
}

@Override
@Operation(summary = "Add a new baton to the database")
public int create(Baton baton) {
return super.create(baton);
}

@Override
@Operation(summary = "Find baton by ID")
public Baton get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Update an existing baton")
public Baton update(Baton baton, Optional<Integer> id) {
return super.update(baton, id);
}

@Override
@Operation(summary = "Delete an existing baton")
public boolean delete(Optional<Integer> id) {
return super.delete(id);
}
}

24 changes: 1 addition & 23 deletions src/main/java/telraam/api/BatonSwitchoverResource.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
package telraam.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import telraam.database.daos.BatonSwitchoverDAO;
import telraam.database.models.BatonSwitchover;

import java.util.List;
import java.util.Optional;

@Path("/batonswitchover") // dropwizard
@Tag(name="Baton Switchover")
@Tag(name = "Baton Switchover")
@Produces(MediaType.APPLICATION_JSON)
public class BatonSwitchoverResource extends AbstractListableResource<BatonSwitchover> {
public BatonSwitchoverResource(BatonSwitchoverDAO dao) {
super(dao);
}

@Override
@Operation(summary = "Find all baton switchovers")
public List<BatonSwitchover> getListOf() {
return super.getListOf();
}

@Override
@Operation(summary = "Find baton switchover by ID")
public BatonSwitchover get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Add a new baton switchover to the database")
public int create(BatonSwitchover batonSwitchover) {
return super.create(batonSwitchover);
}
}

30 changes: 0 additions & 30 deletions src/main/java/telraam/api/DetectionResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,6 @@ public DetectionResource(DetectionDAO dao) {
detectionDAO = dao;
}

@Override
@Operation(summary = "Find all detections")
public List<Detection> getListOf() {
return super.getListOf();
}

@Override
@Operation(summary = "Add a new detection to the database")
public int create(Detection detection) {
return super.create(detection);
}

@Override
@Operation(summary = "Find detection by ID")
public Detection get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Update an existing detection")
public Detection update(Detection detection, Optional<Integer> id) {
return super.update(detection, id);
}

@Override
@Operation(summary = "Delete an existing detection")
public boolean delete(Optional<Integer> id) {
return super.delete(id);
}

@GET
@Path("/since/{id}")
@Operation(summary = "Get detections with ID larger than given ID")
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/telraam/api/LapResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,4 @@ public List<Lap> getListOf(@QueryParam("source") final Integer source) {
return lapDAO.getAllBySource(source);
}
}

@Override
@Operation(summary = "Add a new lap to the database")
public int create(Lap lap) {
return super.create(lap);
}

@Override
@Operation(summary = "Find lap by ID")
public Lap get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Update an existing lap")
public Lap update(Lap lap, Optional<Integer> id) {
return super.update(lap, id);
}

@Override
@Operation(summary = "Delete an existing lap")
public boolean delete(Optional<Integer> id) {
return super.delete(id);
}
}
37 changes: 2 additions & 35 deletions src/main/java/telraam/api/LapSourceResource.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
package telraam.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import telraam.database.daos.DAO;
import telraam.database.models.LapSource;

import java.util.List;
import java.util.Optional;

@Path("/lap-source")
@Tag(name = "Lap Source")
@Produces(MediaType.APPLICATION_JSON)
public class LapSourceResource extends AbstractListableResource<LapSource> {
public LapSourceResource(DAO<LapSource> dao) {
super(dao);
}

@Override
@Operation(summary = "Find all lap sources")
public List<LapSource> getListOf() {
return super.getListOf();
}

@Override
@Operation(summary = "Add a new lap source to the database")
public int create(LapSource lapSource) {
return super.create(lapSource);
}

@Override
@Operation(summary = "Find lap source by ID")
public LapSource get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Update an existing lap source")
public LapSource update(LapSource lapSource, Optional<Integer> id) {
return super.update(lapSource, id);
}

@Override
@Operation(summary = "Delete an existing lap source")
public boolean delete(Optional<Integer> id) {
return super.delete(id);
}
}
27 changes: 3 additions & 24 deletions src/main/java/telraam/api/LapSourceSwitchoverResource.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
package telraam.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import telraam.database.daos.LapSourceSwitchoverDAO;
import telraam.database.models.LapSourceSwitchover;

import java.util.List;
import java.util.Optional;

@Path("/lapsourceswitchover") // dropwizard
@Tag(name="Lap Source Switchover")
@Tag(name = "Lap Source Switchover")
@Produces(MediaType.APPLICATION_JSON)
public class LapSourceSwitchoverResource extends AbstractListableResource<LapSourceSwitchover> {
public LapSourceSwitchoverResource(LapSourceSwitchoverDAO dao) {
super(dao);
}

@Override
@Operation(summary = "Find all lap source switchovers")
public List<LapSourceSwitchover> getListOf() {
return super.getListOf();
}

@Override
@Operation(summary = "Find lap source switchover by ID")
public LapSourceSwitchover get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Add a new lap source switchover to the database")
public int create(LapSourceSwitchover lapSourceSwitchover) {
return super.create(lapSourceSwitchover);
}
}

40 changes: 3 additions & 37 deletions src/main/java/telraam/api/StationResource.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,17 @@
package telraam.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import telraam.database.daos.DAO;
import telraam.database.models.Station;

import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
import java.util.Optional;

@Path("/station")
@Tag(name="Station")
@Tag(name = "Station")
@Produces(MediaType.APPLICATION_JSON)
public class StationResource extends AbstractListableResource<Station> {
public StationResource(DAO<Station> dao) {
super(dao);
}

@Override
@Operation(summary = "Find all stations")
public List<Station> getListOf() {
return super.getListOf();
}

@Override
@Operation(summary = "Add a new station to the database")
public int create(Station station) {
return super.create(station);
}

@Override
@Operation(summary = "Find station by ID")
public Station get(Optional<Integer> id) {
return super.get(id);
}

@Override
@Operation(summary = "Update an existing station")
public Station update(Station station, Optional<Integer> id) {
return super.update(station, id);
}

@Override
@Operation(summary = "Delete an existing station")
public boolean delete(Optional<Integer> id) {
return super.delete(id);
}
}
Loading

0 comments on commit a61799e

Please sign in to comment.