diff --git a/backend/src/main/java/meowhub/backend/jpa_buddy/ProfileData.java b/backend/src/main/java/meowhub/backend/jpa_buddy/ProfileData.java deleted file mode 100644 index dfef7a2..0000000 --- a/backend/src/main/java/meowhub/backend/jpa_buddy/ProfileData.java +++ /dev/null @@ -1,52 +0,0 @@ -package meowhub.backend.jpa_buddy; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import lombok.Getter; -import lombok.Setter; - -import java.time.LocalDateTime; -import java.util.LinkedHashSet; -import java.util.Set; - -@Getter -@Setter -@Entity -@Table(name = "PROFILE_DATA", schema = "mh_profiles") -public class ProfileData { - @Id - @Size(max = 36) - @GeneratedValue(strategy = GenerationType.UUID) - @Column(name = "ID", nullable = false, length = 36) - private String id; - - @Size(max = 40) - @NotNull - @Column(name = "CODE", nullable = false, length = 40) - private String code; - - @Column(name = "CREATED_AT") - private LocalDateTime createdAt; - - @Size(max = 36) - @Column(name = "CREATED_BY", length = 36) - private String createdBy; - - @Column(name = "MODIFIED_AT") - private LocalDateTime modifiedAt; - - @Size(max = 36) - @Column(name = "MODIFIED_BY", length = 36) - private String modifiedBy; - - @OneToMany(mappedBy = "profileData") - private Set profileUserData = new LinkedHashSet<>(); - -} \ No newline at end of file diff --git a/backend/src/main/java/meowhub/backend/jpa_buddy/ProfileUserData.java b/backend/src/main/java/meowhub/backend/jpa_buddy/ProfileUserData.java deleted file mode 100644 index 80c105f..0000000 --- a/backend/src/main/java/meowhub/backend/jpa_buddy/ProfileUserData.java +++ /dev/null @@ -1,63 +0,0 @@ -package meowhub.backend.jpa_buddy; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import lombok.Getter; -import lombok.Setter; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; - -import java.time.LocalDateTime; - -@Getter -@Setter -@Entity -@Table(name = "PROFILE_USER_DATA", schema = "mh_profiles") -public class ProfileUserData { - @Id - @Size(max = 36) - @GeneratedValue(strategy = GenerationType.UUID) - @Column(name = "ID", nullable = false, length = 36) - private String id; - - @NotNull - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @OnDelete(action = OnDeleteAction.RESTRICT) - @JoinColumn(name = "PROFILE_ID", nullable = false) - private Profile profile; - - @NotNull - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @OnDelete(action = OnDeleteAction.RESTRICT) - @JoinColumn(name = "PROFILE_DATA_ID", nullable = false) - private ProfileData profileData; - - @Size(max = 200) - @NotNull - @Column(name = "CONTENT", nullable = false, length = 200) - private String content; - - @Column(name = "CREATED_AT") - private LocalDateTime createdAt; - - @Size(max = 36) - @Column(name = "CREATED_BY", length = 36) - private String createdBy; - - @Column(name = "MODIFIED_AT") - private LocalDateTime modifiedAt; - - @Size(max = 36) - @Column(name = "MODIFIED_BY", length = 36) - private String modifiedBy; - -} \ No newline at end of file diff --git a/backend/src/main/java/meowhub/backend/profiles/controllers/ProfileController.java b/backend/src/main/java/meowhub/backend/profiles/controllers/ProfileController.java index 2629b9b..5199129 100644 --- a/backend/src/main/java/meowhub/backend/profiles/controllers/ProfileController.java +++ b/backend/src/main/java/meowhub/backend/profiles/controllers/ProfileController.java @@ -3,6 +3,7 @@ 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; @@ -14,8 +15,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import java.util.List; - @RestController @RequestMapping(path ="/api/profiles") @RequiredArgsConstructor @@ -23,17 +22,17 @@ public class ProfileController { private final ProfileService profileService; @GetMapping("/{login}") - public ProfileDto getProfile(@PathVariable String login, @AuthenticationPrincipal UserDetails userDetails) { - return profileService.getProfile(login, userDetails.getUsername()); + public ResponseEntity getProfile(@PathVariable String login, @AuthenticationPrincipal UserDetails userDetails) { + return ResponseEntity.ok(profileService.getProfile(login, userDetails.getUsername())); } @PostMapping("") - public ProfileDto updateProfile(@RequestParam String content, @AuthenticationPrincipal UserDetails userDetails) { - return profileService.updateProfile(content, userDetails.getUsername()); + public ResponseEntity updateProfile(@RequestParam String content, @AuthenticationPrincipal UserDetails userDetails) { + return ResponseEntity.ok(profileService.updateProfile(content, userDetails.getUsername())); } @PostMapping("/pictures") - public ProfileDto addPictures(@RequestPart List files, @AuthenticationPrincipal UserDetails userDetails) { - return profileService.addPictures(files, userDetails.getUsername()); + public ResponseEntity addPictures(@RequestPart MultipartFile file, @AuthenticationPrincipal UserDetails userDetails) { + return ResponseEntity.ok(profileService.addProfilePicture(file, userDetails.getUsername())); } } diff --git a/backend/src/main/java/meowhub/backend/profiles/dtos/ProfileDto.java b/backend/src/main/java/meowhub/backend/profiles/dtos/ProfileDto.java index dd08188..9cc4aa8 100644 --- a/backend/src/main/java/meowhub/backend/profiles/dtos/ProfileDto.java +++ b/backend/src/main/java/meowhub/backend/profiles/dtos/ProfileDto.java @@ -1,12 +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; - } diff --git a/backend/src/main/java/meowhub/backend/jpa_buddy/Profile.java b/backend/src/main/java/meowhub/backend/profiles/models/Profile.java similarity index 92% rename from backend/src/main/java/meowhub/backend/jpa_buddy/Profile.java rename to backend/src/main/java/meowhub/backend/profiles/models/Profile.java index 4b9f0b8..7b9a7f7 100644 --- a/backend/src/main/java/meowhub/backend/jpa_buddy/Profile.java +++ b/backend/src/main/java/meowhub/backend/profiles/models/Profile.java @@ -1,4 +1,4 @@ -package meowhub.backend.jpa_buddy; +package meowhub.backend.profiles.models; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -60,8 +60,4 @@ public class Profile { @OneToMany(mappedBy = "profile") private Set profilePictures = new LinkedHashSet<>(); - - @OneToMany(mappedBy = "profile") - private Set profileUserData = new LinkedHashSet<>(); - } \ No newline at end of file diff --git a/backend/src/main/java/meowhub/backend/jpa_buddy/ProfilePicture.java b/backend/src/main/java/meowhub/backend/profiles/models/ProfilePicture.java similarity index 92% rename from backend/src/main/java/meowhub/backend/jpa_buddy/ProfilePicture.java rename to backend/src/main/java/meowhub/backend/profiles/models/ProfilePicture.java index 5fccec7..21d9943 100644 --- a/backend/src/main/java/meowhub/backend/jpa_buddy/ProfilePicture.java +++ b/backend/src/main/java/meowhub/backend/profiles/models/ProfilePicture.java @@ -1,4 +1,4 @@ -package meowhub.backend.jpa_buddy; +package meowhub.backend.profiles.models; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -44,8 +44,8 @@ public class ProfilePicture { private String ociUrl; @NotNull - @Column(name = "PICTURE_INDEX", nullable = false) - private Long index; + @Column(name = "IS_CURRENT_PP", nullable = false) + private boolean isCurrentProfilePicture; @Column(name = "CREATED_AT") private LocalDateTime createdAt; diff --git a/backend/src/main/java/meowhub/backend/profiles/repositories/ProfilePictureRepository.java b/backend/src/main/java/meowhub/backend/profiles/repositories/ProfilePictureRepository.java index afc8320..fd2f2a1 100644 --- a/backend/src/main/java/meowhub/backend/profiles/repositories/ProfilePictureRepository.java +++ b/backend/src/main/java/meowhub/backend/profiles/repositories/ProfilePictureRepository.java @@ -1,7 +1,10 @@ package meowhub.backend.profiles.repositories; -import meowhub.backend.jpa_buddy.ProfilePicture; +import meowhub.backend.profiles.models.ProfilePicture; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface ProfilePictureRepository extends JpaRepository { + Optional findByProfileIdAndCurrentProfilePicture(String profileId, boolean currentProfilePicture); } \ No newline at end of file diff --git a/backend/src/main/java/meowhub/backend/profiles/repositories/ProfileRepository.java b/backend/src/main/java/meowhub/backend/profiles/repositories/ProfileRepository.java index d1a042f..f8daabf 100644 --- a/backend/src/main/java/meowhub/backend/profiles/repositories/ProfileRepository.java +++ b/backend/src/main/java/meowhub/backend/profiles/repositories/ProfileRepository.java @@ -1,7 +1,48 @@ package meowhub.backend.profiles.repositories; -import meowhub.backend.jpa_buddy.Profile; +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 { + + @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 findByUserLogin(String login); } \ No newline at end of file diff --git a/backend/src/main/java/meowhub/backend/profiles/services/ProfileService.java b/backend/src/main/java/meowhub/backend/profiles/services/ProfileService.java index b7a4149..4e8d536 100644 --- a/backend/src/main/java/meowhub/backend/profiles/services/ProfileService.java +++ b/backend/src/main/java/meowhub/backend/profiles/services/ProfileService.java @@ -4,11 +4,9 @@ import meowhub.backend.security.requests.SignUpRequest; import org.springframework.web.multipart.MultipartFile; -import java.util.List; - public interface ProfileService { void createProfile(SignUpRequest signUpRequest); ProfileDto updateProfile(String content, String login); ProfileDto getProfile(String login, String requesterLogin); - ProfileDto addPictures(List file, String login); + ProfileDto addProfilePicture(MultipartFile file, String login); } diff --git a/backend/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacade.java b/backend/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacade.java new file mode 100644 index 0000000..27d9f02 --- /dev/null +++ b/backend/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacade.java @@ -0,0 +1,7 @@ +package meowhub.backend.profiles.services.facades; + +import meowhub.backend.security.requests.SignUpRequest; + +public interface ProfileAuthServiceFacade { + void createProfile(SignUpRequest signUpRequest); +} diff --git a/backend/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacadeImpl.java b/backend/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacadeImpl.java new file mode 100644 index 0000000..aa10f29 --- /dev/null +++ b/backend/src/main/java/meowhub/backend/profiles/services/facades/ProfileAuthServiceFacadeImpl.java @@ -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); + } +} diff --git a/backend/src/main/java/meowhub/backend/profiles/services/impl/ProfileServiceImpl.java b/backend/src/main/java/meowhub/backend/profiles/services/impl/ProfileServiceImpl.java index e64ad3c..b582838 100644 --- a/backend/src/main/java/meowhub/backend/profiles/services/impl/ProfileServiceImpl.java +++ b/backend/src/main/java/meowhub/backend/profiles/services/impl/ProfileServiceImpl.java @@ -1,32 +1,84 @@ package meowhub.backend.profiles.services.impl; +import lombok.RequiredArgsConstructor; import meowhub.backend.profiles.dtos.ProfileDto; +import meowhub.backend.profiles.models.Profile; +import meowhub.backend.profiles.models.ProfilePicture; +import meowhub.backend.profiles.repositories.ProfilePictureRepository; +import meowhub.backend.profiles.repositories.ProfileRepository; import meowhub.backend.profiles.services.ProfileService; import meowhub.backend.security.requests.SignUpRequest; +import meowhub.backend.shared.constants.AlertConstants; +import meowhub.backend.shared.utils.PictureUtils; +import meowhub.backend.users.facades.UserProfileServiceFacade; +import meowhub.backend.users.models.User; +import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import java.util.List; +import java.util.Optional; @Service +@RequiredArgsConstructor public class ProfileServiceImpl implements ProfileService { + private final UserProfileServiceFacade userProfileServiceFacade; + private final ProfileRepository profileRepository; + private final ProfilePictureRepository profilePictureRepository; + private final PictureUtils pictureUtils; + @Override public void createProfile(SignUpRequest signUpRequest) { + User user = userProfileServiceFacade.findUserByLogin(signUpRequest.getLogin()); + Profile profile = new Profile(); + profile.setUser(user); + profileRepository.save(profile); } @Override public ProfileDto updateProfile(String content, String login) { - return null; + Profile profile = profileRepository.findByUserLogin(login) + .orElseThrow(() -> new NullPointerException(AlertConstants.USER_WITH_LOGIN_NOT_FOUND + login)); + profile.setProfileDetailsHtml(content); + profileRepository.save(profile); + + return profileRepository.getOwnProfile(login); } @Override public ProfileDto getProfile(String login, String requesterLogin) { - return null; + userProfileServiceFacade.validateIfUserExists(login); + + if(login.equals(requesterLogin)){ + return profileRepository.getOwnProfile(login); + } else { + return profileRepository.getProfileIfPublicOrFriends(login, requesterLogin); + } } @Override - public ProfileDto addPictures(List file, String login) { - return null; + public ProfileDto addProfilePicture(MultipartFile file, String login) { + if(file == null || file.getContentType() == null || file.getContentType().isEmpty()){ + throw new NullPointerException(AlertConstants.VALUE_REQUIRED_TITLE); + } + Profile profile = profileRepository.findByUserLogin(login) + .orElseThrow(() -> new NullPointerException(AlertConstants.USER_WITH_LOGIN_NOT_FOUND + login)); + + //setting current profile picture to false if exists + Optional currentProfilePicture = profilePictureRepository.findByProfileIdAndCurrentProfilePicture(login, true); + if(currentProfilePicture.isPresent()){ + currentProfilePicture.get().setCurrentProfilePicture(false); + profilePictureRepository.save(currentProfilePicture.get()); + } + + Pair pictureDetails = pictureUtils.uploadPictureToOCIAndGetAuthorizedUrlToAccessIt(file, login); + ProfilePicture profilePicture = new ProfilePicture(); + profilePicture.setProfile(profile); + profilePicture.setOciName(pictureDetails.getFirst()); + profilePicture.setOciUrl(pictureDetails.getSecond()); + profilePicture.setCurrentProfilePicture(true); + profilePictureRepository.save(profilePicture); + + return profileRepository.getOwnProfile(login); } } diff --git a/backend/src/main/java/meowhub/backend/security/services/impl/AuthServiceImpl.java b/backend/src/main/java/meowhub/backend/security/services/impl/AuthServiceImpl.java index c4c9a29..6adeb84 100644 --- a/backend/src/main/java/meowhub/backend/security/services/impl/AuthServiceImpl.java +++ b/backend/src/main/java/meowhub/backend/security/services/impl/AuthServiceImpl.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import meowhub.backend.constants.Roles; +import meowhub.backend.profiles.services.facades.ProfileAuthServiceFacade; import meowhub.backend.shared.constants.AlertConstants; import meowhub.backend.shared.exceptions.NotUniqueObjectException; import meowhub.backend.users.facades.UserAuthServiceFacade; @@ -28,6 +29,7 @@ public class AuthServiceImpl implements AuthService { private final JwtUtils jwtUtils; private final AuthenticationManager authenticationManager; private final UserAuthServiceFacade userAuthServiceFacade; + private final ProfileAuthServiceFacade profileAuthServiceFacade; @Override public LoginResponse authenticateUser(LoginRequest request) { @@ -52,6 +54,7 @@ public LoginResponse authenticateUser(LoginRequest request) { public void signUpUser(SignUpRequest request) { validateSignUpRequest(request); userAuthServiceFacade.createUser(request.getLogin(), request.getName(), request.getSurname(), request.getEmail(), request.getPassword(), request.getBirthdate(), Roles.ROLE_USER, request.getGender()); + profileAuthServiceFacade.createProfile(request); } private void validateSignUpRequest(SignUpRequest request) { diff --git a/backend/src/main/java/meowhub/backend/user_relations/repositories/UserRelationRepository.java b/backend/src/main/java/meowhub/backend/user_relations/repositories/UserRelationRepository.java index ea34b1e..4ad1838 100644 --- a/backend/src/main/java/meowhub/backend/user_relations/repositories/UserRelationRepository.java +++ b/backend/src/main/java/meowhub/backend/user_relations/repositories/UserRelationRepository.java @@ -17,12 +17,14 @@ public interface UserRelationRepository extends JpaRepository { ) FROM User u LEFT JOIN Profile p ON p.user.id = u.id - LEFT JOIN ProfilePicture pp ON pp.profile.id = p.id + LEFT JOIN ProfilePicture pp ON pp.profile.id = p.id AND pp.isCurrentProfilePicture = true WHERE u.login = :login ORDER BY pp.id FETCH FIRST 1 ROWS ONLY @@ -43,9 +43,11 @@ public interface UserRepository extends JpaRepository { u.name, u.surname, u.login, - null + pp.ociUrl ) FROM User u + JOIN Profile p ON p.user.id = u.id + LEFT JOIN ProfilePicture pp ON pp.profile.id = p.id AND pp.isCurrentProfilePicture = true WHERE LOWER(u.login) LIKE LOWER(CONCAT('%', :query, '%')) OR LOWER(u.name) LIKE LOWER(CONCAT('%', :query, '%')) OR LOWER(u.surname) LIKE LOWER(CONCAT('%', :query, '%')) diff --git a/backend/src/test/java/meowhub/backend/InitDataTestConfig.java b/backend/src/test/java/meowhub/backend/InitDataTestConfig.java index 0a43792..b3dbaaa 100644 --- a/backend/src/test/java/meowhub/backend/InitDataTestConfig.java +++ b/backend/src/test/java/meowhub/backend/InitDataTestConfig.java @@ -7,10 +7,8 @@ import meowhub.backend.posts.models.Comment; import meowhub.backend.posts.models.Post; import meowhub.backend.posts.models.PostPicture; -import meowhub.backend.jpa_buddy.Profile; -import meowhub.backend.jpa_buddy.ProfileData; -import meowhub.backend.jpa_buddy.ProfilePicture; -import meowhub.backend.jpa_buddy.ProfileUserData; +import meowhub.backend.profiles.models.Profile; +import meowhub.backend.profiles.models.ProfilePicture; import meowhub.backend.user_relations.models.RelationType; import meowhub.backend.user_relations.models.UserRelation; import meowhub.backend.posts.repositories.CommentRepository; diff --git a/database/scripts/120_create_tables.sql b/database/scripts/120_create_tables.sql index ff3b584..d878e64 100644 --- a/database/scripts/120_create_tables.sql +++ b/database/scripts/120_create_tables.sql @@ -286,18 +286,6 @@ CREATE TABLE mh_matching.Matching_Profiles ); ---------------------------------------- || MH_PROFILES SCHEMA || ---------------------------------------- --- Table: Profile_Data -CREATE TABLE mh_profiles.Profile_Data -( - id varchar2(36) DEFAULT sys_guid() NOT NULL, - code varchar2(40) NOT NULL, - created_at date NOT NULL, - created_by varchar2(36) NOT NULL, - modified_at date NULL, - modified_by varchar2(36) NULL, - CONSTRAINT Profile_Data_pk PRIMARY KEY (id) -); - -- Table: Profile_Pictures CREATE TABLE mh_profiles.Profile_Pictures ( @@ -305,26 +293,13 @@ CREATE TABLE mh_profiles.Profile_Pictures profile_id varchar2(36) NOT NULL, oci_name varchar2(100) NOT NULL, oci_url varchar2(2000) NOT NULL, - picture_index number NOT NULL, + is_current_pp number(1) NOT NULL, created_at date NOT NULL, created_by varchar2(36) NOT NULL, modified_at date NULL, modified_by varchar2(36) NULL, - CONSTRAINT Profile_Pictures_pk PRIMARY KEY (id) -); - --- Table: Profile_User_Data -CREATE TABLE mh_profiles.Profile_User_Data -( - id varchar2(36) DEFAULT sys_guid() NOT NULL, - profile_id varchar2(36) NOT NULL, - profile_data_Id varchar2(36) NOT NULL, - content varchar2(200) NOT NULL, - created_at date NOT NULL, - created_by varchar2(36) NOT NULL, - modified_at date NULL, - modified_by varchar2(36) NULL, - CONSTRAINT Profile_User_Data_pk PRIMARY KEY (id) + CONSTRAINT Profile_Pictures_pk PRIMARY KEY (id), + CONSTRAINT Profile_Pictures_is_current_pp_ch CHECK (is_current_pp IN (0, 1)) ); -- Table: Profiles diff --git a/database/scripts/130_grant_references.sql b/database/scripts/130_grant_references.sql index cdc0ccf..60e1cd3 100644 --- a/database/scripts/130_grant_references.sql +++ b/database/scripts/130_grant_references.sql @@ -4,10 +4,4 @@ GRANT REFERENCES ON mh_users.users TO mh_posts; GRANT REFERENCES ON mh_users.users TO mh_groups; GRANT REFERENCES ON mh_users.users TO mh_user_relations; GRANT REFERENCES ON mh_users.users TO mh_matching; -GRANT REFERENCES ON mh_users.users TO mh_profiles; - --- grant references to users.pictures -GRANT REFERENCES ON mh_users.pictures TO mh_profiles; -GRANT REFERENCES ON mh_users.pictures TO mh_matching; -GRANT REFERENCES ON mh_users.pictures TO mh_posts; -GRANT REFERENCES ON mh_users.pictures TO mh_groups; \ No newline at end of file +GRANT REFERENCES ON mh_users.users TO mh_profiles; \ No newline at end of file diff --git a/database/scripts/140_create_references.sql b/database/scripts/140_create_references.sql index fc9c647..ca71f1a 100644 --- a/database/scripts/140_create_references.sql +++ b/database/scripts/140_create_references.sql @@ -69,12 +69,6 @@ ALTER TABLE mh_groups.Groupchat_messages FOREIGN KEY (answered_message_id) REFERENCES mh_groups.Groupchat_messages (id); --- Reference: Groups_Pictures (table: Groups) -ALTER TABLE mh_groups.Groups - ADD CONSTRAINT Groups_Pictures - FOREIGN KEY (picture_id) - REFERENCES mh_users.Pictures (id); - -- Reference: User_Groups_Groups (table: User_Groups) ALTER TABLE mh_groups.User_Groups ADD CONSTRAINT User_Groups_Groups @@ -130,12 +124,6 @@ ALTER TABLE mh_matching.Matching_Chats FOREIGN KEY (sender_id) REFERENCES mh_matching.Matching_Profiles (id); --- Reference: Matching_Profile_Pictures (table: Matching_Profile_Pictures) -ALTER TABLE mh_matching.Matching_Profile_Pictures - ADD CONSTRAINT Matching_Profile_Pictures - FOREIGN KEY (picture_id) - REFERENCES mh_users.Pictures (id); - -- Reference: Matching_Profile_Pictures_MP (table: Matching_Profile_Pictures) ALTER TABLE mh_matching.Matching_Profile_Pictures ADD CONSTRAINT Matching_Profile_Pictures_MP @@ -149,11 +137,6 @@ ALTER TABLE mh_matching.Matching_Profiles REFERENCES mh_users.Users (id); ---------------------------------------- || MH_USERS SCHEMA || ---------------------------------------- --- Reference: Pictures_Users (table: Pictures) -ALTER TABLE mh_users.Pictures - ADD CONSTRAINT Pictures_Users - FOREIGN KEY (user_id) - REFERENCES mh_users.Users (id); -- Reference: User_tokens_Users (table: User_tokens) ALTER TABLE mh_users.User_tokens @@ -192,11 +175,6 @@ ALTER TABLE mh_users.Users REFERENCES mh_users.Roles (id); ---------------------------------------- || MH_POSTS SCHEMA || ---------------------------------------- --- Reference: Posts_Pictures_Pictures (table: Post_Pictures) -ALTER TABLE mh_posts.Post_Pictures - ADD CONSTRAINT Posts_Pictures_Pictures - FOREIGN KEY (picture_id) - REFERENCES mh_users.Pictures (id); -- Reference: Posts_Pictures_Posts (table: Post_Pictures) ALTER TABLE mh_posts.Post_Pictures @@ -211,11 +189,6 @@ ALTER TABLE mh_posts.Posts REFERENCES mh_users.Users (id); ---------------------------------------- || MH_PROFILES SCHEMA || ---------------------------------------- --- Reference: Profile_Pictures_Pictures (table: Profile_Pictures) -ALTER TABLE mh_profiles.Profile_Pictures - ADD CONSTRAINT Profile_Pictures_Pictures - FOREIGN KEY (picture_id) - REFERENCES mh_users.Pictures (id); -- Reference: Profile_Pictures_Profiles (table: Profile_Pictures) ALTER TABLE mh_profiles.Profile_Pictures @@ -223,18 +196,6 @@ ALTER TABLE mh_profiles.Profile_Pictures FOREIGN KEY (profile_id) REFERENCES mh_profiles.Profiles (id); --- Reference: Profile_User_Data_Profile_Data (table: Profile_User_Data) -ALTER TABLE mh_profiles.Profile_User_Data - ADD CONSTRAINT Profile_User_Data_Profile_Data - FOREIGN KEY (profile_data_Id) - REFERENCES mh_profiles.Profile_Data (id); - --- Reference: Profile_User_Data_Profiles (table: Profile_User_Data) -ALTER TABLE mh_profiles.Profile_User_Data - ADD CONSTRAINT Profile_User_Data_Profiles - FOREIGN KEY (profile_id) - REFERENCES mh_profiles.Profiles (id); - -- Reference: Profiles_Users (table: Profiles) ALTER TABLE mh_profiles.Profiles ADD CONSTRAINT Profiles_Users diff --git a/database/scripts/150_grant_permissions_to_meowhub.sql b/database/scripts/150_grant_permissions_to_meowhub.sql index f73a5a1..79d7f00 100644 --- a/database/scripts/150_grant_permissions_to_meowhub.sql +++ b/database/scripts/150_grant_permissions_to_meowhub.sql @@ -21,7 +21,6 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON mh_users.privacy_settings TO mh_meowhub; GRANT SELECT, INSERT, UPDATE, DELETE ON mh_users.user_tokens TO mh_meowhub; GRANT SELECT, INSERT, UPDATE, DELETE ON mh_users.roles TO mh_meowhub; GRANT SELECT, INSERT, UPDATE, DELETE ON mh_users.genders TO mh_meowhub; -GRANT SELECT, INSERT, UPDATE, DELETE ON mh_users.pictures TO mh_meowhub; GRANT SELECT ON mh_users.h_users TO mh_meowhub; --user_relations @@ -29,8 +28,6 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON mh_user_relations.relation_types TO mh_m GRANT SELECT, INSERT, UPDATE, DELETE ON mh_user_relations.user_relations TO mh_meowhub; --profiles -GRANT SELECT, INSERT, UPDATE, DELETE ON mh_profiles.profile_data TO mh_meowhub; -GRANT SELECT, INSERT, UPDATE, DELETE ON mh_profiles.profile_user_data TO mh_meowhub; GRANT SELECT, INSERT, UPDATE, DELETE ON mh_profiles.profiles TO mh_meowhub; GRANT SELECT, INSERT, UPDATE, DELETE ON mh_profiles.profile_pictures TO mh_meowhub; diff --git a/database/scripts/160_create_indexes.sql b/database/scripts/160_create_indexes.sql index 829776a..fc84717 100644 --- a/database/scripts/160_create_indexes.sql +++ b/database/scripts/160_create_indexes.sql @@ -62,36 +62,13 @@ CREATE INDEX mh_matching.Matching_Chats_receiver_id_idx (receiver_id ASC) ; --- Table: mh_matching.Matching_Profile_Pictures -CREATE INDEX mh_matching.Match_Pr_Pict_match_pr_id_idx - on mh_matching.Matching_Profile_Pictures - (matching_profile_id ASC) -; - -CREATE INDEX mh_matching.Match_Pr_Pic_pic_id_idx - on mh_matching.Matching_Profile_Pictures - (picture_id ASC) -; - -- Table: mh_matching.Matching_Profiles CREATE INDEX mh_matching.Matching_Profiles_user_id_idx on mh_matching.Matching_Profiles (user_id ASC) ; ----------------------------------------- || MH_USERS SCHEMA || ---------------------------------------- --- Table: mh_users.Pictures -CREATE INDEX Pictures_user_id_idx - on mh_users.Pictures - (user_id ASC) -; - ---------------------------------------- || MH_PROFILES SCHEMA || ---------------------------------------- --- Table: mh_profiles.Profile_User_Data -CREATE INDEX mh_profiles.Pr_User_Data_profile_id_idx - on mh_profiles.Profile_User_Data - (profile_id ASC) -; -- Table: mh_profiles.Profiles CREATE INDEX mh_profiles.Profiles_user_id_idx diff --git a/database/scripts/400_create_audit_triggers.sql b/database/scripts/400_create_audit_triggers.sql index 6cd52bb..00727d1 100644 --- a/database/scripts/400_create_audit_triggers.sql +++ b/database/scripts/400_create_audit_triggers.sql @@ -199,36 +199,6 @@ BEGIN END; / -CREATE OR REPLACE TRIGGER mh_profiles.profile_data_audit_trg - BEFORE INSERT OR UPDATE - ON mh_profiles.profile_data - FOR EACH ROW -BEGIN - IF INSERTING THEN - :NEW.created_at := CURRENT_TIMESTAMP; - :NEW.created_by := mh_meowhub.get_user_id; - ELSIF UPDATING THEN - :NEW.modified_at := CURRENT_TIMESTAMP; - :NEW.modified_by := mh_meowhub.get_user_id; - END IF; -END; -/ - -CREATE OR REPLACE TRIGGER mh_profiles.profile_user_data_audit_trg - BEFORE INSERT OR UPDATE - ON mh_profiles.profile_user_data - FOR EACH ROW -BEGIN - IF INSERTING THEN - :NEW.created_at := CURRENT_TIMESTAMP; - :NEW.created_by := mh_meowhub.get_user_id; - ELSIF UPDATING THEN - :NEW.modified_at := CURRENT_TIMESTAMP; - :NEW.modified_by := mh_meowhub.get_user_id; - END IF; -END; -/ - ---------------------------------------- || MH_GROUPS SCHEMA AUDIT TRIGGERS || ---------------------------------------- CREATE OR REPLACE TRIGGER mh_groups.groups_audit_trg BEFORE INSERT OR UPDATE diff --git a/database/scripts/510_insert_mock_data.sql b/database/scripts/510_insert_mock_data.sql deleted file mode 100644 index 7da419c..0000000 --- a/database/scripts/510_insert_mock_data.sql +++ /dev/null @@ -1,68 +0,0 @@ - -DECLARE - l_user_id VARCHAR2(36); - l_admin_id VARCHAR2(36); - l_relation_type_friends_id VARCHAR2(36); -BEGIN - --get needed id's - - SELECT id - INTO l_user_id - FROM mh_users.users - WHERE login = 'user1'; - - SELECT id - INTO l_admin_id - FROM mh_users.users - WHERE login = 'admin'; - - SELECT id - INTO l_relation_type_friends_id - FROM mh_user_relations.relation_types - WHERE code = 'FRIENDS'; - ---mh_users.pictures - INSERT INTO mh_users.pictures (id, user_id, picture) - VALUES (1, l_user_id, UTL_RAW.CAST_TO_RAW('9ffdc87faedbe...b27777ce')); -- Skrócona treść pliku - - INSERT INTO mh_users.pictures (id, user_id, picture) - VALUES (2, l_admin_id, UTL_RAW.CAST_TO_RAW('1ffdc87faedbe...b27777ce')); -- Skrócona treść pliku - ---mh_posts.posts - INSERT INTO mh_posts.posts (id, user_id, content_html) VALUES (1, l_user_id, 'Hello world from user - 1'); - INSERT INTO mh_posts.posts (id, user_id, content_html) VALUES (2, l_admin_id, 'Hello world from admin - 1'); - INSERT INTO mh_posts.posts (id, user_id, content_html) VALUES (3, l_admin_id, 'Hello world from admin - 2'); - ---mh_posts.post_pictures - INSERT INTO mh_posts.post_pictures (id, post_id, picture_id, picture_index) VALUES (1, 1, 1, 0); - ---mh_posts.comments - INSERT INTO mh_posts.comments (id, post_id, user_id, answered_comment_id, content) VALUES (1, 3, l_user_id, NULL, 'Nice post'); - INSERT INTO mh_posts.comments (id, post_id, user_id, answered_comment_id, content) VALUES (2, 3, l_user_id, 1, 'Yeah, I agree'); - ---mh_profiles.profiles - INSERT INTO mh_profiles.profiles (id, user_id, profile_details_html) VALUES (1, l_user_id, 'Hello this is my profile'); - INSERT INTO mh_profiles.profiles (id, user_id, profile_details_html) VALUES (2, l_admin_id, 'ADMIN is my name, and this is my profile:D'); - - ---mh_profiles.profile_pictures - INSERT INTO mh_profiles.profile_pictures (id, profile_id, picture_id, picture_index) VALUES (1, 2, 2, 0); - ---mh_profiles.profile_data - INSERT INTO mh_profiles.profile_data (id, code) VALUES (1, 'Urodzony w:'); - INSERT INTO mh_profiles.profile_data (id, code) VALUES (2, 'W relacji:'); - ---mh_profiles.profile_user_data - INSERT INTO mh_profiles.profile_user_data (id, profile_id, profile_data_id, content) - VALUES (1, 1, 1, 'Warszawa'); - - INSERT INTO mh_profiles.profile_user_data (id, profile_id, profile_data_id, content) - VALUES (2, 1, 1, 'Wolny'); - ---mh_user_relations.user_relations - INSERT INTO mh_user_relations.user_relations (id, sender_id, receiver_id, relation_type_id, send_date) - VALUES (1, l_user_id, l_admin_id, l_relation_type_friends_id, TO_TIMESTAMP('2024-12-29 12:00:00', 'YYYY-MM-DD HH24:MI:SS')); - - COMMIT; - -END;