Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed RouteFollowed backend relation with Route #37

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public class RouteFollowed extends UriEntity<Long> {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@NotNull
@ManyToOne
public Route routeOrigin;
public Route follows;

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void handleRouteFollowedPreCreate(RouteFollowed routeFollowed) {
routeFollowed.setCreatedBy(user);
List<Route> routeList = routeRepository.findByCreatedBy(user);
if(!routeList.isEmpty())
routeFollowed.setRouteOrigin(routeList.get(0));
routeFollowed.setFollows(routeList.get(0));
routeFollowed.setDate(ZonedDateTime.now());
logger.info("Creation of new routeFollowed: {}", routeFollowed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public interface RouteFollowedRepository extends CrudRepository<RouteFollowed, Long>, PagingAndSortingRepository<RouteFollowed, Long> {
List<RouteFollowed> findByIdContaining(@Param("long") Long id);
List<Route> findByCreatedBy(@Param("creator") User creator);
List<User> findByRouteOrigin(@Param("origin") Route origin);
List<RouteFollowed> findByCreatedByAndRouteOrigin(@Param("creator") User creator, @Param("origin") Route origin);
List<String> findByCreatedBy(@Param("creator") User creator);
List<User> findByFollows(@Param("follows") Route follows);
List<RouteFollowed> findByCreatedByAndFollows(@Param("creator") User creator, @Param("follows") Route follows);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import cat.udl.eps.softarch.myroutes.repository.RouteFollowedRepository;
import cat.udl.eps.softarch.myroutes.repository.RouteRepository;
import cat.udl.eps.softarch.myroutes.repository.UserRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
Expand Down Expand Up @@ -39,7 +38,7 @@ public void iCreateARouteFollowedWithDateDurationLevelUpAndALevelDown(String dat
Iterable<User> usersList = userRepository.findAll();
Route route = routesList.iterator().next();
User user = usersList.iterator().next();
routeFollowed.setRouteOrigin(route);
routeFollowed.setFollows(route);
routeFollowed.setCreatedBy(user);
stepDefs.result = stepDefs.mockMvc.perform(
post("/routeFolloweds")
Expand All @@ -60,7 +59,7 @@ public void iDonTHaveAnyRouteFollowed() {
public void thereIsARouteFollowedWithDateDurationLevelUpAndALevelDownByUserUsernameAndRouteTitle(String date, String duration, String levelUp, String levelDown, String user, String route) {
RouteFollowed routeFollowed = RouteFollowedUtil.buildRoute(date,duration,levelUp,levelDown);
routeFollowed.setCreatedBy(userRepository.findById(user).get());
routeFollowed.setRouteOrigin(routeRepository.findByTitle(route).get(0));
routeFollowed.setFollows(routeRepository.findByTitle(route).get(0));
routeFollowedRepository.save(routeFollowed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import cat.udl.eps.softarch.myroutes.domain.Route;
import cat.udl.eps.softarch.myroutes.domain.RouteFollowed;
import cat.udl.eps.softarch.myroutes.domain.User;
import cat.udl.eps.softarch.myroutes.domain.Waypoint;
import cat.udl.eps.softarch.myroutes.repository.RouteFollowedRepository;
import cat.udl.eps.softarch.myroutes.repository.RouteRepository;
import cat.udl.eps.softarch.myroutes.repository.UserRepository;
import io.cucumber.java.en.When;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;

import java.util.Optional;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

public class RetrieveRouteFollowedStepDefs {
Expand All @@ -37,15 +34,4 @@ public void iTryToRetrieveARouteFollowedWithUserAndRoute(String userId, String r
.with(AuthenticationStepDefs.authenticate())
.accept(MediaType.APPLICATION_JSON));
}

@When("I try to retrieve a routeFollowed with user {string} and route {string}")
public void iTryToRetrieveAWaypointWithUserAndRoute(String userId, String routeTitle) throws Throwable {
Route route = RouteUtil.getRouteByTitle(routeRepository,routeTitle);
User user = userRepository.findById(userId).get();
Optional<RouteFollowed> optionalRouteFollowed = Optional.ofNullable(RouteFollowedUtil.getRouteFollowed(routeFollowedRepository, route, user));
stepDefs.result = stepDefs.mockMvc.perform(
get("/waypoints/{id}", optionalRouteFollowed.isPresent() ? optionalRouteFollowed.get().getId() : "999")
.with(AuthenticationStepDefs.authenticate())
.accept(MediaType.APPLICATION_JSON));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
import cat.udl.eps.softarch.myroutes.domain.RouteFollowed;
import cat.udl.eps.softarch.myroutes.domain.User;
import cat.udl.eps.softarch.myroutes.repository.RouteFollowedRepository;
import cat.udl.eps.softarch.myroutes.repository.RouteRepository;
import cat.udl.eps.softarch.myroutes.repository.UserRepository;

import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;

public class RouteFollowedUtil {
public static RouteFollowed buildRoute(String date, String duration, String levelUp, String levelDown){
RouteFollowed route = new RouteFollowed();
RouteFollowed route;
route = setValuesToRoute(new RouteFollowed(),date, duration, levelUp, levelDown);
return route;
}
Expand Down Expand Up @@ -43,7 +40,7 @@ public static RouteFollowed getRouteFollowed(RouteFollowedRepository rfRepo, Lon


public static RouteFollowed getRouteFollowed(RouteFollowedRepository rfRepo, Route route, User user){
List<RouteFollowed> routeFollowedList = rfRepo.findByCreatedByAndRouteOrigin(user, route);
List<RouteFollowed> routeFollowedList = rfRepo.findByCreatedByAndFollows(user, route);
if(routeFollowedList.isEmpty())
return new RouteFollowed();
return routeFollowedList.get(0);
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/features/RetrieveRouteFollowed.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ Feature: Retrieve RouteFollowed
When I try to retrieve a RouteFollowed with user "user" and route "testRoute"
Then The response code is 200

Scenario: Get a RouteFollowed which does not exist
Given I login as "user" with password "password"
When I try to retrieve a routeFollowed with user "user" and route "testRoute2"
Then The response code is 404

Loading