Skip to content

Commit

Permalink
#218 Added logic to other related endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
loreV committed Jun 9, 2022
1 parent 184b657 commit a29e2dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TrailResponse addPlaceToTrail(@PathVariable String id,
errors.addAll(generalValidator.validate(placeRefDto));
if (errors.isEmpty()) {
final List<TrailDto> linkedPlaceResultDtos =
trailManager.linkTrailToPlace(id, placeRefDto);
trailService.linkTrailToPlace(id, placeRefDto);
return trailResponseHelper.constructResponse(errors, linkedPlaceResultDtos,
trailManager.count(),
ONE, ONE);
Expand All @@ -72,7 +72,7 @@ public TrailResponse removePlaceFromTrail(@PathVariable String id,
errors.addAll(generalValidator.validate(placeRefDto));
if (errors.isEmpty()) {
final List<TrailDto> linkedPlaceResultDtos =
trailManager.unlinkPlace(id, placeRefDto);
trailService.unlinkPlace(id, placeRefDto);
return trailResponseHelper.constructResponse(errors, linkedPlaceResultDtos,
trailManager.count(),
ONE, ONE);
Expand Down
1 change: 0 additions & 1 deletion backend/src/main/java/org/sc/manager/TrailManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class TrailManager @Autowired constructor(
}
}


fun unlinkPlace(id: String, placeRef: PlaceRefDto): List<TrailDto> {
val unLinkPlace = trailDAO.unLinkPlace(id, placeRefMapper.map(placeRef))
return unLinkPlace.map { trailMapper.map(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PlacesTrailSyncProcessor @Autowired constructor(private val trailManager:
}
}

private fun updateCrosswayNameWithTrailsPassingCodes(placeId: String) {
fun updateCrosswayNameWithTrailsPassingCodes(placeId: String) {
val placeList = placeManager.getById(placeId)
if(placeList.isEmpty()) throw IllegalStateException("Cannot update place name of a not-existing location")
val place = placeList.first()
Expand Down
14 changes: 14 additions & 0 deletions backend/src/main/java/org/sc/service/TrailService.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.sc.service

import org.sc.common.rest.PlaceRefDto
import org.sc.common.rest.TrailDto
import org.sc.data.mapper.TrailMapper
import org.sc.data.model.Trail
import org.sc.data.model.TrailStatus
import org.sc.manager.*
import org.sc.processor.PlacesTrailSyncProcessor
Expand Down Expand Up @@ -56,6 +58,18 @@ class TrailService @Autowired constructor(private val trailManager: TrailManager
return trailManager.update(trailMapper.map(trailToUpdate))
}

fun unlinkPlace(trailId: String,
placeRef: PlaceRefDto): List<TrailDto> {
val unLinkPlace = trailManager.unlinkPlace(trailId, placeRef)
if (placeRef.isDynamicCrossway)
placesTrailSyncProcessor.updateCrosswayNameWithTrailsPassingCodes(placeRef.placeId)
return unLinkPlace
}

fun linkTrailToPlace(id: String, placeRefDto: PlaceRefDto): List<TrailDto> {
TODO("Not yet implemented")
}

private fun isSwitchingToDraft(
trailDto: TrailDto,
trailToUpdate: TrailDto
Expand Down

0 comments on commit a29e2dc

Please sign in to comment.