Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/.run/Adoptme [desktopRun].run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Adoptme [desktopRun]" type="GradleRunConfiguration" factoryName="Gradle" nameIsGenerated="true">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="DEVELOPER_DIR" value="/Applications/Xcode.app/Contents/Developer" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
Expand Down
2 changes: 2 additions & 0 deletions backend/.run/Server.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="DEVELOPER_DIR" value="/Applications/Xcode.app/Contents/Developer" />
<entry key="JDBC_DATABASE_URL" value="jdbc:postgresql:habits?user=postgres" />
<entry key="JDBC_DRIVER" value="org.postgresql.Driver" />
<entry key="JWT_SECRET" value="898748674728934843" />
Expand All @@ -26,6 +27,7 @@
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion backend/docs/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.41
3.0.69
2 changes: 1 addition & 1 deletion backend/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,7 @@ <h3> Status: 200 - A JSON array of user names </h3>
this.isPrimitive = !this.isAny && !this.isArray && !this.isObject;

//
this.showToggle = this.schema.description || this.schema.title || this.isPrimitive && (this.schema.minimum || this.schema.maximum || this.schema.exclusiveMinimum || this.schema.exclusiveMaximum);
this.showToggle = this.schema.description || this.schema.title || this.isPrimitive && (this.schema.minimum || this.schema.maximum || this.schema.exclusiveMinimum || this.schema.exclusiveMaximum || this.schema.maxLength || this.schema.minLength || this.schema.pattern || this.schema.format);

