-
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.
Merge pull request #148 from Tech-Harbor/Bezsmertnyi
Bezsmertnyi
- Loading branch information
Showing
19 changed files
with
118 additions
and
98 deletions.
There are no files selected for viewing
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
27 changes: 14 additions & 13 deletions
27
src/main/java/com/example/backend/utils/general/Helpers.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 |
---|---|---|
@@ -1,36 +1,37 @@ | ||
package com.example.backend.utils.general; | ||
|
||
|
||
import com.example.backend.security.servers.JwtServer; | ||
import com.example.backend.web.User.UserServer; | ||
import com.example.backend.web.User.UserRepository; | ||
import com.example.backend.web.User.store.UserEntity; | ||
import org.springframework.context.annotation.Lazy; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.example.backend.utils.exception.RequestException.badRequestException; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class Helpers { | ||
|
||
private final UserRepository userRepository; | ||
private final JwtServer jwtServer; | ||
private final UserServer userServer; | ||
|
||
public Helpers(final @Lazy JwtServer jwtServer, | ||
final @Lazy UserServer userServer) { | ||
this.jwtServer = jwtServer; | ||
this.userServer = userServer; | ||
} | ||
|
||
|
||
public UserEntity tokenUserData(final String jwt) { | ||
final var token = jwtServer.extractUserData(jwt.substring(7)); | ||
|
||
return userServer.getByUserData(token); | ||
return getByUserData(token); | ||
} | ||
|
||
public Optional<UserEntity> tokenUserEmail(final String jwt) { | ||
final var token = jwtServer.extractUserData(jwt.substring(7)); | ||
|
||
return userServer.getByEmail(token); | ||
return userRepository.findByEmail(token); | ||
} | ||
|
||
private UserEntity getByUserData(final String userData) { | ||
return userRepository.findByEmail(userData).orElseThrow( | ||
() -> badRequestException("Not userData: " + userData) | ||
); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/backend/utils/mapper/AdvertisementBaseMapper.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.example.backend.utils.mapper; | ||
|
||
import com.example.backend.web.Advertisement.store.AdvertisementEntity; | ||
import com.example.backend.web.Advertisement.store.dto.AdvertisementDTO; | ||
import com.example.backend.web.Advertisement.store.mapper.AdvertisementMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.mapstruct.Named; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Named("AdvertisementBaseMapper") | ||
public class AdvertisementBaseMapper { | ||
|
||
private final AdvertisementMapper advertisementMapper; | ||
|
||
@Named("getAllAdvertisements") | ||
public List<AdvertisementDTO> getAllAdvertisements(final List<AdvertisementEntity> advertisement) { | ||
return Collections.singletonList(advertisementMapper | ||
.advertisementMapperDTO((AdvertisementEntity) advertisement) | ||
); | ||
} | ||
} |
16 changes: 2 additions & 14 deletions
16
...ple/backend/utils/general/BaseMapper.java → ...mple/backend/utils/mapper/BaseMapper.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
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
Oops, something went wrong.