-
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.
task: 8697d5a87
- Loading branch information
Showing
31 changed files
with
319 additions
and
388 deletions.
There are no files selected for viewing
52 changes: 0 additions & 52 deletions
52
backend/src/main/java/meowhub/backend/jpa_buddy/ProfileData.java
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
backend/src/main/java/meowhub/backend/jpa_buddy/ProfileUserData.java
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
backend/src/main/java/meowhub/backend/profiles/controllers/ProfileController.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,38 @@ | ||
package meowhub.backend.profiles.controllers; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import meowhub.backend.profiles.dtos.ProfileDto; | ||
import meowhub.backend.profiles.services.ProfileService; | ||
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.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@RequestMapping(path ="/api/profiles") | ||
@RequiredArgsConstructor | ||
public class ProfileController { | ||
private final ProfileService profileService; | ||
|
||
@GetMapping("/{login}") | ||
public ResponseEntity<ProfileDto> getProfile(@PathVariable String login, @AuthenticationPrincipal UserDetails userDetails) { | ||
return ResponseEntity.ok(profileService.getProfile(login, userDetails.getUsername())); | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<ProfileDto> updateProfile(@RequestParam String content, @AuthenticationPrincipal UserDetails userDetails) { | ||
return ResponseEntity.ok(profileService.updateProfile(content, userDetails.getUsername())); | ||
} | ||
|
||
@PostMapping("/pictures") | ||
public ResponseEntity<ProfileDto> addPictures(@RequestPart MultipartFile file, @AuthenticationPrincipal UserDetails userDetails) { | ||
return ResponseEntity.ok(profileService.addProfilePicture(file, userDetails.getUsername())); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/meowhub/backend/profiles/dtos/ProfileDto.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,13 @@ | ||
package meowhub.backend.profiles.dtos; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class ProfileDto { | ||
private String profilePicture; | ||
private String content; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/meowhub/backend/profiles/repositories/ProfilePictureRepository.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,10 @@ | ||
package meowhub.backend.profiles.repositories; | ||
|
||
import meowhub.backend.profiles.models.ProfilePicture; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ProfilePictureRepository extends JpaRepository<ProfilePicture, String> { | ||
Optional<ProfilePicture> findByProfileIdAndIsCurrentProfilePicture(String profileId, Boolean currentProfilePicture); | ||
} |
48 changes: 48 additions & 0 deletions
48
backend/src/main/java/meowhub/backend/profiles/repositories/ProfileRepository.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,48 @@ | ||
package meowhub.backend.profiles.repositories; | ||
|
||
import meowhub.backend.profiles.dtos.ProfileDto; | ||
import meowhub.backend.profiles.models.Profile; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ProfileRepository extends JpaRepository<Profile, String> { | ||
|
||
@Query(""" | ||
SELECT new meowhub.backend.profiles.dtos.ProfileDto(pp.ociUrl, p.profileDetailsHtml) | ||
FROM Profile p | ||
LEFT JOIN ProfilePicture pp ON pp.profile.id = p.id AND pp.isCurrentProfilePicture = true | ||
WHERE p.user.login = :login | ||
""") | ||
ProfileDto getOwnProfile(@Param("login") String login); | ||
|
||
@Query(""" | ||
SELECT new meowhub.backend.profiles.dtos.ProfileDto(pp.ociUrl, p.profileDetailsHtml) | ||
FROM Profile p | ||
LEFT JOIN ProfilePicture pp ON pp.profile.id = p.id AND pp.isCurrentProfilePicture = true | ||
JOIN User u ON u.id = p.user.id | ||
JOIN u.profilePrivacy profilePrivacy | ||
WHERE u.login = :login | ||
AND (profilePrivacy.code = 'PUBLIC' | ||
OR (profilePrivacy.code = 'FRIENDS_ONLY' AND u.id IN ( | ||
SELECT r.receiver.id | ||
FROM User sender | ||
JOIN sender.userRelationsSender r | ||
JOIN r.relationType relType | ||
WHERE relType.code = 'FRIENDS' | ||
AND sender.login = :requestedBy | ||
UNION | ||
SELECT r.sender.id | ||
FROM User receiver | ||
JOIN receiver.userRelationsReceiver r | ||
JOIN r.relationType relType | ||
WHERE relType.code = 'FRIENDS' | ||
AND receiver.login = :requestedBy) | ||
)) ORDER BY p.createdAt DESC | ||
""") | ||
ProfileDto getProfileIfPublicOrFriends(@Param("login") String login, @Param("requestedBy") String requestedBy); | ||
|
||
Optional<Profile> findByUserLogin(String login); | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/meowhub/backend/profiles/services/BooleanConverter.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,24 @@ | ||
package meowhub.backend.profiles.services; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
|
||
@Converter(autoApply = true) | ||
public class BooleanConverter implements AttributeConverter<Boolean, Integer> { | ||
|
||
@Override | ||
public Integer convertToDatabaseColumn(Boolean attribute) { | ||
if (attribute == null) { | ||
return null; | ||
} | ||
return attribute ? 1 : 0; | ||
} | ||
|
||
@Override | ||
public Boolean convertToEntityAttribute(Integer dbData) { | ||
if (dbData == null) { | ||
return null; | ||
} | ||
return dbData == 1; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/meowhub/backend/profiles/services/ProfileService.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,12 @@ | ||
package meowhub.backend.profiles.services; | ||
|
||
import meowhub.backend.profiles.dtos.ProfileDto; | ||
import meowhub.backend.security.requests.SignUpRequest; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public interface ProfileService { | ||
void createProfile(SignUpRequest signUpRequest); | ||
ProfileDto updateProfile(String content, String login); | ||
ProfileDto getProfile(String login, String requesterLogin); | ||
ProfileDto addProfilePicture(MultipartFile file, String login); | ||
} |
7 changes: 7 additions & 0 deletions
7
...end/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacade.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,7 @@ | ||
package meowhub.backend.profiles.services.facades; | ||
|
||
import meowhub.backend.security.requests.SignUpRequest; | ||
|
||
public interface ProfileAuthServiceFacade { | ||
void createProfile(SignUpRequest signUpRequest); | ||
} |
17 changes: 17 additions & 0 deletions
17
...src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacadeImpl.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,17 @@ | ||
package meowhub.backend.profiles.services.facades; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import meowhub.backend.profiles.services.ProfileService; | ||
import meowhub.backend.security.requests.SignUpRequest; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ProfileAuthServiceFacadeImpl implements ProfileAuthServiceFacade { | ||
private final ProfileService profileService; | ||
|
||
@Override | ||
public void createProfile(SignUpRequest signUpRequest) { | ||
profileService.createProfile(signUpRequest); | ||
} | ||
} |
Oops, something went wrong.