// populate isRequired property down to properties
if (this.schema && Array.isArray(this.schema.required)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ fun Application.configureGeneralRouting() {
}

class AuthenticationException : RuntimeException()

class AuthorizationException : RuntimeException()
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ import java.util.Date
const val JWT_CONFIGURATION = "MyProjectNameJWT"

class JwtService {

private val issuer = "MyProjectNameServer"
private val jwtSecret = System.getenv("JWT_SECRET")
private val algorithm = HMAC512(jwtSecret)

val verifier: JWTVerifier = JWT
.require(algorithm)
.withIssuer(issuer)
.build()
val verifier: JWTVerifier =
JWT
.require(algorithm)
.withIssuer(issuer)
.build()

fun generateToken(databaseUser: DatabaseUser): String = JWT.create()
.withSubject("Authentication")
.withIssuer(issuer)
.withClaim("id", databaseUser.userId)
.withExpiresAt(expiresAt())
.sign(algorithm)
fun generateToken(databaseUser: DatabaseUser): String =
JWT
.create()
.withSubject("Authentication")
.withIssuer(issuer)
.withClaim("id", databaseUser.userId)
.withExpiresAt(expiresAt())
.sign(algorithm)

@Suppress("MagicNumber")
private fun expiresAt() = Date(System.currentTimeMillis() + 3_600_000 * 24) // 24 hours
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class DatabaseUser(
val userId: Int,
val email: String,
val name: String,
val passwordHash: String
val passwordHash: String,
) : Serializable, Principal
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ fun Application.configureHTTP() {
install(CachingHeaders) {
options { _, outgoingContent ->
when (outgoingContent.contentType?.withoutParameters()) {
ContentType.Text.CSS -> CachingOptions(
CacheControl.MaxAge(maxAgeSeconds = 24 * 60 * 60),
ZonedDateTime.of(0, 0, 1, 0, 0, 0, 0, ZoneId.systemDefault())
)
ContentType.Text.CSS ->
CachingOptions(
CacheControl.MaxAge(maxAgeSeconds = 24 * 60 * 60),
ZonedDateTime.of(0, 0, 1, 0, 0, 0, 0, ZoneId.systemDefault()),
)

else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface PetsRepository {
size: String,
color: String,
status: String,
shelterId: Int?
shelterId: Int?,
): PetModel?

suspend fun getPet(petId: Int): PetModel
Expand All @@ -39,6 +39,6 @@ interface PetsRepository {
size: String?,
color: String?,
status: String?,
shelterId: Int?
shelterId: Int?,
): PetModel?
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.update

Expand All @@ -31,43 +30,41 @@ class PetsRepositoryImp : PetsRepository {
size: String,
color: String,
status: String,
shelterId: Int?
shelterId: Int?,
): PetModel? {
var statement: InsertStatement<Number>? = null
dbQuery {
statement = Pets.insert {
it[Pets.userId] = userId
it[Pets.title] = title
it[Pets.description] = description
it[Pets.images] = images
it[Pets.category] = category
it[Pets.location] = location
it[Pets.published] = published
it[Pets.breed] = breed
it[Pets.age] = age
it[Pets.gender] = gender
it[Pets.size] = size
it[Pets.color] = color
it[Pets.status] = status
it[Pets.shelterId] = shelterId ?: 0
}
statement =
Pets.insert {
it[Pets.userId] = userId
it[Pets.title] = title
it[Pets.description] = description
it[Pets.images] = images
it[Pets.category] = category
it[Pets.location] = location
it[Pets.published] = published
it[Pets.breed] = breed
it[Pets.age] = age
it[Pets.gender] = gender
it[Pets.size] = size
it[Pets.color] = color
it[Pets.status] = status
it[Pets.shelterId] = shelterId ?: 0
}
}
return rowToPetModel(statement?.resultedValues?.get(0))
}

override suspend fun getPets(userId: Int): List<PetModel> {
return dbQuery {
Pets.select {
Pets.userId.eq((userId)) // 3
}.mapNotNull { rowToPetModel(it) }
Pets.select(Pets.userId).where { Pets.userId.eq(userId) }
.mapNotNull { rowToPetModel(it) }
}
}

override suspend fun getPet(petId: Int): PetModel {
return dbQuery {
Pets.select {
Pets.id.eq((petId))
}.mapNotNull { rowToPetModel(it) }
Pets.select(Pets.id).where { Pets.id.eq(petId) }.mapNotNull { rowToPetModel(it) }
}.first()
}

Expand All @@ -92,10 +89,10 @@ class PetsRepositoryImp : PetsRepository {
size: String?,
color: String?,
status: String?,
shelterId: Int?
shelterId: Int?,
): PetModel? {
return dbQuery {
Pets.select {
Pets.select(Pets.id).where {
Pets.id.eq((petId))
}.forUpdate()

Expand Down Expand Up @@ -139,7 +136,7 @@ class PetsRepositoryImp : PetsRepository {
}
}

Pets.select {
Pets.select(Pets.id).where {
Pets.id.eq((petId))
}.mapNotNull { rowToPetModel(it) }
}.firstOrNull()
Expand All @@ -166,7 +163,7 @@ class PetsRepositoryImp : PetsRepository {
size = PetSize.valueOf(row[Pets.size]),
color = row[Pets.color].toString(),
status = PetStatus.valueOf(row[Pets.status]),
shelterId = row[Pets.shelterId]
shelterId = row[Pets.shelterId],
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package com.multiplatformkickstarter.repository.profile
import com.multiplatformkickstarter.app.common.model.Profile

interface ProfileRepository {

suspend fun addProfile(
userId: Int,
name: String,
description: String?,
image: String?,
location: String?,
rating: Double?
rating: Double?,
): Profile?

suspend fun getProfile(userId: Int): Profile?
Expand All @@ -21,6 +20,6 @@ interface ProfileRepository {
description: String?,
image: String?,
location: String?,
rating: Double?
rating: Double?,
): Profile?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,44 @@ import com.multiplatformkickstarter.repository.DatabaseFactory.dbQuery
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.update

class ProfileRepositoryImpl : ProfileRepository {

override suspend fun addProfile(
userId: Int,
name: String,
description: String?,
image: String?,
location: String?,
rating: Double?
rating: Double?,
): Profile? {
var statement: InsertStatement<Number>? = null
dbQuery {
statement = Profiles.insert { profiles ->
profiles[Profiles.userId] = userId
profiles[Profiles.name] = name
description?.let {
profiles[Profiles.description] = it
}
image?.let {
profiles[Profiles.image] = it
}
location?.let {
profiles[Profiles.location] = it
statement =
Profiles.insert { profiles ->
profiles[Profiles.userId] = userId
profiles[Profiles.name] = name
description?.let {
profiles[Profiles.description] = it
}
image?.let {
profiles[Profiles.image] = it
}
location?.let {
profiles[Profiles.location] = it
}
rating?.let {
profiles[Profiles.rating] = it
}
}
rating?.let {
profiles[Profiles.rating] = it
}
}
}
return rowToProfiles(statement?.resultedValues?.get(0))
}

override suspend fun getProfile(userId: Int): Profile? {
return dbQuery {
Profiles.select {
Profiles.select(Profiles.userId).where {
Profiles.userId.eq((userId))
}.mapNotNull { rowToProfiles(it) }
}.firstOrNull()
Expand All @@ -56,10 +55,10 @@ class ProfileRepositoryImpl : ProfileRepository {
description: String?,
image: String?,
location: String?,
rating: Double?
rating: Double?,
): Profile? {
return dbQuery {
Profiles.select {
Profiles.select(Profiles.userId).where {
Profiles.userId.eq((userId))
}.forUpdate()

Expand All @@ -82,7 +81,7 @@ class ProfileRepositoryImpl : ProfileRepository {
}
}

Profiles.select {
Profiles.select(Profiles.userId).where {
Profiles.userId.eq((userId))
}.mapNotNull { rowToProfiles(it) }
}.firstOrNull()
Expand All @@ -100,7 +99,7 @@ class ProfileRepositoryImpl : ProfileRepository {
description = row[Profiles.description],
image = row[Profiles.image],
location = geoLocation,
rating = row[Profiles.rating]
rating = row[Profiles.rating],
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ interface UserRepository {
suspend fun addUser(
email: String,
name: String,
passwordHash: String
passwordHash: String,
): DatabaseUser?

suspend fun findUser(userId: Int): DatabaseUser?

suspend fun findUserByEmail(email: String): DatabaseUser?
}
Loading
Loading