Skip to content

Commit 90972e4

Browse files
committed
server: fix migration to spring 4
1 parent 7349335 commit 90972e4

40 files changed

Lines changed: 53 additions & 54 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Fri Oct 30 13:18:19 MSK 2020
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

01_di/server/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ dependencies {
2121
implementation("com.github.javafaker:javafaker:1.0.2") {
2222
exclude(module = "snakeyaml")
2323
}
24-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
2524
implementation("org.jetbrains.kotlin:kotlin-reflect")
2625
implementation("org.apache.tika:tika-core:3.2.3")
2726
implementation("com.google.firebase:firebase-admin:9.7.0")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

01_di/server/src/main/kotlin/ru/netology/nmedia/entity/UserEntity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ data class UserEntity(
2525
override fun isCredentialsNonExpired(): Boolean = true
2626
override fun isEnabled(): Boolean = true
2727

28-
fun toDto() = User(id, login, name, avatar, authorities.map(GrantedAuthority::getAuthority))
28+
fun toDto() = User(id, login, name, avatar, authorities.mapNotNull(GrantedAuthority::getAuthority))
2929
}

01_di/server/src/main/kotlin/ru/netology/nmedia/extensions/Security.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package ru.netology.nmedia.extensions
33
import org.springframework.security.core.context.SecurityContextHolder
44
import ru.netology.nmedia.dto.User
55

6-
fun principal() = SecurityContextHolder.getContext().authentication.principal as User
7-
fun principalOrNull() = SecurityContextHolder.getContext()?.authentication?.principal as? User?
6+
fun principal() = requireNotNull(SecurityContextHolder.getContext().authentication).principal as User
7+
fun principalOrNull() = SecurityContextHolder.getContext().authentication?.principal as? User?

01_di/server/src/main/kotlin/ru/netology/nmedia/service/PostService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PostService(
5757
likedByMe = false,
5858
published = OffsetDateTime.now().toEpochSecond()
5959
)
60-
).copy(author = userRepository.getById(principal.id))
60+
).copy(author = userRepository.getReferenceById(principal.id))
6161
)
6262
.let {
6363
if (it.author.id != principal.id) {

01_di/server/src/main/kotlin/ru/netology/nmedia/service/PushService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package ru.netology.nmedia.service
22

3-
import com.fasterxml.jackson.databind.ObjectMapper
43
import com.google.firebase.messaging.FirebaseMessaging
54
import com.google.firebase.messaging.Message
65
import jakarta.transaction.Transactional
76
import org.springframework.context.annotation.Lazy
87
import org.springframework.stereotype.Service
98
import ru.netology.nmedia.dto.PushMessage
109
import ru.netology.nmedia.repository.PushTokenRepository
10+
import tools.jackson.databind.ObjectMapper
1111

1212
@Service
1313
@Transactional

01_di/server/src/main/kotlin/ru/netology/nmedia/service/ScheduledPostGeneratorService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ScheduledPostGeneratorService(
1616

1717
@Scheduled(initialDelay = 60 * 1000, fixedRate = 5 * 60 * 1000)
1818
fun generate() {
19-
val user = userService.getByLogin("got")
19+
val user = userService.getByLogin("got") ?: return
2020

2121
postService.saveInitial(
2222
Post(

01_di/server/src/main/kotlin/ru/netology/nmedia/service/UserService.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class UserService(
3737
UserEntity(
3838
0L,
3939
login,
40-
passwordEncoder.encode(pass),
40+
requireNotNull(passwordEncoder.encode(pass)),
4141
name,
4242
avatar,
4343
)
@@ -56,7 +56,7 @@ class UserService(
5656
UserEntity(
5757
0L,
5858
login,
59-
passwordEncoder.encode(pass),
59+
requireNotNull(passwordEncoder.encode(pass)),
6060
name,
6161
avatar?.id ?: "", // TODO:
6262
)
@@ -78,16 +78,16 @@ class UserService(
7878
token
7979
} ?: throw NotFoundException()
8080

81-
fun getByLogin(login: String): User = userRepository
81+
fun getByLogin(login: String): User? = userRepository
8282
.findByLogin(login)
83-
?.toDto() ?: throw NotFoundException()
83+
?.toDto()
8484

8585
fun getByToken(token: String): User? = tokenRepository
8686
.findByIdOrNull(token)
8787
?.user
8888
?.toDto()
8989

90-
override fun loadUserByUsername(username: String?): UserDetails =
90+
override fun loadUserByUsername(username: String): UserDetails =
9191
userRepository.findByLogin(username) ?: throw UsernameNotFoundException(username)
9292

9393
fun saveInitialToken(userId: Long, value: String): Token =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Mon Feb 07 20:04:31 NOVT 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)