diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/client/MediaClient.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/client/MediaClient.java index c943a39..532b454 100644 --- a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/client/MediaClient.java +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/client/MediaClient.java @@ -1,18 +1,10 @@ package com.MTAPizza.Sympoll.groupmanagementservice.client; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.GroupDataDeleteRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.delete.GroupDataDeleteRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.media.service.GroupDataDeleteResponse; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.user.service.UserDataResponse; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.user.service.UserIdExistsResponse; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.service.annotation.DeleteExchange; -import org.springframework.web.service.annotation.GetExchange; -import org.springframework.web.service.annotation.PostExchange; - -import java.util.List; -import java.util.UUID; public interface MediaClient { @DeleteExchange("/api/media/group/data") diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/controller/ServiceController.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/controller/ServiceController.java index 89ce9ce..a461f81 100644 --- a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/controller/ServiceController.java +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/controller/ServiceController.java @@ -2,11 +2,13 @@ import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.GroupCreateRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.decription.GroupUpdateDescriptionRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update.GroupUpdateProfileBannerUrlResponse; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update.GroupUpdateProfilePictureUrlResponse; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.user.role.UserRoleChangeRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.user.role.UserRoleCreateRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.user.role.UserRoleDeleteRequest; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.GroupUpdateProfileBannerUrlRequest; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.GroupUpdateProfilePictureUrlRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.update.GroupUpdateProfileBannerUrlRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.update.GroupUpdateProfilePictureUrlRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.DeleteGroupResponse; import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.*; import com.MTAPizza.Sympoll.groupmanagementservice.service.GroupService; @@ -237,7 +239,7 @@ public List getGroupsDataByIds(@RequestBody List groupIds */ @PostMapping("/profile-picture-url") @ResponseStatus(HttpStatus.OK) - public String updateProfilePictureUrl(@RequestBody GroupUpdateProfilePictureUrlRequest groupUpdateProfilePictureUrlRequest){ + public GroupUpdateProfilePictureUrlResponse updateProfilePictureUrl(@RequestBody GroupUpdateProfilePictureUrlRequest groupUpdateProfilePictureUrlRequest){ log.info("Received request to save a profile picture url"); log.debug("Request received to add profile picture url: {}", groupUpdateProfilePictureUrlRequest); return groupService.addProfilePictureUrl(groupUpdateProfilePictureUrlRequest); @@ -250,7 +252,7 @@ public String updateProfilePictureUrl(@RequestBody GroupUpdateProfilePictureUrlR */ @PostMapping("/profile-banner-url") @ResponseStatus(HttpStatus.OK) - public String updateProfileBannerUrl(@RequestBody GroupUpdateProfileBannerUrlRequest groupUpdateProfileBannerUrlRequest){ + public GroupUpdateProfileBannerUrlResponse updateProfileBannerUrl(@RequestBody GroupUpdateProfileBannerUrlRequest groupUpdateProfileBannerUrlRequest){ log.info("Received request to save a banner picture url"); log.debug("Request received to add banner picture url: {}", groupUpdateProfileBannerUrlRequest); return groupService.addProfileBannerUrl(groupUpdateProfileBannerUrlRequest); diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupDataDeleteRequest.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/delete/GroupDataDeleteRequest.java similarity index 85% rename from src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupDataDeleteRequest.java rename to src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/delete/GroupDataDeleteRequest.java index b858430..3f7a5db 100644 --- a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupDataDeleteRequest.java +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/delete/GroupDataDeleteRequest.java @@ -1,4 +1,4 @@ -package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media; +package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.delete; public record GroupDataDeleteRequest( String groupId diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupUpdateProfileBannerUrlRequest.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/update/GroupUpdateProfileBannerUrlRequest.java similarity index 88% rename from src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupUpdateProfileBannerUrlRequest.java rename to src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/update/GroupUpdateProfileBannerUrlRequest.java index 9627c14..9cbe5f1 100644 --- a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupUpdateProfileBannerUrlRequest.java +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/update/GroupUpdateProfileBannerUrlRequest.java @@ -1,4 +1,4 @@ -package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media; +package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.update; public record GroupUpdateProfileBannerUrlRequest( String groupId, diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupUpdateProfilePictureUrlRequest.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/update/GroupUpdateProfilePictureUrlRequest.java similarity index 89% rename from src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupUpdateProfilePictureUrlRequest.java rename to src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/update/GroupUpdateProfilePictureUrlRequest.java index 65f24ab..c1013a7 100644 --- a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/GroupUpdateProfilePictureUrlRequest.java +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/request/update/GroupUpdateProfilePictureUrlRequest.java @@ -1,4 +1,4 @@ -package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media; +package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.update; public record GroupUpdateProfilePictureUrlRequest( String groupId, diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/response/update/GroupUpdateProfileBannerUrlResponse.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/response/update/GroupUpdateProfileBannerUrlResponse.java new file mode 100644 index 0000000..63c9808 --- /dev/null +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/response/update/GroupUpdateProfileBannerUrlResponse.java @@ -0,0 +1,7 @@ +package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update; + +public record GroupUpdateProfileBannerUrlResponse( + String groupId, + String profileBannerUrl +) { +} diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/response/update/GroupUpdateProfilePictureUrlResponse.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/response/update/GroupUpdateProfilePictureUrlResponse.java new file mode 100644 index 0000000..2c56acb --- /dev/null +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/media/response/update/GroupUpdateProfilePictureUrlResponse.java @@ -0,0 +1,7 @@ +package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update; + +public record GroupUpdateProfilePictureUrlResponse( + String groupId, + String profilePictureUrl +) { +} diff --git a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/service/GroupService.java b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/service/GroupService.java index 1d1d679..97abc65 100644 --- a/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/service/GroupService.java +++ b/src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/service/GroupService.java @@ -4,11 +4,13 @@ import com.MTAPizza.Sympoll.groupmanagementservice.client.PollClient; import com.MTAPizza.Sympoll.groupmanagementservice.client.UserClient; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.decription.GroupUpdateDescriptionRequest; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.GroupDataDeleteRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.delete.GroupDataDeleteRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update.GroupUpdateProfileBannerUrlResponse; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update.GroupUpdateProfilePictureUrlResponse; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.poll.DeleteGroupPollsRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.GroupCreateRequest; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.GroupUpdateProfileBannerUrlRequest; -import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.GroupUpdateProfilePictureUrlRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.update.GroupUpdateProfileBannerUrlRequest; +import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.request.update.GroupUpdateProfilePictureUrlRequest; import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.GroupNameResponse; import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.GroupResponse; import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.MemberDetailsResponse; @@ -324,37 +326,45 @@ public List getGroupsDataByIds(List groupIds) { /** * Add a profile picture to a group's profile. * @param groupUpdateProfilePictureUrlRequest Information on the update requested. - * @return ID of the user that was updated. + * @return DTO containing the ID of the group and the old profile picture url. */ - public String addProfilePictureUrl(GroupUpdateProfilePictureUrlRequest groupUpdateProfilePictureUrlRequest) { + public GroupUpdateProfilePictureUrlResponse addProfilePictureUrl(GroupUpdateProfilePictureUrlRequest groupUpdateProfilePictureUrlRequest) { Group groupToUpdate = groupRepository .findById(groupUpdateProfilePictureUrlRequest.groupId()) .orElseThrow( () -> new GroupNotFoundException(groupUpdateProfilePictureUrlRequest.groupId()) ); + String oldProfilePictureUrl = groupToUpdate.getProfilePictureUrl(); groupToUpdate.setProfilePictureUrl(groupUpdateProfilePictureUrlRequest.profilePictureUrl()); groupRepository.save(groupToUpdate); - return groupToUpdate.getGroupId(); + return new GroupUpdateProfilePictureUrlResponse( + groupToUpdate.getGroupId(), + oldProfilePictureUrl + ); } /** * Add a banner picture to a group's profile. * @param groupUpdateProfileBannerUrlRequest Information on the update requested. - * @return ID of the user that was updated. + * @return DTO containing the ID of the group and the old profile banner url. */ - public String addProfileBannerUrl(GroupUpdateProfileBannerUrlRequest groupUpdateProfileBannerUrlRequest) { + public GroupUpdateProfileBannerUrlResponse addProfileBannerUrl(GroupUpdateProfileBannerUrlRequest groupUpdateProfileBannerUrlRequest) { Group groupToUpdate = groupRepository .findById(groupUpdateProfileBannerUrlRequest.groupId()) .orElseThrow( () -> new GroupNotFoundException(groupUpdateProfileBannerUrlRequest.groupId()) ); + String oldProfileBannerUrl = groupToUpdate.getProfilePictureUrl(); groupToUpdate.setProfileBannerUrl(groupUpdateProfileBannerUrlRequest.profileBannerUrl()); groupRepository.save(groupToUpdate); - return groupToUpdate.getGroupId(); + return new GroupUpdateProfileBannerUrlResponse( + groupToUpdate.getGroupId(), + oldProfileBannerUrl + ); } /**