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

feature: MATCHING: add endpoints for adding/deleting a single picture + add indexing #134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -4,8 +4,8 @@
import meowhub.backend.matching.dtos.CreateMatchingProfileRequestDto;
import meowhub.backend.matching.dtos.UpdateMatchingProfileRequestDto;
import meowhub.backend.matching.dtos.MatchingProfileDto;
import meowhub.backend.matching.services.MatchingProfileQueryService;
import meowhub.backend.matching.services.MatchingProfileService;
import meowhub.backend.shared.dtos.PictureDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
Expand All @@ -16,33 +16,25 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/matching-profile")
@AllArgsConstructor
public class MatchingProfileController {
private final MatchingProfileService matchingProfileService;
private final MatchingProfileQueryService matchingProfileQueryService;

@GetMapping("")
public ResponseEntity<MatchingProfileDto> getMyMatchingProfile(@AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfileService.getMyProfile(userDetails.getUsername()));
return ResponseEntity.ok(matchingProfileQueryService.getMyProfile(userDetails.getUsername()));
}

@PostMapping("/update")
public ResponseEntity<MatchingProfileDto> updateMatchingProfile(@RequestBody UpdateMatchingProfileRequestDto matchingProfileDto, @AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfileService.updateMatchingProfile(matchingProfileDto, userDetails.getUsername()));
}

@PostMapping("/pictures")
public ResponseEntity<List<PictureDto>> addMatchingProfilePictures(@RequestPart List<MultipartFile> files, @RequestPart(required = false) String profilePictureName, @AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfileService.addMatchingProfilePictures(files, profilePictureName, userDetails.getUsername()));
}

