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

43 events gallery of photos #203

Merged
merged 41 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6885bee
Adding gallery to event model and simple service methods
AvilaAndre Sep 16, 2023
6eca9e9
Uploading image
AvilaAndre Sep 26, 2023
d6a1f3d
removed code added by accident
AvilaAndre Oct 17, 2023
0e67a81
Changed galery image folder
AvilaAndre Oct 17, 2023
28c58f1
Created addPhoto test
AvilaAndre Oct 17, 2023
3f061dc
fixed photoUrl type and added errors when event/photo doesn't exist
AvilaAndre Oct 18, 2023
a8b0c9e
test photo add if event does not exist
AvilaAndre Oct 23, 2023
e2262dd
test photo add wrong image format test
AvilaAndre Oct 23, 2023
8a2f4b9
Remove photo from gallery test
AvilaAndre Oct 23, 2023
79ee8f1
gallery photo remove from unexistent event test
AvilaAndre Oct 23, 2023
c8d19ef
gallery remove unexistent photo test
AvilaAndre Oct 23, 2023
4b0634f
generalized gallery to activity
AvilaAndre Jan 30, 2024
50acea5
Move gallery service methods from Event to Activity
AvilaAndre Feb 4, 2024
91f0ea6
Merge branch 'develop' into 43-events-gallery-of-photos
AvilaAndre Feb 6, 2024
91ace92
added gallery to develop tests
AvilaAndre Feb 6, 2024
a3516e7
added gallery documentation to activity payload
AvilaAndre Feb 6, 2024
cd6f37f
Update src/main/kotlin/pt/up/fe/ni/website/backend/model/Activity.kt
AvilaAndre Mar 28, 2024
971b2c0
Added missing import
AvilaAndre Mar 28, 2024
6b3e978
Formatted imports
AvilaAndre Mar 28, 2024
c6f4c3c
Removed unnnecessary code
AvilaAndre Mar 28, 2024
31d5a4b
Replaced photo with image
AvilaAndre Mar 28, 2024
8639688
added image folder to gallery
AvilaAndre Mar 28, 2024
1863c6f
Updated gallery documentation
AvilaAndre Mar 28, 2024
250bb18
Fixing tests failing after changes
AvilaAndre Mar 29, 2024
dd4818b
replace endpoints to be restful and add delete method to testing
AvilaAndre Jul 20, 2024
1b664c1
generalized image to file
AvilaAndre Jul 20, 2024
02ced4e
added file deletion to FileUploader class and delete files on removal
AvilaAndre Jul 21, 2024
26df8a7
feat: serve static files on the /static/ path
AvilaAndre Oct 18, 2024
7d42ee7
tweak: change static port from 3000 to 8080 for development
AvilaAndre Oct 18, 2024
95f4a50
Merge branch 'develop' into 43-events-gallery-of-photos
AvilaAndre Oct 18, 2024
0c68988
fix: add gallery list to Auth test
AvilaAndre Oct 18, 2024
02f45a9
lint: line too long
AvilaAndre Oct 18, 2024
693afa8
Update src/main/kotlin/pt/up/fe/ni/website/backend/service/activity/A…
AvilaAndre Nov 6, 2024
c796bac
Update src/test/kotlin/pt/up/fe/ni/website/backend/utils/mockmvc/Mock…
AvilaAndre Nov 6, 2024
0b5c228
fix: Added explanation to line and replaced variable
AvilaAndre Nov 6, 2024
2735fdc
lint: missing space
AvilaAndre Nov 6, 2024
12d6616
docs: started documentation while #144 is not done
AvilaAndre Nov 6, 2024
2322b14
test: added gallery tests to Project
AvilaAndre Nov 6, 2024
aeef473
refactor: make slug non optional
AvilaAndre Nov 7, 2024
2f26ff6
Merge branch 'develop' into 43-events-gallery-of-photos
AvilaAndre Nov 7, 2024
88e915d
Merge branch 'develop' into 43-events-gallery-of-photos
MRita443 Nov 20, 2024
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 @@ -74,4 +74,18 @@ class EventController(private val service: EventService) {
@PathVariable idEvent: Long,
@PathVariable idAccount: Long
) = service.removeTeamMemberById(idEvent, idAccount)

