-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IL-63][issue-4] Hibernate issue with authorities save and fixed issue with registration response #98
Merged
Sunagatov
merged 10 commits into
Sunagatov:development
from
Reyzis2021:bugfix/Issue-4/Hibernate_issue_with_authorities_save
Sep 24, 2023
Merged
[IL-63][issue-4] Hibernate issue with authorities save and fixed issue with registration response #98
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3771ec4
Fixed repeat registration case with same user
Reyzis2021 757e431
Fixed Hibernate issue with authorities saving
Reyzis2021 c5d024e
Fixed Hibernate issue with authorities saving part.2
Reyzis2021 639b00d
Fixed Hibernate issue with authorities saving part.2
Reyzis2021 308d9a0
Merge branch 'development' into bugfix/Issue-4/Hibernate_issue_with_a…
Reyzis2021 62d0db9
Merge branch 'development' into bugfix/Issue-4/Hibernate_issue_with_a…
Reyzis2021 a7332cc
Merge branch 'development' into bugfix/Issue-4/Hibernate_issue_with_a…
Reyzis2021 fd4fe55
Fixed Hibernate issue with authorities saving part.3
Reyzis2021 ce6100f
Merge branch 'development' into bugfix/Issue-4/Hibernate_issue_with_a…
Reyzis2021 89e6788
Fixed Hibernate issue with authorities saving part.4
Reyzis2021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/zufar/onlinestore/common/validation/annotation/UniqueEmail.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,26 @@ | ||
package com.zufar.onlinestore.common.validation.annotation; | ||
|
||
import com.zufar.onlinestore.common.validation.validator.UniqueEmailValidator; | ||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Target({ FIELD }) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = UniqueEmailValidator.class) | ||
@Documented | ||
public @interface UniqueEmail { | ||
|
||
String message() default ""; | ||
|
||
Class<?>[] groups() default { }; | ||
|
||
Class<? extends Payload>[] payload() default { }; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/zufar/onlinestore/common/validation/annotation/UniqueUsername.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 com.zufar.onlinestore.common.validation.annotation; | ||
|
||
import com.zufar.onlinestore.common.validation.validator.UniqueUsernameValidator; | ||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Target({ FIELD }) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = UniqueUsernameValidator.class) | ||
@Documented | ||
public @interface UniqueUsername { | ||
|
||
String message() default ""; | ||
|
||
Class<?>[] groups() default { }; | ||
|
||
Class<? extends Payload>[] payload() default { }; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/zufar/onlinestore/common/validation/validator/UniqueEmailValidator.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,22 @@ | ||
package com.zufar.onlinestore.common.validation.validator; | ||
|
||
import com.zufar.onlinestore.user.repository.UserRepository; | ||
import com.zufar.onlinestore.common.validation.annotation.UniqueEmail; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class UniqueEmailValidator implements ConstraintValidator<UniqueEmail, String> { | ||
|
||
private final UserRepository userCrudRepository; | ||
|
||
@Override | ||
public boolean isValid(String email, ConstraintValidatorContext constraintValidatorContext) { | ||
return userCrudRepository | ||
.findByEmail(email) | ||
.isEmpty(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/zufar/onlinestore/common/validation/validator/UniqueUsernameValidator.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,20 @@ | ||
package com.zufar.onlinestore.common.validation.validator; | ||
|
||
import com.zufar.onlinestore.common.validation.annotation.UniqueUsername; | ||
import com.zufar.onlinestore.user.repository.UserRepository; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class UniqueUsernameValidator implements ConstraintValidator<UniqueUsername, String> { | ||
|
||
private final UserRepository userCrudRepository; | ||
|
||
@Override | ||
public boolean isValid(String username, ConstraintValidatorContext constraintValidatorContext) { | ||
return userCrudRepository.findUserByUsername(username) == null; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/zufar/onlinestore/user/api/AuthorityService.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 com.zufar.onlinestore.user.api; | ||
|
||
import com.zufar.onlinestore.user.entity.Authority; | ||
import com.zufar.onlinestore.user.entity.UserEntity; | ||
import com.zufar.onlinestore.user.entity.UserGrantedAuthority; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AuthorityService { | ||
|
||
public void setDefaultAuthority(UserEntity savedUserEntity) { | ||
UserGrantedAuthority defaultAuthority = UserGrantedAuthority | ||
.builder() | ||
.authority(Authority.USER) | ||
.build(); | ||
|
||
savedUserEntity.addAuthority(defaultAuthority); | ||
} | ||
} |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefaultUserAuthoritySetter
sound clearerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this service may have a greater responsibility than setting the default role