Skip to content

Commit

Permalink
Merge pull request #25 from sympoll/group-profile-pictures
Browse files Browse the repository at this point in the history
Group profile pictures
  • Loading branch information
RoyToledano authored Sep 5, 2024
2 parents ca9d145 + d359d2c commit ccf7b21
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.UserRoleChangeRequest;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.UserRoleCreateRequest;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.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.response.group.service.DeleteGroupResponse;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.*;
import com.MTAPizza.Sympoll.groupmanagementservice.service.GroupService;
Expand Down Expand Up @@ -216,14 +218,40 @@ public UserGroupsResponse getAllUserGroups(@RequestParam UUID userId) {
}

/**
* Fetch and retrieve a list of group names by their ids.
* @param groupIds Given group ids.
* @return A list of DTO with the user id and the username.
* Fetch and retrieve a list of groups' data by their IDs.
* @param groupIds Given group IDs.
* @return List of group data DTOs.
*/
@PostMapping("/group-name-list")
@PostMapping("/groups-list")
@ResponseStatus(HttpStatus.OK)
public List<GroupNameResponse> getGroupNamesByIds(@RequestBody List<String> groupIds){
log.info("Received request to retrieve usernames");
return groupService.getGroupNamesByIds(groupIds);
public List<GroupResponse> getGroupsDataByIds(@RequestBody List<String> groupIds){
log.info("Received request to retrieve groups' data by IDs");
return groupService.getGroupsDataByIds(groupIds);
}

/**
* Save a profile picture for a group
* @param groupUpdateProfilePictureUrlRequest Information on the update to perform.
* @return The updated group's ID.
*/
@PostMapping("/profile-picture-url")
@ResponseStatus(HttpStatus.OK)
public String 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);
}

/**
* Save a banner picture for a group
* @param groupUpdateProfileBannerUrlRequest Information on the update to perform.
* @return The updated group's ID.
*/
@PostMapping("/profile-banner-url")
@ResponseStatus(HttpStatus.OK)
public String 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.MTAPizza.Sympoll.groupmanagementservice.dto.request.media;

public record GroupUpdateProfileBannerUrlRequest(
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;

public record GroupUpdateProfilePictureUrlRequest(
String groupId,
String profilePictureUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public record GroupResponse (
String groupId,
String groupName,
String description,
String profilePictureUrl,
String profileBannerUrl,
UUID creatorId,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
LocalDateTime timeCreated,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.MTAPizza.Sympoll.groupmanagementservice.exception.group;

import java.util.UUID;

public class GroupNotFoundException extends RuntimeException {
public GroupNotFoundException(String groupId) {
super("Group with ID '" + groupId + "' was not found");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public class Group {
@Column(name = "description")
private String description;

@Column(name = "profile_picture_url")
private String profilePictureUrl;

@Column(name = "profile_banner_url")
private String profileBannerUrl;

@Column(name = "creator_id")
private UUID creatorId;

Expand Down Expand Up @@ -75,12 +81,14 @@ public Member getMember(UUID memberId) {

public GroupResponse toGroupResponse() {
return new GroupResponse(
groupId,
groupName,
description,
creatorId,
timeCreated,
membersList != null ? membersList.stream().map(Member::toMemberResponse).toList() : new ArrayList<>() // Convert to member response
this.groupId,
this.groupName,
this.description,
this.profilePictureUrl,
this.profileBannerUrl,
this.creatorId,
this.timeCreated,
this. membersList != null ? this.membersList.stream().map(Member::toMemberResponse).toList() : new ArrayList<>() // Convert to member response
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.MTAPizza.Sympoll.groupmanagementservice.client.UserClient;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.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.response.group.service.GroupNameResponse;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.GroupResponse;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.MemberDetailsResponse;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.group.service.MemberResponse;
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.poll.service.DeleteGroupPollsResponse;
import com.MTAPizza.Sympoll.groupmanagementservice.exception.group.GroupNotFoundException;
import com.MTAPizza.Sympoll.groupmanagementservice.exception.request.RequestFailedException;
import com.MTAPizza.Sympoll.groupmanagementservice.model.Group;
import com.MTAPizza.Sympoll.groupmanagementservice.model.member.Member;
Expand Down Expand Up @@ -295,14 +298,50 @@ public GroupResponse getGroupById(String groupId) {
return groupRepository.getReferenceById(groupId).toGroupResponse();
}

public List<GroupNameResponse> getGroupNamesByIds(List<String> groupIds) {
public List<GroupResponse> getGroupsDataByIds(List<String> groupIds) {
validator.validateMultipleIdsExist(groupIds);
log.info("Retrieving groups names from db");
log.info("Retrieving groups' data from DB");

return groupRepository
.findByGroupIdIn(groupIds)
.stream()
.map(Group::toGroupNameResponse)
.map(Group::toGroupResponse)
.toList();
}

/**
* Add a profile picture to a group's profile.
* @param groupUpdateProfilePictureUrlRequest Information on the update requested.
* @return ID of the user that was updated.
*/
public String addProfilePictureUrl(GroupUpdateProfilePictureUrlRequest groupUpdateProfilePictureUrlRequest) {
Group groupToUpdate = groupRepository
.findById(groupUpdateProfilePictureUrlRequest.groupId())
.orElseThrow(
() -> new GroupNotFoundException(groupUpdateProfilePictureUrlRequest.groupId())
);

groupToUpdate.setProfilePictureUrl(groupUpdateProfilePictureUrlRequest.profilePictureUrl());
groupRepository.save(groupToUpdate);

return groupToUpdate.getGroupId();
}

/**
* Add a banner picture to a group's profile.
* @param groupUpdateProfileBannerUrlRequest Information on the update requested.
* @return ID of the user that was updated.
*/
public String addProfileBannerUrl(GroupUpdateProfileBannerUrlRequest groupUpdateProfileBannerUrlRequest) {
Group groupToUpdate = groupRepository
.findById(groupUpdateProfileBannerUrlRequest.groupId())
.orElseThrow(
() -> new GroupNotFoundException(groupUpdateProfileBannerUrlRequest.groupId())
);

groupToUpdate.setProfileBannerUrl(groupUpdateProfileBannerUrlRequest.profileBannerUrl());
groupRepository.save(groupToUpdate);

return groupToUpdate.getGroupId();
}
}
2 changes: 2 additions & 0 deletions docker/init.sql → src/main/resources/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CREATE TABLE groups
group_id VARCHAR(255) PRIMARY KEY,
group_name VARCHAR(255),
description TEXT,
profile_picture_url VARCHAR(255),
profile_banner_url VARCHAR(255),
creator_id UUID,
time_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Expand Down

0 comments on commit ccf7b21

Please sign in to comment.