Skip to content

Commit

Permalink
Changed RouteOrigin to Follows and changed type back to Route instead…
Browse files Browse the repository at this point in the history
… of String
  • Loading branch information
SergiFn committed Dec 21, 2023
1 parent 8220865 commit cd42bc5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class RouteFollowed extends UriEntity<Long> {

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@NotNull
public String follows;
@ManyToOne
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.setFollows(routeList.get(0).getUri());
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
@@ -1,5 +1,6 @@
package cat.udl.eps.softarch.myroutes.repository;

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 org.springframework.data.repository.CrudRepository;
Expand All @@ -11,6 +12,6 @@
public interface RouteFollowedRepository extends CrudRepository<RouteFollowed, Long>, PagingAndSortingRepository<RouteFollowed, Long> {
List<RouteFollowed> findByIdContaining(@Param("long") Long id);
List<String> findByCreatedBy(@Param("creator") User creator);
List<User> findByFollows(@Param("follows") String follows);
List<RouteFollowed> findByCreatedByAndFollows(@Param("creator") User creator, @Param("follows") String follows);
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 @@ -38,7 +38,7 @@ public void iCreateARouteFollowedWithDateDurationLevelUpAndALevelDown(String dat
Iterable<User> usersList = userRepository.findAll();
Route route = routesList.iterator().next();
User user = usersList.iterator().next();
routeFollowed.setFollows(route.getUri());
routeFollowed.setFollows(route);
routeFollowed.setCreatedBy(user);
stepDefs.result = stepDefs.mockMvc.perform(
post("/routeFolloweds")
Expand All @@ -59,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.setFollows(routeRepository.findByTitle(route).get(0).getUri());
routeFollowed.setFollows(routeRepository.findByTitle(route).get(0));
routeFollowedRepository.save(routeFollowed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static RouteFollowed getRouteFollowed(RouteFollowedRepository rfRepo, Lon


public static RouteFollowed getRouteFollowed(RouteFollowedRepository rfRepo, Route route, User user){
List<RouteFollowed> routeFollowedList = rfRepo.findByCreatedByAndFollows(user, route.getUri());
List<RouteFollowed> routeFollowedList = rfRepo.findByCreatedByAndFollows(user, route);
if(routeFollowedList.isEmpty())
return new RouteFollowed();
return routeFollowedList.get(0);
Expand Down

0 comments on commit cd42bc5

Please sign in to comment.