-
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.
Feature/44 vytvořit na BE i FE uživatelské lokace (#58)
* added backend and frontend for user weather locations --------- Co-authored-by: Štěpán Moc <[email protected]>
- Loading branch information
Showing
38 changed files
with
827 additions
and
83 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
11 changes: 11 additions & 0 deletions
11
backend/src/main/kotlin/com/tul/backend/auth/base/dto/AuthJwtClaims.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,11 @@ | ||
package com.tul.backend.auth.base.dto | ||
|
||
import com.tul.backend.auth.base.valueobject.AuthUserRole | ||
import com.tul.backend.auth.base.valueobject.EmailAddress | ||
import org.springframework.security.core.AuthenticatedPrincipal | ||
|
||
interface AuthJwtClaims : AuthenticatedPrincipal { | ||
val authUserId: Long | ||
val authUserRole: AuthUserRole | ||
val email: EmailAddress | ||
} |
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
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
17 changes: 17 additions & 0 deletions
17
backend/src/main/kotlin/com/tul/backend/weather/dto/UserWeatherLocationDTO.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,17 @@ | ||
package com.tul.backend.weather.dto | ||
|
||
import com.tul.backend.weather.entity.UserWeatherLocation | ||
|
||
data class UserWeatherLocationDTO( | ||
val id: Long, | ||
val location: String | ||
) { | ||
companion object { | ||
fun from(userWeatherLocation: UserWeatherLocation): UserWeatherLocationDTO { | ||
return UserWeatherLocationDTO( | ||
id = userWeatherLocation.id, | ||
location = userWeatherLocation.location | ||
) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/src/main/kotlin/com/tul/backend/weather/entity/UserWeatherLocation.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,29 @@ | ||
package com.tul.backend.weather.entity | ||
|
||
import com.tul.backend.auth.entity.AuthUser | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.ManyToOne | ||
|
||
@Entity | ||
class UserWeatherLocation( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0L, | ||
val location: String, | ||
@ManyToOne(optional = false) | ||
val user: AuthUser | ||
) { | ||
|
||
companion object { | ||
fun from(location: String, user: AuthUser): UserWeatherLocation { | ||
return UserWeatherLocation( | ||
location = location, | ||
user = user | ||
) | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/kotlin/com/tul/backend/weather/repository/UserWeatherLocationRepository.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,13 @@ | ||
package com.tul.backend.weather.repository | ||
|
||
import com.tul.backend.weather.entity.UserWeatherLocation | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface UserWeatherLocationRepository : JpaRepository<UserWeatherLocation, Long> { | ||
|
||
fun findByUser_Id(id: Long): List<UserWeatherLocation> | ||
|
||
fun existsByUser_IdAndLocation(id: Long, location: String): Boolean | ||
|
||
fun existsByUser_IdAndId(id: Long, id1: Long): Boolean | ||
} |
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
24 changes: 24 additions & 0 deletions
24
backend/src/main/resources/db/changelog/2024/04/02_user_weather_location.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
|
||
<changeSet id="1714045336927-1" author="stepan.moc"> | ||
<createTable tableName="user_weather_location"> | ||
<column autoIncrement="true" name="id" type="BIGINT"> | ||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_userweatherlocation"/> | ||
</column> | ||
<column name="location" type="VARCHAR(255)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="user_id" type="BIGINT"> | ||
<constraints nullable="false"/> | ||
</column> | ||
</createTable> | ||
<addForeignKeyConstraint baseColumnNames="user_id" baseTableName="user_weather_location" | ||
constraintName="FK_USERWEATHERLOCATION_ON_USER" referencedColumnNames="id" | ||
referencedTableName="auth_user"/> | ||
</changeSet> | ||
</databaseChangeLog> |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper | |
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import com.tul.backend.auth.base.dto.AccessTokenClaims | ||
import com.tul.backend.auth.base.dto.AuthJwtClaims | ||
import com.tul.backend.auth.base.valueobject.AuthUserRole | ||
import com.tul.backend.auth.base.valueobject.EmailAddress | ||
import com.tul.backend.auth.entity.AuthUser | ||
|
@@ -16,10 +18,10 @@ val objectMapper: ObjectMapper = jacksonObjectMapper() | |
|
||
fun createAuthUser( | ||
id: Long = 0L, | ||
username: String = "admin", | ||
email: EmailAddress = EmailAddress("admin@admin.cz"), | ||
password: String = "admin", | ||
role: AuthUserRole = AuthUserRole.ADMIN | ||
username: String = "test", | ||
email: EmailAddress = EmailAddress("test@test.cz"), | ||
password: String = "test", | ||
role: AuthUserRole = AuthUserRole.USER | ||
): AuthUser { | ||
return AuthUser( | ||
id = id, | ||
|
@@ -29,3 +31,15 @@ fun createAuthUser( | |
role = role | ||
) | ||
} | ||
|
||
fun createAccessTokenClaims( | ||
authUserId: Long = 0L, | ||
role: AuthUserRole = AuthUserRole.USER, | ||
email: String = "[email protected]" | ||
) = AccessTokenClaims( | ||
authUserId = authUserId, | ||
authUserRole = role, | ||
email = EmailAddress(email) | ||
) | ||
|
||
fun createUserClaims(): AuthJwtClaims = createAccessTokenClaims() |
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.