diff --git a/README.md b/README.md index f236ed5..01d6cef 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,20 @@ Engineering Thesis For production environment, you need to have an oracle database. If you don't have a created an oracle database yet, run script `database/install.sql`. + ## Profiles -`swagger` - to run application with Swagger +`swagger` - to run application with Swagger +`dev` - to run application with H2 database (for offline development) ## Swagger To run swagger use `swagger` profile. Link to swagger documentation: http://localhost:8080/swagger-ui/index.html +## Offline development && Testing +To develop application offline please use `dev` profile - it uses h2 database instead of oracle database that is used on production. +img.png +No other configurations are needed. + ## Environment variables `DB_URL` - database url `DB_USERNAME` - database username diff --git a/backend/src/main/java/meowhub/backend/security/SecurityConfig.java b/backend/src/main/java/meowhub/backend/security/SecurityConfig.java index 8330beb..0c3644e 100644 --- a/backend/src/main/java/meowhub/backend/security/SecurityConfig.java +++ b/backend/src/main/java/meowhub/backend/security/SecurityConfig.java @@ -70,9 +70,21 @@ public CommandLineRunner initData(RoleRepository roleRepository, UserRepository PrivacySetting publicSetting = privacySettingRepository.findByCode(PrivacySettings.PUBLIC.name()) .orElseGet(() -> privacySettingRepository.save(new PrivacySetting(PrivacySettings.PUBLIC))); + PrivacySetting privateSetting = privacySettingRepository.findByCode(PrivacySettings.PRIVATE.name()) + .orElseGet(() -> privacySettingRepository.save(new PrivacySetting(PrivacySettings.PRIVATE))); + + PrivacySetting friendsOnlySetting = privacySettingRepository.findByCode(PrivacySettings.FRIENDS_ONLY.name()) + .orElseGet(() -> privacySettingRepository.save(new PrivacySetting(PrivacySettings.FRIENDS_ONLY))); + Gender female = genderRepository.findByCode(Genders.FEMALE.name()) .orElseGet(() -> genderRepository.save(new Gender(Genders.FEMALE))); + Gender male = genderRepository.findByCode(Genders.MALE.name()) + .orElseGet(() -> genderRepository.save(new Gender(Genders.MALE))); + + Gender other = genderRepository.findByCode(Genders.OTHER.name()) + .orElseGet(() -> genderRepository.save(new Gender(Genders.OTHER))); + if (!userRepository.existsByLogin("user1")) { User user1 = new User(); user1.setLogin("user1"); @@ -88,7 +100,7 @@ public CommandLineRunner initData(RoleRepository roleRepository, UserRepository user1.setPostsPrivacy(publicSetting); user1.setFriendsPrivacy(publicSetting); user1.setProfilePrivacy(publicSetting); - user1.setGender(female); + user1.setGender(male); userRepository.save(user1); } @@ -107,7 +119,7 @@ public CommandLineRunner initData(RoleRepository roleRepository, UserRepository admin.setPostsPrivacy(publicSetting); admin.setFriendsPrivacy(publicSetting); admin.setProfilePrivacy(publicSetting); - admin.setGender(female); + admin.setGender(male); userRepository.save(admin); } diff --git a/backend/src/main/resources/application-dev.properties b/backend/src/main/resources/application-dev.properties new file mode 100644 index 0000000..4115c6f --- /dev/null +++ b/backend/src/main/resources/application-dev.properties @@ -0,0 +1,19 @@ +spring.datasource.url=jdbc:h2:file:./data/devdb;DB_CLOSE_DELAY=-1;AUTO_SERVER=TRUE +spring.datasource.driver-class-name=org.h2.Driver + +spring.datasource.username=sa +spring.datasource.password= +spring.jpa.hibernate.ddl-auto=update +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + + +spring.sql.init.mode=always +spring.sql.init.schema-locations=classpath:data/create_schemas_h2.sql + +spring.app.jwtSecret=mySecretKey134567854345671693872934523452436235234523451412432342341534524352346 +spring.app.jwtExpirationMs=17280000 + +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.springframework.jdbc=DEBUG +logging.level.org.springframework.orm.jpa=DEBUG diff --git a/backend/src/main/resources/data/create_schemas_h2.sql b/backend/src/main/resources/data/create_schemas_h2.sql new file mode 100644 index 0000000..a869565 --- /dev/null +++ b/backend/src/main/resources/data/create_schemas_h2.sql @@ -0,0 +1,7 @@ +CREATE SCHEMA IF NOT EXISTS MH_USERS; +CREATE SCHEMA IF NOT EXISTS MH_CHATS; +CREATE SCHEMA IF NOT EXISTS MH_MATCHING; +CREATE SCHEMA IF NOT EXISTS MH_POSTS; +CREATE SCHEMA IF NOT EXISTS MH_PROFILES; +CREATE SCHEMA IF NOT EXISTS MH_GROUPS; +CREATE SCHEMA IF NOT EXISTS MH_USER_RELATIONS; \ No newline at end of file diff --git a/backend/src/test/java/meowhub/backend/InitDataTestConfig.java b/backend/src/test/java/meowhub/backend/InitDataTestConfig.java index b2158f4..3242f18 100644 --- a/backend/src/test/java/meowhub/backend/InitDataTestConfig.java +++ b/backend/src/test/java/meowhub/backend/InitDataTestConfig.java @@ -93,7 +93,6 @@ private void initUser() { user1.setEmail("admin1@example.com"); user1.setName("Jan"); user1.setSurname("Kos"); - user1.setSalt("salt"); user1.setAccountNonLocked(false); user1.setBirthdate(LocalDate.of(1990, 1, 1)); user1.setCredentialsNonExpired(true); @@ -111,7 +110,6 @@ private void initUser() { user2.setEmail("user1@example.com"); user2.setName("Gustaw"); user2.setSurname("Jeleń"); - user2.setSalt("salt"); user2.setAccountNonLocked(false); user2.setBirthdate(LocalDate.of(1991, 11, 11)); user2.setCredentialsNonExpired(true); @@ -129,7 +127,6 @@ private void initUser() { user3.setEmail("grzegorz@example.com"); user3.setName("Grzegorz"); user3.setSurname("Saakaszwili"); - user3.setSalt("salt"); user3.setAccountNonLocked(false); user3.setBirthdate(LocalDate.of(1991, 11, 11)); user3.setCredentialsNonExpired(true); diff --git a/img.png b/img.png new file mode 100644 index 0000000..90e05d9 Binary files /dev/null and b/img.png differ