@PostMapping("/create")
public ResponseEntity<MatchingProfileDto> createMatchingProfileBasedOnAccount(@AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfileService.createMatchingProfileBasedOnAccount(userDetails.getUsername()));
Expand All @@ -55,17 +47,11 @@ public ResponseEntity<MatchingProfileDto> createMatchingProfileFromScratch(@Requ

@GetMapping("/all")
public ResponseEntity<Page<MatchingProfileDto>> getAllMatchingProfiles(Pageable pageable) {
return ResponseEntity.ok(matchingProfileService.getAllMatchingProfiles(pageable));
return ResponseEntity.ok(matchingProfileQueryService.getAllMatchingProfiles(pageable));
}

@DeleteMapping()
public void deleteMatchingProfile(@AuthenticationPrincipal UserDetails userDetails) {
matchingProfileService.deleteMatchingProfile(userDetails.getUsername());
}

@DeleteMapping("/pictures")
public void deleteMatchingProfilePicture(@RequestBody List<String> pictureIds, @AuthenticationPrincipal UserDetails userDetails) {
matchingProfileService.deleteMatchingProfilePicturesForUser(pictureIds, userDetails.getUsername());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package meowhub.backend.matching.controllers;

import lombok.RequiredArgsConstructor;
import meowhub.backend.matching.services.MatchingProfilePictureService;
import meowhub.backend.shared.dtos.PictureDto;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/matching-profile-picture")
@RequiredArgsConstructor
public class MatchingProfilePictureController {
private final MatchingProfilePictureService matchingProfilePictureService;

@PostMapping()
public ResponseEntity<PictureDto> addPicture(@RequestPart MultipartFile file, @RequestPart String pictureIndex, @AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfilePictureService.addMatchingProfilePicture(file, Long.valueOf(pictureIndex), userDetails.getUsername()));
}

@PostMapping("/indexes")
public ResponseEntity<List<PictureDto>> setIndexes(@RequestBody Map<String, Long> pictureIndexes, @AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfilePictureService.setIndexes(pictureIndexes, userDetails.getUsername()));
}

@DeleteMapping("/{pictureId}")
public void deletePicture(@PathVariable("pictureId") String pictureId, @AuthenticationPrincipal UserDetails userDetails) {
matchingProfilePictureService.deleteMatchingProfilePictureForUser(pictureId, userDetails.getUsername());
}

//-------------------------------------------------------------------------------- UNUSED --------------------------------------------------------------------------------
@PostMapping("/pictures")
@Deprecated(forRemoval = true)
public ResponseEntity<List<PictureDto>> addMatchingProfilePictures(@RequestPart List<MultipartFile> files, @RequestPart(required = false) String profilePictureName, @AuthenticationPrincipal UserDetails userDetails) {
return ResponseEntity.ok(matchingProfilePictureService.addMatchingProfilePictures(files, profilePictureName, userDetails.getUsername()));
}

@DeleteMapping("/pictures")
@Deprecated(forRemoval = true)
public void deleteMatchingProfilePicture(@RequestBody List<String> pictureIds, @AuthenticationPrincipal UserDetails userDetails) {
matchingProfilePictureService.deleteMatchingProfilePicturesForUser(pictureIds, userDetails.getUsername());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public static MatchingProfileDto createFromMatchingProfile(MatchingProfile match
}

private static PictureDto createFromPicture(MatchingProfilePicture picture) {
return new PictureDto(picture.getId(), picture.getOciUrl(), picture.getCreatedAt());
return new PictureDto(picture.getId(), picture.getOciUrl(), picture.getIndex(), picture.getCreatedAt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class MatchingProfilePicture {
@Column(name = "OCI_URL", nullable = false, length = 2000)
private String ociUrl;

@NotNull
@Column(name = "PICTURE_INDEX", nullable = false)
private Long index;

@NotNull
@Column(name = "IS_CURRENT_PP", nullable = false)
@Convert(converter = BooleanConverter.class)
Expand All @@ -66,10 +70,11 @@ public class MatchingProfilePicture {
@Column(name = "MODIFIED_BY", length = 36)
private String modifiedBy;

public MatchingProfilePicture(MatchingProfile matchingProfile, String ociName, String ociUrl, boolean isCurrentProfilePicture) {
public MatchingProfilePicture(MatchingProfile matchingProfile, String ociName, String ociUrl, boolean isCurrentProfilePicture, Long index) {
this.matchingProfile = matchingProfile;
this.ociName = ociName;
this.ociUrl = ociUrl;
this.isCurrentProfilePicture = isCurrentProfilePicture;
this.index = index;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package meowhub.backend.matching.services;

import meowhub.backend.shared.dtos.PictureDto;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

public interface MatchingProfilePictureService {
PictureDto addMatchingProfilePicture(MultipartFile file, Long index, String login);

List<PictureDto> setIndexes(Map<String, Long> pictureIndexes, String login);

void deleteMatchingProfilePictureForUser(String pictureId, String login);

void intDeleteMatchingProfilePicture(String pictureId);

/***
* Adds pictures to the matching profile.
* Since currently frontend does not support adding multiple pictures in single request to the profile, this method is deprecated.
* @param files, max 5 pictures
* @param profilePictureName - name of the picture in files list, that is to be set as new profile picture
* @param login
* @return
* @deprecated
*/
@Deprecated
List<PictureDto> addMatchingProfilePictures(List<MultipartFile> files, String profilePictureName, String login);

/**
* Since currently frontend does not support deleting multiple pictures in single request, this method is deprecated.
* @deprecated
*/
@Deprecated
void deleteMatchingProfilePicturesForUser(List<String> profilePictureIds, String login);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package meowhub.backend.matching.services;


import meowhub.backend.matching.dtos.MatchingProfileDto;
import meowhub.backend.matching.models.MatchingProfile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.Optional;

public interface MatchingProfileQueryService {
Page<MatchingProfileDto> getAllMatchingProfiles(Pageable pageable);

MatchingProfileDto getMyProfile(String login);

MatchingProfile findMatchingProfileByLoginOrThrow(String login);

Optional<MatchingProfile> findMatchingProfileByLogin(String login);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,14 @@
import meowhub.backend.matching.dtos.CreateMatchingProfileRequestDto;
import meowhub.backend.matching.dtos.UpdateMatchingProfileRequestDto;
import meowhub.backend.matching.dtos.MatchingProfileDto;
import meowhub.backend.shared.dtos.PictureDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface MatchingProfileService {
Page<MatchingProfileDto> getAllMatchingProfiles(Pageable pageable);

MatchingProfileDto getMyProfile(String login);

MatchingProfileDto createMatchingProfileBasedOnAccount(String login);

MatchingProfileDto createMatchingProfileFromScratch(CreateMatchingProfileRequestDto request, String login);

MatchingProfileDto updateMatchingProfile(UpdateMatchingProfileRequestDto matchingProfileDto, String login);

/***
* Adds pictures to the matching profile.
* @param files, max 5 pictures
* @param profilePictureName - name of the picture in files list, that is to be set as new profile picture
* @param login
* @return
*/
List<PictureDto> addMatchingProfilePictures(List<MultipartFile> files, String profilePictureName, String login);

void deleteMatchingProfile(String login);

void deleteMatchingProfilePicturesForUser(List<String> profilePictureIds, String login);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package meowhub.backend.matching.services;

public interface MatchingProfileValidationService {
void validateIfMatchingProfileAlreadyExists(String login);
}
Loading