-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from JimTheCat/CU-8697q6e93_MATCHING-add-endp…
…oints-for-addingdeleting-a-single-picture--add-indexes_Kinga-Traczyk feature: MATCHING: add endpoints for adding/deleting a single picture + add indexing
- Loading branch information
Showing
14 changed files
with
377 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
.../src/main/java/meowhub/backend/matching/controllers/MatchingProfilePictureController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
backend/src/main/java/meowhub/backend/matching/services/MatchingProfilePictureService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/meowhub/backend/matching/services/MatchingProfileQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...end/src/main/java/meowhub/backend/matching/services/MatchingProfileValidationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.