Skip to content

Commit

Permalink
On update profile pictures endpoints, will return the old url in a ne…
Browse files Browse the repository at this point in the history
…w DTO.
  • Loading branch information
Idan-sh committed Sep 16, 2024
1 parent fe96928 commit 8e30edd
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -237,7 +239,7 @@ public List<GroupResponse> getGroupsDataByIds(@RequestBody List<String> 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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update;

public record GroupUpdateProfileBannerUrlResponse(
String groupId,
String profileBannerUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media.response.update;

public record GroupUpdateProfilePictureUrlResponse(
String groupId,
String profilePictureUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -324,37 +326,45 @@ public List<GroupResponse> getGroupsDataByIds(List<String> 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
);
}

/**
Expand Down

0 comments on commit 8e30edd

Please sign in to comment.