Can now remove tags from images
This commit is contained in:
parent
a78bea1167
commit
1bce01e07e
@ -38,8 +38,16 @@ class BaseController
|
|||||||
if (logout != null) model.addAttribute("message", "You have been logged out successfully.")
|
if (logout != null) model.addAttribute("message", "You have been logged out successfully.")
|
||||||
return "login"
|
return "login"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/view/{id}")
|
@Controller
|
||||||
|
@RequestMapping("/view/{id}")
|
||||||
|
class SingleImageViewController
|
||||||
|
@Autowired constructor(
|
||||||
|
val imageRepository: ImageRepository,
|
||||||
|
val tagRepository: TagRepository
|
||||||
|
){
|
||||||
|
@GetMapping
|
||||||
fun viewSingleImage(@PathVariable id: Long, model: Model, @AuthenticationPrincipal userDetails: CustomUserDetails?) : String {
|
fun viewSingleImage(@PathVariable id: Long, model: Model, @AuthenticationPrincipal userDetails: CustomUserDetails?) : String {
|
||||||
val image = imageRepository.findById(id).get()
|
val image = imageRepository.findById(id).get()
|
||||||
val tagData = image.tags.sortedBy { it.tag }
|
val tagData = image.tags.sortedBy { it.tag }
|
||||||
@ -49,6 +57,21 @@ class BaseController
|
|||||||
model.addAttribute("isUploader", (userDetails != null && (userDetails.authorities.any { it.authority == "ADMIN" } || userDetails.getId() == image.uploader.id)))
|
model.addAttribute("isUploader", (userDetails != null && (userDetails.authorities.any { it.authority == "ADMIN" } || userDetails.getId() == image.uploader.id)))
|
||||||
return "single"
|
return "single"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/removetag")
|
||||||
|
@Transactional
|
||||||
|
fun removeTagFromImage(@PathVariable id: Long, @RequestParam("tagId") tagID: Long, model: Model, @AuthenticationPrincipal userDetails: CustomUserDetails?) : String {
|
||||||
|
val image = imageRepository.findById(id).get()
|
||||||
|
if(userDetails == null || userDetails.getId() != image.uploader.id || !userDetails.authorities.any { it.authority == "ADMIN" }) return "redirect:/view/$id"
|
||||||
|
val targetTag = image.tags.find { it.id == tagID }
|
||||||
|
if(targetTag != null){
|
||||||
|
targetTag.amount -= 1
|
||||||
|
tagRepository.save(targetTag)
|
||||||
|
image.tags.remove(targetTag)
|
||||||
|
imageRepository.save(image)
|
||||||
|
}
|
||||||
|
return "redirect:/view/$id"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -14,7 +14,12 @@
|
|||||||
<li th:each="tag : ${tags}">
|
<li th:each="tag : ${tags}">
|
||||||
<a class="text-decoration-none"
|
<a class="text-decoration-none"
|
||||||
th:href="${#mvc.url('IC#getGalleryPage').arg(1, tag.tag).build()}"
|
th:href="${#mvc.url('IC#getGalleryPage').arg(1, tag.tag).build()}"
|
||||||
th:text="${tag.tag} + ' '">tag</a><span th:text="${tag.amount}"></span></li>
|
th:text="${tag.tag} + ' '">tag</a><span th:text="${tag.amount}"></span>
|
||||||
|
<form th:action="${'/view/' + image.id + '/removetag'}" method="post" th:if="${isUploader}">
|
||||||
|
<input type="hidden" th:value="${tag.id}" name="tagId">
|
||||||
|
<button type="submit">-</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Uploaded by: <span th:text="${image.uploader.name}"></span></p>
|
<p>Uploaded by: <span th:text="${image.uploader.name}"></span></p>
|
||||||
<form th:action="'/upload/d/' + ${image.id}"
|
<form th:action="'/upload/d/' + ${image.id}"
|
||||||
|
Loading…
Reference in New Issue
Block a user