Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created samfundetUserController, updated repository to use baserepository #299

Merged
merged 17 commits into from
Oct 27, 2024
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
40 changes: 20 additions & 20 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: CI-CD
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down Expand Up @@ -59,25 +59,25 @@ jobs:
files: ./target/*

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ktlint with reviewdog
# You may pin to the exact commit or the version.
# uses: ScaCap/action-ktlint@58b3c386f5160049b0a1d0f986c56e0d0717140a
uses: ScaCap/action-ktlint@1.3
with:
# GITHUB_TOKEN
github_token: ${{ secrets.GITHUB_TOKEN }}
# Report level for reviewdog [info,warning,error]
level: error# optional, default is error
# Reporter of reviewdog command [github-pr-check,github-pr-review].
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ktlint with reviewdog
# You may pin to the exact commit or the version.
# uses: ScaCap/action-ktlint@58b3c386f5160049b0a1d0f986c56e0d0717140a
uses: ScaCap/action-ktlint@1.3
with:
# GITHUB_TOKEN
github_token: ${{ secrets.GITHUB_TOKEN }}
# Report level for reviewdog [info,warning,error]
level: error# optional, default is error
# Reporter of reviewdog command [github-pr-check,github-pr-review].

reporter: github-pr-check # optional, default is github-pr-check
# Fails the current check if any error was found [true/false]
reporter: github-pr-check # optional, default is github-pr-check
# Fails the current check if any error was found [true/false]

fail_on_error: false # optional, default is false
fail_on_error: false # optional, default is false

# Print files relative to the working directory
relative: true # optional, default is true
# Run KtLint with Android Kotlin Style Guide
# Print files relative to the working directory
relative: true # optional, default is true
# Run KtLint with Android Kotlin Style Guide
40 changes: 20 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
pull_request:
branches: [ master ]
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -23,23 +23,23 @@ jobs:
docker network create traefik
docker compose -f docker-compose.yml -f docker-compose.test.yml up run-tests
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ktlint with reviewdog
# You may pin to the exact commit or the version.
# uses: ScaCap/action-ktlint@58b3c386f5160049b0a1d0f986c56e0d0717140a
uses: ScaCap/action-ktlint@1.3
with:
# GITHUB_TOKEN
github_token: ${{ secrets.GITHUB_TOKEN }}
# Report level for reviewdog [info,warning,error]
level: error# optional, default is error
# Reporter of reviewdog command [github-pr-check,github-pr-review].
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ktlint with reviewdog
# You may pin to the exact commit or the version.
# uses: ScaCap/action-ktlint@58b3c386f5160049b0a1d0f986c56e0d0717140a
uses: ScaCap/action-ktlint@1.3
with:
# GITHUB_TOKEN
github_token: ${{ secrets.GITHUB_TOKEN }}
# Report level for reviewdog [info,warning,error]
level: error# optional, default is error
# Reporter of reviewdog command [github-pr-check,github-pr-review].

reporter: github-pr-check # optional, default is github-pr-check
# Fails the current check if any error was found [true/false]
fail_on_error: false # optional, default is false
# Print files relative to the working directory
relative: true # optional, default is true
# Run KtLint with Android Kotlin Style Guide
reporter: github-pr-check # optional, default is github-pr-check
# Fails the current check if any error was found [true/false]
fail_on_error: false # optional, default is false
# Print files relative to the working directory
relative: true # optional, default is true
# Run KtLint with Android Kotlin Style Guide
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.fg.hilflingbackend.configurations

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.multipart.MultipartResolver
import org.springframework.web.multipart.support.StandardServletMultipartResolver

@Configuration
class FileUploadConfiguration {
@Bean
fun multipartResolver(): MultipartResolver = StandardServletMultipartResolver()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package no.fg.hilflingbackend.controller

import no.fg.hilflingbackend.dto.SamfundetUserDto
import no.fg.hilflingbackend.dto.SamfundetUserPatchRequestDto
import no.fg.hilflingbackend.model.SamfundetUser
import no.fg.hilflingbackend.repository.SamfundetUserRepository
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/users")
open class SamfundetUserController(
override val repository: SamfundetUserRepository,
) : BaseController<SamfundetUser, SamfundetUserDto, SamfundetUserPatchRequestDto>(repository)
7 changes: 3 additions & 4 deletions src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class SamfundetUserPatchRequestDto(
val email: Email?,
val profilePicturePath: String?,
val sex: String?,
val securityLevel: SecurityLevelDto?
val securityLevel: SecurityLevelDto?,
)

data class SamfundetUserDto(
Expand All @@ -27,7 +27,7 @@ data class SamfundetUserDto(
// TODO: Rename SQL-scheme and interface to match this variablename
val profilePicturePath: String,
val sex: String,
val securityLevel: SecurityLevelDto
val securityLevel: SecurityLevelDto,
)

// Extend Dto object with a converter to ktorm interface
Expand All @@ -40,15 +40,14 @@ fun SamfundetUserDto.toEntity(): SamfundetUser {
lastName = dto.lastName
username = dto.username
phoneNumber = dto.phoneNumber.value
email = dto.email.value
sex = dto.sex
securityLevel = dto.securityLevel.toEntity()
profilePicture = dto.profilePicturePath
}
}

data class SamfundetUserId(
override val id: UUID = UUID.randomUUID()
override val id: UUID = UUID.randomUUID(),
) : UuidId {
override fun toString(): String = id.toString()
}
11 changes: 7 additions & 4 deletions src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ interface SamfundetUser : BaseModel<SamfundetUser> {

var securityLevel: SecurityLevel
}
fun SamfundetUser.toDto() = SamfundetUserDto(

fun SamfundetUser.toDto() =
SamfundetUserDto(
samfundetUserId = SamfundetUserId(this.id),
firstName = this.firstName,
lastName = this.lastName,
Expand All @@ -35,8 +37,8 @@ fun SamfundetUser.toDto() = SamfundetUserDto(
profilePicturePath = this.profilePicture,
phoneNumber = PhoneNumber(this.phoneNumber),
securityLevel = this.securityLevel.toDto(),
sex = this.sex
)
sex = this.sex,
)

object SamfundetUsers : BaseTable<SamfundetUser>("samfundet_user") {
val firstName = varchar("first_name").bindTo { it.firstName }
Expand All @@ -52,4 +54,5 @@ object SamfundetUsers : BaseTable<SamfundetUser>("samfundet_user") {
val securityLevelId = uuid("security_level_id").references(SecurityLevels) { it.securityLevel }
}

val Database.samfundet_users get() = this.sequenceOf(SamfundetUsers)
val Database.samfundet_users
get() = this.sequenceOf(SamfundetUsers)
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ abstract class BaseRepository<E : BaseModel<E>, D, R>(val table: BaseTable<E>, v
.where { table.dateDeleted.isNull() }
.limit(page, pageSize)
return Page(
page,
pageSize,
1,
page = page,
pageSize = pageSize,
totalRecords = resultSet.totalRecords,
currentList = resultSet.map { row -> convertToClass(row) }
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
package no.fg.hilflingbackend.repository

import me.liuwj.ktorm.database.Database
import me.liuwj.ktorm.dsl.eq
import me.liuwj.ktorm.dsl.QueryRowSet
import me.liuwj.ktorm.entity.add
import me.liuwj.ktorm.entity.update
import me.liuwj.ktorm.entity.find
import me.liuwj.ktorm.entity.toList
import no.fg.hilflingbackend.dto.SamfundetUserDto
import no.fg.hilflingbackend.dto.SamfundetUserId
import no.fg.hilflingbackend.dto.SamfundetUserPatchRequestDto
import no.fg.hilflingbackend.dto.SecurityLevelDto
import no.fg.hilflingbackend.dto.SecurityLevelId
import no.fg.hilflingbackend.dto.toEntity
import no.fg.hilflingbackend.model.SamfundetUser
import no.fg.hilflingbackend.model.SamfundetUsers
import no.fg.hilflingbackend.model.samfundet_users
import no.fg.hilflingbackend.model.toDto
import org.springframework.beans.factory.annotation.Autowired
import no.fg.hilflingbackend.value_object.Email
import no.fg.hilflingbackend.value_object.PhoneNumber
import org.springframework.stereotype.Repository
import java.util.UUID
import jakarta.persistence.EntityNotFoundException

@Repository
open class SamfundetUserRepository {
@Autowired
open lateinit var database: Database
open class SamfundetUserRepository(
database: Database,
) : BaseRepository<SamfundetUser, SamfundetUserDto, SamfundetUserPatchRequestDto>(
table = SamfundetUsers,
database = database,
) {

fun findById(id: UUID): SamfundetUser? {
return database.samfundet_users.find { it.id eq id }
}
override fun convertToClass(qrs: QueryRowSet): SamfundetUserDto =
SamfundetUserDto(
samfundetUserId = SamfundetUserId(qrs[SamfundetUsers.id]!!),
firstName = qrs[SamfundetUsers.firstName]!!,
lastName = qrs[SamfundetUsers.lastName]!!,
username = qrs[SamfundetUsers.username]!!,
phoneNumber = PhoneNumber(qrs[SamfundetUsers.phoneNumber]!!),
email = Email(qrs[SamfundetUsers.email]!!),
profilePicturePath = qrs[SamfundetUsers.profilePicture]!!,
sex = qrs[SamfundetUsers.sex]!!,
securityLevel =
SecurityLevelDto(
securityLevelId =
SecurityLevelId(
qrs[SamfundetUsers.securityLevelId]!!,
),
),
)

fun findAll(): List<SamfundetUser> {
return database.samfundet_users.toList()
}
override fun create(dto: SamfundetUserDto): Int = database.samfundet_users.add(dto.toEntity())

fun create(
samfundetUserDto: SamfundetUserDto
): SamfundetUserDto? {
var success = 0
try {
success = database
.samfundet_users
.add(
samfundetUserDto.toEntity()
)
} catch (error: Error) {
return null
}
if (success == 1) {
return findById(samfundetUserDto.samfundetUserId.id)?.toDto()
}
return null
override fun patch(dto: SamfundetUserPatchRequestDto): SamfundetUserDto {
val fromDb =
findById(dto.samfundetUserId.id)
?: throw EntityNotFoundException("Could not find SecurityLevel")
val newDto =
SamfundetUserDto(
samfundetUserId = fromDb.samfundetUserId,
firstName = dto.firstName ?: fromDb.firstName,
lastName = dto.lastName ?: fromDb.lastName,
username = dto.username ?: fromDb.username,
phoneNumber = dto.phoneNumber ?: fromDb.phoneNumber,
email = dto.email ?: fromDb.email,
profilePicturePath =
dto.profilePicturePath ?: fromDb.profilePicturePath,
sex = dto.sex ?: fromDb.sex,
securityLevel = dto.securityLevel ?: fromDb.securityLevel,
)
val updated = database.samfundet_users.update(newDto.toEntity())
return if (updated == 1) newDto else fromDb
}
}
2 changes: 1 addition & 1 deletion static-files/blob_storage/__azurite_db_queue__.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"filename":"/data/__azurite_db_queue__.json","collections":[{"name":"$SERVICES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{},"constraints":null,"uniqueNames":["accountName"],"transforms":{},"objType":"$SERVICES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$QUEUES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"name":{"name":"name","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$QUEUES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$MESSAGES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"queueName":{"name":"queueName","dirty":false,"values":[]},"messageId":{"name":"messageId","dirty":false,"values":[]},"visibleTime":{"name":"visibleTime","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$MESSAGES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"}
{"filename":"/data/__azurite_db_queue__.json","collections":[{"name":"$SERVICES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{},"constraints":null,"uniqueNames":["accountName"],"transforms":{},"objType":"$SERVICES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$QUEUES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"name":{"name":"name","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$QUEUES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$MESSAGES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"queueName":{"name":"queueName","dirty":false,"values":[]},"messageId":{"name":"messageId","dirty":false,"values":[]},"visibleTime":{"name":"visibleTime","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$MESSAGES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"persistenceMethod":"fs","autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"}
Loading
Loading