From 557421aee8f3e306d47ac95656cf0bb5735b7389 Mon Sep 17 00:00:00 2001 From: Makar Selivanov Date: Thu, 26 Oct 2023 19:21:12 +0300 Subject: [PATCH] move models to subpackage users, rooms or reservations (#83) --- .../roomkn/server/auth/AccountController.kt | 4 ++-- .../server/auth/AccountControllerImpl.kt | 6 +++--- .../server/database/CredentialsDatabase.kt | 6 +++--- .../tod87et/roomkn/server/database/Database.kt | 14 +++++++------- .../roomkn/server/database/DatabaseSession.kt | 18 +++++++++--------- .../models/{ => reservations}/Reservation.kt | 2 +- .../UnregisteredReservation.kt | 2 +- .../server/models/{ => rooms}/NewRoomInfo.kt | 2 +- .../server/models/{ => rooms}/RoomInfo.kt | 2 +- .../server/models/{ => rooms}/ShortRoomInfo.kt | 2 +- .../server/models/{ => users}/LoginUserInfo.kt | 2 +- .../models/{ => users}/RegistrationUserInfo.kt | 2 +- .../server/models/{ => users}/ShortUserInfo.kt | 2 +- .../models/{ => users}/UnregisteredUserInfo.kt | 2 +- .../models/{ => users}/UserCredentialsInfo.kt | 2 +- .../server/models/{ => users}/UserInfo.kt | 2 +- .../roomkn/server/routing/AccountRouting.kt | 4 ++-- .../tod87et/roomkn/server/routing/Reserve.kt | 2 +- .../org/tod87et/roomkn/server/AuthTest.kt | 4 ++-- .../org/tod87et/roomkn/server/DatabaseTest.kt | 16 ++++++++-------- 20 files changed, 48 insertions(+), 48 deletions(-) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => reservations}/Reservation.kt (85%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => reservations}/UnregisteredReservation.kt (84%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => rooms}/NewRoomInfo.kt (74%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => rooms}/RoomInfo.kt (75%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => rooms}/ShortRoomInfo.kt (72%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => users}/LoginUserInfo.kt (74%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => users}/RegistrationUserInfo.kt (80%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => users}/ShortUserInfo.kt (73%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => users}/UnregisteredUserInfo.kt (78%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => users}/UserCredentialsInfo.kt (76%) rename server/src/main/kotlin/org/tod87et/roomkn/server/models/{ => users}/UserInfo.kt (75%) diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountController.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountController.kt index 458ce764..0ff8029f 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountController.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountController.kt @@ -1,7 +1,7 @@ package org.tod87et.roomkn.server.auth -import org.tod87et.roomkn.server.models.LoginUserInfo -import org.tod87et.roomkn.server.models.UnregisteredUserInfo +import org.tod87et.roomkn.server.models.users.LoginUserInfo +import org.tod87et.roomkn.server.models.users.UnregisteredUserInfo interface AccountController { fun authenticateUser(loginUserInfo: LoginUserInfo): Result diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountControllerImpl.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountControllerImpl.kt index e69cc466..0fa4ec47 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountControllerImpl.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/auth/AccountControllerImpl.kt @@ -5,9 +5,9 @@ import com.auth0.jwt.algorithms.Algorithm import io.ktor.util.logging.Logger import org.tod87et.roomkn.server.database.ConstraintViolationException import org.tod87et.roomkn.server.database.MissingElementException -import org.tod87et.roomkn.server.models.LoginUserInfo -import org.tod87et.roomkn.server.models.RegistrationUserInfo -import org.tod87et.roomkn.server.models.UnregisteredUserInfo +import org.tod87et.roomkn.server.models.users.LoginUserInfo +import org.tod87et.roomkn.server.models.users.RegistrationUserInfo +import org.tod87et.roomkn.server.models.users.UnregisteredUserInfo import java.security.MessageDigest import java.security.SecureRandom import java.util.Date diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/database/CredentialsDatabase.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/database/CredentialsDatabase.kt index 4612c010..9b78214a 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/database/CredentialsDatabase.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/database/CredentialsDatabase.kt @@ -1,8 +1,8 @@ package org.tod87et.roomkn.server.database -import org.tod87et.roomkn.server.models.RegistrationUserInfo -import org.tod87et.roomkn.server.models.UserCredentialsInfo -import org.tod87et.roomkn.server.models.UserInfo +import org.tod87et.roomkn.server.models.users.RegistrationUserInfo +import org.tod87et.roomkn.server.models.users.UserCredentialsInfo +import org.tod87et.roomkn.server.models.users.UserInfo interface CredentialsDatabase { fun registerUser(user: RegistrationUserInfo): Result diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/database/Database.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/database/Database.kt index 1a7a1244..d39e7345 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/database/Database.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/database/Database.kt @@ -1,12 +1,12 @@ package org.tod87et.roomkn.server.database -import org.tod87et.roomkn.server.models.NewRoomInfo -import org.tod87et.roomkn.server.models.Reservation -import org.tod87et.roomkn.server.models.RoomInfo -import org.tod87et.roomkn.server.models.ShortRoomInfo -import org.tod87et.roomkn.server.models.ShortUserInfo -import org.tod87et.roomkn.server.models.UnregisteredReservation -import org.tod87et.roomkn.server.models.UserInfo +import org.tod87et.roomkn.server.models.rooms.NewRoomInfo +import org.tod87et.roomkn.server.models.reservations.Reservation +import org.tod87et.roomkn.server.models.rooms.RoomInfo +import org.tod87et.roomkn.server.models.rooms.ShortRoomInfo +import org.tod87et.roomkn.server.models.users.ShortUserInfo +import org.tod87et.roomkn.server.models.reservations.UnregisteredReservation +import org.tod87et.roomkn.server.models.users.UserInfo interface Database { fun getRooms(): Result> diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/database/DatabaseSession.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/database/DatabaseSession.kt index c5f37b32..37e5507f 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/database/DatabaseSession.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/database/DatabaseSession.kt @@ -7,21 +7,21 @@ import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction -import org.tod87et.roomkn.server.models.RegistrationUserInfo -import org.tod87et.roomkn.server.models.Reservation -import org.tod87et.roomkn.server.models.RoomInfo -import org.tod87et.roomkn.server.models.ShortRoomInfo -import org.tod87et.roomkn.server.models.ShortUserInfo -import org.tod87et.roomkn.server.models.UnregisteredReservation -import org.tod87et.roomkn.server.models.UserCredentialsInfo -import org.tod87et.roomkn.server.models.UserInfo +import org.tod87et.roomkn.server.models.users.RegistrationUserInfo +import org.tod87et.roomkn.server.models.reservations.Reservation +import org.tod87et.roomkn.server.models.rooms.RoomInfo +import org.tod87et.roomkn.server.models.rooms.ShortRoomInfo +import org.tod87et.roomkn.server.models.users.ShortUserInfo +import org.tod87et.roomkn.server.models.reservations.UnregisteredReservation +import org.tod87et.roomkn.server.models.users.UserCredentialsInfo +import org.tod87et.roomkn.server.models.users.UserInfo import java.sql.Connection import javax.sql.DataSource import org.tod87et.roomkn.server.database.Database as RooMknDatabase import org.jetbrains.exposed.exceptions.ExposedSQLException import org.jetbrains.exposed.sql.deleteAll import org.postgresql.util.PSQLException -import org.tod87et.roomkn.server.models.NewRoomInfo +import org.tod87et.roomkn.server.models.rooms.NewRoomInfo class DatabaseSession private constructor(private val database: Database) : RooMknDatabase, CredentialsDatabase { diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/Reservation.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/reservations/Reservation.kt similarity index 85% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/Reservation.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/reservations/Reservation.kt index 2cd9c760..acb325ed 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/Reservation.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/reservations/Reservation.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.reservations import kotlinx.datetime.Instant import kotlinx.serialization.SerialName diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UnregisteredReservation.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/reservations/UnregisteredReservation.kt similarity index 84% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/UnregisteredReservation.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/reservations/UnregisteredReservation.kt index 2f8149f6..fb081f3c 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UnregisteredReservation.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/reservations/UnregisteredReservation.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.reservations import kotlinx.datetime.Instant import kotlinx.serialization.SerialName diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/NewRoomInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/NewRoomInfo.kt similarity index 74% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/NewRoomInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/NewRoomInfo.kt index 6e6462e2..afdf5621 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/NewRoomInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/NewRoomInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.rooms import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/RoomInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/RoomInfo.kt similarity index 75% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/RoomInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/RoomInfo.kt index babf2d5d..39ca0324 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/RoomInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/RoomInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.rooms import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/ShortRoomInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/ShortRoomInfo.kt similarity index 72% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/ShortRoomInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/ShortRoomInfo.kt index ad9045bf..089ad00c 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/ShortRoomInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/rooms/ShortRoomInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.rooms import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/LoginUserInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/LoginUserInfo.kt similarity index 74% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/LoginUserInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/users/LoginUserInfo.kt index 292058f3..e2d2a5ff 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/LoginUserInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/LoginUserInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.users import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/RegistrationUserInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/RegistrationUserInfo.kt similarity index 80% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/RegistrationUserInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/users/RegistrationUserInfo.kt index bc3a1176..94fbd856 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/RegistrationUserInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/RegistrationUserInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.users /** For internal use only. **Not** serializable */ class RegistrationUserInfo( diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/ShortUserInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/ShortUserInfo.kt similarity index 73% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/ShortUserInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/users/ShortUserInfo.kt index 80463c7d..25c780f5 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/ShortUserInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/ShortUserInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.users import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UnregisteredUserInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UnregisteredUserInfo.kt similarity index 78% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/UnregisteredUserInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UnregisteredUserInfo.kt index 0323239d..3b1450d4 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UnregisteredUserInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UnregisteredUserInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.users import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UserCredentialsInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UserCredentialsInfo.kt similarity index 76% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/UserCredentialsInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UserCredentialsInfo.kt index c70b20c3..feb83c3b 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UserCredentialsInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UserCredentialsInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.users /** For internal use only. **Not** serializable */ class UserCredentialsInfo( diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UserInfo.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UserInfo.kt similarity index 75% rename from server/src/main/kotlin/org/tod87et/roomkn/server/models/UserInfo.kt rename to server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UserInfo.kt index 7610a85c..4c004bca 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/models/UserInfo.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/models/users/UserInfo.kt @@ -1,4 +1,4 @@ -package org.tod87et.roomkn.server.models +package org.tod87et.roomkn.server.models.users import kotlinx.serialization.Serializable diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/routing/AccountRouting.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/routing/AccountRouting.kt index 5723c0f6..66d6faa8 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/routing/AccountRouting.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/routing/AccountRouting.kt @@ -20,8 +20,8 @@ import org.tod87et.roomkn.server.auth.AuthSession import org.tod87et.roomkn.server.auth.AuthenticationProvider import org.tod87et.roomkn.server.auth.NoSuchUserException import org.tod87et.roomkn.server.auth.RegistrationFailedException -import org.tod87et.roomkn.server.models.LoginUserInfo -import org.tod87et.roomkn.server.models.UnregisteredUserInfo +import org.tod87et.roomkn.server.models.users.LoginUserInfo +import org.tod87et.roomkn.server.models.users.UnregisteredUserInfo fun Route.accountRouting(authConfig: AuthConfig) { val env = environment!! diff --git a/server/src/main/kotlin/org/tod87et/roomkn/server/routing/Reserve.kt b/server/src/main/kotlin/org/tod87et/roomkn/server/routing/Reserve.kt index 04f086e5..ce15eb58 100644 --- a/server/src/main/kotlin/org/tod87et/roomkn/server/routing/Reserve.kt +++ b/server/src/main/kotlin/org/tod87et/roomkn/server/routing/Reserve.kt @@ -7,7 +7,7 @@ import io.ktor.server.response.respondText import io.ktor.server.routing.Route import io.ktor.server.routing.post import org.tod87et.roomkn.server.database.DatabaseFactory.database -import org.tod87et.roomkn.server.models.UnregisteredReservation +import org.tod87et.roomkn.server.models.reservations.UnregisteredReservation fun Route.reserveRouting() { post("/reserve") { unregisteredReservation: UnregisteredReservation -> diff --git a/server/src/test/kotlin/org/tod87et/roomkn/server/AuthTest.kt b/server/src/test/kotlin/org/tod87et/roomkn/server/AuthTest.kt index dd6eb105..f45a330f 100644 --- a/server/src/test/kotlin/org/tod87et/roomkn/server/AuthTest.kt +++ b/server/src/test/kotlin/org/tod87et/roomkn/server/AuthTest.kt @@ -13,8 +13,8 @@ import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.tod87et.roomkn.server.KtorTestEnv.testJsonApplication import org.tod87et.roomkn.server.database.DatabaseFactory -import org.tod87et.roomkn.server.models.LoginUserInfo -import org.tod87et.roomkn.server.models.UnregisteredUserInfo +import org.tod87et.roomkn.server.models.users.LoginUserInfo +import org.tod87et.roomkn.server.models.users.UnregisteredUserInfo import kotlin.test.assertContains import kotlin.test.assertEquals diff --git a/server/src/test/kotlin/org/tod87et/roomkn/server/DatabaseTest.kt b/server/src/test/kotlin/org/tod87et/roomkn/server/DatabaseTest.kt index 449f560f..80f96f21 100644 --- a/server/src/test/kotlin/org/tod87et/roomkn/server/DatabaseTest.kt +++ b/server/src/test/kotlin/org/tod87et/roomkn/server/DatabaseTest.kt @@ -9,14 +9,14 @@ import org.tod87et.roomkn.server.database.ConstraintViolationException import org.tod87et.roomkn.server.database.DatabaseSession import org.tod87et.roomkn.server.database.MissingElementException import org.tod87et.roomkn.server.database.ReservationException -import org.tod87et.roomkn.server.models.NewRoomInfo -import org.tod87et.roomkn.server.models.RegistrationUserInfo -import org.tod87et.roomkn.server.models.Reservation -import org.tod87et.roomkn.server.models.RoomInfo -import org.tod87et.roomkn.server.models.ShortRoomInfo -import org.tod87et.roomkn.server.models.ShortUserInfo -import org.tod87et.roomkn.server.models.UnregisteredReservation -import org.tod87et.roomkn.server.models.UserInfo +import org.tod87et.roomkn.server.models.rooms.NewRoomInfo +import org.tod87et.roomkn.server.models.users.RegistrationUserInfo +import org.tod87et.roomkn.server.models.reservations.Reservation +import org.tod87et.roomkn.server.models.rooms.RoomInfo +import org.tod87et.roomkn.server.models.rooms.ShortRoomInfo +import org.tod87et.roomkn.server.models.users.ShortUserInfo +import org.tod87et.roomkn.server.models.reservations.UnregisteredReservation +import org.tod87et.roomkn.server.models.users.UserInfo import javax.sql.DataSource import kotlin.test.assertContentEquals import kotlin.test.assertEquals