@PutMapping("/{idEvent}/gallery/addPhoto", consumes = ["multipart/form-data"])
AvilaAndre marked this conversation as resolved.
Show resolved Hide resolved
fun addGalleryPhoto(
@PathVariable idEvent: Long,
@RequestParam
@ValidImage
image: MultipartFile
) = service.addGalleryPhoto(idEvent, image)

@PutMapping("/{idEvent}/gallery/removePhoto")
fun removeGalleryPhoto(
@PathVariable idEvent: Long,
@RequestPart photoUrl: String
) = service.removeGalleryPhoto(idEvent, photoUrl)
}
2 changes: 2 additions & 0 deletions src/main/kotlin/pt/up/fe/ni/website/backend/model/Activity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ abstract class Activity(
@field:NotBlank
open var image: String,

val gallery: MutableList<String> = mutableListOf(),
AvilaAndre marked this conversation as resolved.
Show resolved Hide resolved

@Id
@GeneratedValue
open val id: Long? = null
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/pt/up/fe/ni/website/backend/model/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Event(
associatedRoles: MutableList<PerActivityRole> = mutableListOf(),
slug: String? = null,
image: String,
gallery: MutableList<String> = mutableListOf(),

@field:NullOrNotBlank
@field:URL
Expand All @@ -33,4 +34,4 @@ class Event(
val category: String?,

id: Long? = null
) : Activity(title, description, teamMembers, associatedRoles, slug, image, id)
) : Activity(title, description, teamMembers, associatedRoles, slug, image, gallery, id)
3 changes: 2 additions & 1 deletion src/main/kotlin/pt/up/fe/ni/website/backend/model/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Project(
associatedRoles: MutableList<PerActivityRole> = mutableListOf(),
slug: String? = null,
image: String,
gallery: MutableList<String> = mutableListOf(),

var isArchived: Boolean = false,

Expand Down Expand Up @@ -48,4 +49,4 @@ class Project(
val timeline: List<@Valid TimelineEvent> = emptyList(),

id: Long? = null
) : Activity(title, description, teamMembers, associatedRoles, slug, image, id)
) : Activity(title, description, teamMembers, associatedRoles, slug, image, gallery, id)
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ object ErrorMessages {

fun roleNotFound(id: Long): String = "role not found with id $id"

fun photoNotFound(): String = "photo not found"
AvilaAndre marked this conversation as resolved.
Show resolved Hide resolved

fun userAlreadyHasRole(roleId: Long, userId: Long): String = "user $userId already has role $roleId"

fun userNotInRole(roleId: Long, userId: Long): String = "user $userId doesn't have role $roleId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pt.up.fe.ni.website.backend.service.activity

import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import pt.up.fe.ni.website.backend.dto.entity.ActivityDto
import pt.up.fe.ni.website.backend.model.Activity
import pt.up.fe.ni.website.backend.repository.ActivityRepository
Expand Down Expand Up @@ -83,4 +84,35 @@ abstract class AbstractActivityService<T : Activity>(
activity.teamMembers.removeIf { it.id == idAccount }
return repository.save(activity)
}

fun addGalleryPhoto(activityId: Long, image: MultipartFile): Activity {
if (!repository.existsById(activityId)) {
throw NoSuchElementException(ErrorMessages.eventNotFound(activityId))
AvilaAndre marked this conversation as resolved.
Show resolved Hide resolved
}

val activity = getActivityById(activityId)

val fileName = fileUploader.buildFileName(image, activity.title)
val imageName = fileUploader.uploadImage("gallery", fileName, image.bytes)
AvilaAndre marked this conversation as resolved.
Show resolved Hide resolved

activity.gallery.add(imageName)

return repository.save(activity)
}

fun removeGalleryPhoto(activityId: Long, photoName: String): Activity {
if (!repository.existsById(activityId)) {
throw NoSuchElementException(ErrorMessages.eventNotFound(activityId))
}
AvilaAndre marked this conversation as resolved.
Show resolved Hide resolved

val activity = getActivityById(activityId)

val photoRemoved = activity.gallery.remove(photoName)

if (!photoRemoved) {
throw NoSuchElementException(ErrorMessages.photoNotFound())
}

return repository.save(activity)
}
}
Loading
Loading