Skip to content

Commit

Permalink
feature: dev profile, to enable offline work on the project
Browse files Browse the repository at this point in the history
Task: 86977q49u
  • Loading branch information
KinTrae committed Dec 27, 2024
1 parent cadbb52 commit 4622539
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 alt="img.png" height="300" src="img.png" width="500"/>
No other configurations are needed.

## Environment variables
`DB_URL` - database url
`DB_USERNAME` - database username
Expand Down
16 changes: 14 additions & 2 deletions backend/src/main/java/meowhub/backend/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
19 changes: 19 additions & 0 deletions backend/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions backend/src/main/resources/data/create_schemas_h2.sql
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 0 additions & 3 deletions backend/src/test/java/meowhub/backend/InitDataTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ private void initUser() {
user1.setEmail("[email protected]");
user1.setName("Jan");
user1.setSurname("Kos");
user1.setSalt("salt");
user1.setAccountNonLocked(false);
user1.setBirthdate(LocalDate.of(1990, 1, 1));
user1.setCredentialsNonExpired(true);
Expand All @@ -111,7 +110,6 @@ private void initUser() {
user2.setEmail("[email protected]");
user2.setName("Gustaw");
user2.setSurname("Jeleń");
user2.setSalt("salt");
user2.setAccountNonLocked(false);
user2.setBirthdate(LocalDate.of(1991, 11, 11));
user2.setCredentialsNonExpired(true);
Expand All @@ -129,7 +127,6 @@ private void initUser() {
user3.setEmail("[email protected]");
user3.setName("Grzegorz");
user3.setSurname("Saakaszwili");
user3.setSalt("salt");
user3.setAccountNonLocked(false);
user3.setBirthdate(LocalDate.of(1991, 11, 11));
user3.setCredentialsNonExpired(true);
Expand Down
Binary file added img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4622539

Please sign in to comment.