-
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.
- Loading branch information
Showing
15 changed files
with
264 additions
and
13 deletions.
There are no files selected for viewing
8 changes: 7 additions & 1 deletion
8
botalka/src/main/kotlin/ru/vityaman/lms/botalka/app/spring/logic/SpringHomeworkService.kt
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,11 +1,17 @@ | ||
package ru.vityaman.lms.botalka.app.spring.logic | ||
|
||
import org.springframework.stereotype.Service | ||
import ru.vityaman.lms.botalka.core.logging.Slf4jLog | ||
import ru.vityaman.lms.botalka.core.logic.HomeworkService | ||
import ru.vityaman.lms.botalka.core.logic.basic.BasicHomeworkService | ||
import ru.vityaman.lms.botalka.core.logic.logging.LoggingHomeworkService | ||
import ru.vityaman.lms.botalka.core.storage.HomeworkStorage | ||
|
||
@Service | ||
class SpringHomeworkService( | ||
storage: HomeworkStorage, | ||
) : HomeworkService by BasicHomeworkService(storage) | ||
) : HomeworkService by | ||
LoggingHomeworkService( | ||
Slf4jLog("HomeworkService"), | ||
BasicHomeworkService(storage), | ||
) |
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
8 changes: 7 additions & 1 deletion
8
botalka/src/main/kotlin/ru/vityaman/lms/botalka/app/spring/logic/SpringRatingService.kt
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,11 +1,17 @@ | ||
package ru.vityaman.lms.botalka.app.spring.logic | ||
|
||
import org.springframework.stereotype.Service | ||
import ru.vityaman.lms.botalka.core.logging.Slf4jLog | ||
import ru.vityaman.lms.botalka.core.logic.RatingService | ||
import ru.vityaman.lms.botalka.core.logic.WorkspaceService | ||
import ru.vityaman.lms.botalka.core.logic.basic.BasicRatingService | ||
import ru.vityaman.lms.botalka.core.logic.logging.LoggingRatingService | ||
|
||
@Service | ||
class SpringRatingService( | ||
workspaces: WorkspaceService, | ||
) : RatingService by BasicRatingService(workspaces) | ||
) : RatingService by | ||
LoggingRatingService( | ||
Slf4jLog("RatingService"), | ||
BasicRatingService(workspaces), | ||
) |
8 changes: 7 additions & 1 deletion
8
botalka/src/main/kotlin/ru/vityaman/lms/botalka/app/spring/logic/SpringUserService.kt
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,11 +1,17 @@ | ||
package ru.vityaman.lms.botalka.app.spring.logic | ||
|
||
import org.springframework.stereotype.Service | ||
import ru.vityaman.lms.botalka.core.logging.Slf4jLog | ||
import ru.vityaman.lms.botalka.core.logic.UserService | ||
import ru.vityaman.lms.botalka.core.logic.basic.BasicUserService | ||
import ru.vityaman.lms.botalka.core.logic.logging.LoggingUserService | ||
import ru.vityaman.lms.botalka.core.storage.UserStorage | ||
|
||
@Service | ||
class SpringUserService( | ||
storage: UserStorage, | ||
) : UserService by BasicUserService(storage) | ||
) : UserService by | ||
LoggingUserService( | ||
Slf4jLog("UserService"), | ||
BasicUserService(storage), | ||
) |
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
6 changes: 6 additions & 0 deletions
6
botalka/src/main/kotlin/ru/vityaman/lms/botalka/core/logging/Log.kt
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,6 @@ | ||
package ru.vityaman.lms.botalka.core.logging | ||
|
||
interface Log { | ||
fun info(message: String) | ||
fun warn(message: String) | ||
} |
15 changes: 15 additions & 0 deletions
15
botalka/src/main/kotlin/ru/vityaman/lms/botalka/core/logging/Slf4jLog.kt
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,15 @@ | ||
package ru.vityaman.lms.botalka.core.logging | ||
|
||
import org.slf4j.LoggerFactory | ||
|
||
class Slf4jLog(name: String) : Log { | ||
private val origin = LoggerFactory.getLogger(name) | ||
|
||
override fun info(message: String) { | ||
origin.info(message) | ||
} | ||
|
||
override fun warn(message: String) { | ||
origin.warn(message) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
botalka/src/main/kotlin/ru/vityaman/lms/botalka/core/logic/logging/LoggingAuthService.kt
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 ru.vityaman.lms.botalka.core.logic.logging | ||
|
||
import ru.vityaman.lms.botalka.core.logging.Log | ||
import ru.vityaman.lms.botalka.core.logic.AuthService | ||
import ru.vityaman.lms.botalka.core.model.AuthUser | ||
import ru.vityaman.lms.botalka.core.model.User | ||
import ru.vityaman.lms.botalka.core.security.auth.AccessToken | ||
|
||
class LoggingAuthService<T>( | ||
private val log: Log, | ||
private val origin: AuthService<T>, | ||
) : AuthService<T> { | ||
override suspend fun signUp(draft: User.Draft, credentials: T): AuthUser = | ||
runCatching { origin.signUp(draft, credentials) } | ||
.onSuccess { log.info("User with ${it.user.id} signed up") } | ||
.onFailure { log.warn("Failed to sign up") } | ||
.getOrThrow() | ||
|
||
override suspend fun signIn(credentials: T): AccessToken = | ||
runCatching { origin.signIn(credentials) } | ||
.onSuccess { log.info("Signed in") } | ||
.onFailure { log.warn("Failed to sign in") } | ||
.getOrThrow() | ||
} |
23 changes: 23 additions & 0 deletions
23
botalka/src/main/kotlin/ru/vityaman/lms/botalka/core/logic/logging/LoggingHomeworkService.kt
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,23 @@ | ||
package ru.vityaman.lms.botalka.core.logic.logging | ||
|
||
import ru.vityaman.lms.botalka.core.logging.Log | ||
import ru.vityaman.lms.botalka.core.logic.HomeworkService | ||
import ru.vityaman.lms.botalka.core.model.Homework | ||
|
||
class LoggingHomeworkService( | ||
private val log: Log, | ||
private val origin: HomeworkService, | ||
) : HomeworkService { | ||
override suspend fun create(homework: Homework.Draft): Homework = | ||
runCatching { origin.create(homework) } | ||
.onSuccess { log.info("Created homework with ${it.id}") } | ||
.onFailure { log.warn("Failed to create a homework") } | ||
.getOrThrow() | ||
|
||
override suspend fun getById(id: Homework.Id): Homework? = | ||
runCatching { origin.getById(id) } | ||
.onFailure { | ||
log.warn("Failed to get homework with $id: ${it.message}") | ||
} | ||
.getOrThrow() | ||
} |
45 changes: 45 additions & 0 deletions
45
...lka/src/main/kotlin/ru/vityaman/lms/botalka/core/logic/logging/LoggingPromotionService.kt
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,45 @@ | ||
package ru.vityaman.lms.botalka.core.logic.logging | ||
|
||
import ru.vityaman.lms.botalka.core.logging.Log | ||
import ru.vityaman.lms.botalka.core.logic.PromotionService | ||
import ru.vityaman.lms.botalka.core.model.PromotionRequest | ||
|
||
class LoggingPromotionService( | ||
private val log: Log, | ||
private val origin: PromotionService, | ||
) : PromotionService { | ||
override suspend fun request( | ||
promotion: PromotionRequest.Draft, | ||
): PromotionRequest = | ||
runCatching { origin.request(promotion) } | ||
.onSuccess { | ||
buildString { | ||
append("Created a promotion request with ${it.id} ") | ||
append("of user with ${promotion.user} to ") | ||
append("${promotion.role}") | ||
}.let { log.info(it) } | ||
} | ||
.onFailure { | ||
buildString { | ||
append("Failed to request promotion of user with ") | ||
append("${promotion.user} to ${promotion.role}") | ||
}.let { log.warn(it) } | ||
} | ||
.getOrThrow() | ||
|
||
override suspend fun approve(id: PromotionRequest.Id) = | ||
runCatching { origin.approve(id) } | ||
.onSuccess { log.info("Promotion request with $id was approved") } | ||
.onFailure { | ||
log.warn("Failed to approve promotion request with is $id") | ||
} | ||
.getOrThrow() | ||
|
||
override suspend fun reject(id: PromotionRequest.Id) = | ||
runCatching { origin.reject(id) } | ||
.onSuccess { log.info("Promotion request with $id was rejected") } | ||
.onFailure { | ||
log.warn("Failed to reject promotion request with is $id") | ||
} | ||
.getOrThrow() | ||
} |
15 changes: 15 additions & 0 deletions
15
botalka/src/main/kotlin/ru/vityaman/lms/botalka/core/logic/logging/LoggingRatingService.kt
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,15 @@ | ||
package ru.vityaman.lms.botalka.core.logic.logging | ||
|
||
import ru.vityaman.lms.botalka.core.logging.Log | ||
import ru.vityaman.lms.botalka.core.logic.Grades | ||
import ru.vityaman.lms.botalka.core.logic.RatingService | ||
|
||
class LoggingRatingService( | ||
private val log: Log, | ||
private val origin: RatingService, | ||
) : RatingService { | ||
override suspend fun grades(): Grades = | ||
runCatching { origin.grades() } | ||
.onSuccess { log.info("Got grades for ${it.size} students") } | ||
.getOrThrow() | ||
} |
33 changes: 33 additions & 0 deletions
33
botalka/src/main/kotlin/ru/vityaman/lms/botalka/core/logic/logging/LoggingUserService.kt
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,33 @@ | ||
package ru.vityaman.lms.botalka.core.logic.logging | ||
|
||
import ru.vityaman.lms.botalka.core.logging.Log | ||
import ru.vityaman.lms.botalka.core.logic.UserService | ||
import ru.vityaman.lms.botalka.core.model.User | ||
|
||
class LoggingUserService( | ||
private val log: Log, | ||
private val origin: UserService, | ||
) : UserService { | ||
override suspend fun create(user: User.Draft): User = | ||
runCatching { origin.create(user) } | ||
.onSuccess { log.info("Created user with ${it.id}") } | ||
.onFailure { log.warn("Failed to create user: ${it.message}") } | ||
.getOrThrow() | ||
|
||
override suspend fun getById(id: User.Id): User? = | ||
runCatching { origin.getById(id) } | ||
.onSuccess { it ?: log.warn("User with $id not found") } | ||
.onFailure { log.warn("Failed to get user with $id") } | ||
.getOrThrow() | ||
|
||
override suspend fun promote(id: User.Id, role: User.Role) = | ||
runCatching { origin.promote(id, role) } | ||
.onSuccess { log.info("User with $id promoted to $role") } | ||
.onFailure { | ||
buildString { | ||
append("Failed to promote user with ") | ||
append("$id to $role: ${it.message}") | ||
}.let { log.warn(it) } | ||
} | ||
.getOrThrow() | ||
} |
49 changes: 49 additions & 0 deletions
49
...lka/src/main/kotlin/ru/vityaman/lms/botalka/core/logic/logging/LoggingWorkspaceService.kt
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,49 @@ | ||
package ru.vityaman.lms.botalka.core.logic.logging | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import ru.vityaman.lms.botalka.core.logging.Log | ||
import ru.vityaman.lms.botalka.core.logic.WorkspaceService | ||
import ru.vityaman.lms.botalka.core.model.Homework | ||
import ru.vityaman.lms.botalka.core.model.Workspace | ||
|
||
class LoggingWorkspaceService( | ||
private val log: Log, | ||
private val origin: WorkspaceService, | ||
) : WorkspaceService { | ||
override fun events(id: Workspace.Id): Flow<Workspace.Event> = | ||
runCatching { origin.events(id) } | ||
.onSuccess { log.info("Got events for workspace with $id") } | ||
.onFailure { | ||
buildString { | ||
append("Failed to get events for workspace with $id: ") | ||
append(it.message) | ||
}.let { log.warn(it) } | ||
} | ||
.getOrThrow() | ||
|
||
override suspend fun produce( | ||
id: Workspace.Id, | ||
event: Workspace.Event.Draft, | ||
): Workspace.Event = | ||
runCatching { origin.produce(id, event) } | ||
.onSuccess { | ||
buildString { | ||
append("Produced an event with ${it.id} ") | ||
append("at workspace with $id") | ||
}.let { log.info(it) } | ||
} | ||
.onFailure { | ||
buildString { | ||
append("Failed to produce and event ") | ||
append("at workspace with $id: ") | ||
append(it.message) | ||
}.let { log.warn(it) } | ||
} | ||
.getOrThrow() | ||
|
||
override suspend fun grade(id: Workspace.Id): Homework.Score? = | ||
origin.grade(id) | ||
|
||
override fun all(): Flow<Workspace.Id> = | ||
origin.all() | ||
} |