From 96706874b421750bbb2444503603b7e08422358a Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 12 Sep 2024 18:26:09 +0200 Subject: [PATCH 01/16] Created samfundetUserController, updated repository to use baserepository --- .../controller/SamfundetUserController.kt | 32 +++++ .../hilflingbackend/dto/SamfundetUserDto.kt | 45 +++--- .../fg/hilflingbackend/model/SamfundetUser.kt | 27 ++-- .../repository/SamfundetUserRepository.kt | 128 +++++++++++++----- .../blob_storage/__azurite_db_queue__.json | 2 +- .../__azurite_db_queue_extent__.json | 2 +- .../blob_storage/__azurite_db_table__.json | 2 +- 7 files changed, 163 insertions(+), 75 deletions(-) create mode 100644 src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt diff --git a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt new file mode 100644 index 00000000..e67d673e --- /dev/null +++ b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt @@ -0,0 +1,32 @@ +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(repository) + +// class SamfundetUserController { +// @Autowired lateinit var repository: SamfundetUserRepository + +// @GetMapping("/{id}") +// fun getById(@PathVariable("id") id: UUID): SamfundetUser? { +// return repository.findById(id) +// } + +// @GetMapping +// fun getAll(): List { +// return repository.findAll() +// } + +// @PostMapping +// fun create(@RequestBody user: SamfundetUserDto): SamfundetUserDto? { +// return repository.create(user) +// } +// } diff --git a/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt b/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt index 529aa35a..6f58d9ad 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt @@ -1,33 +1,33 @@ package no.fg.hilflingbackend.dto +import java.util.UUID import no.fg.hilflingbackend.model.SamfundetUser import no.fg.hilflingbackend.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber -import java.util.UUID data class SamfundetUserPatchRequestDto( - val samfundetUserId: SamfundetUserId, - val firstName: String?, - val lastName: String?, - val username: String?, - val phoneNumber: PhoneNumber?, - val email: Email?, - val profilePicturePath: String?, - val sex: String?, - val securityLevel: SecurityLevelDto? + val samfundetUserId: SamfundetUserId, + val firstName: String?, + val lastName: String?, + val username: String?, + val phoneNumber: PhoneNumber?, + val email: Email?, + val profilePicturePath: String?, + val sex: String?, + val securityLevel: SecurityLevelDto? ) data class SamfundetUserDto( - val samfundetUserId: SamfundetUserId = SamfundetUserId(), - val firstName: String, - val lastName: String, - val username: String, - val phoneNumber: PhoneNumber, - val email: Email, - // TODO: Rename SQL-scheme and interface to match this variablename - val profilePicturePath: String, - val sex: String, - val securityLevel: SecurityLevelDto + val samfundetUserId: SamfundetUserId = SamfundetUserId(), + val firstName: String, + val lastName: String, + val username: String, + val phoneNumber: PhoneNumber, + val email: Email, + // TODO: Rename SQL-scheme and interface to match this variablename + val profilePicturePath: String, + val sex: String, + val securityLevel: SecurityLevelDto ) // Extend Dto object with a converter to ktorm interface @@ -40,15 +40,12 @@ 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() -) : UuidId { +data class SamfundetUserId(override val id: UUID = UUID.randomUUID()) : UuidId { override fun toString(): String = id.toString() } diff --git a/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt b/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt index be7fa848..71e1b2d2 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt @@ -26,17 +26,19 @@ interface SamfundetUser : BaseModel { var securityLevel: SecurityLevel } -fun SamfundetUser.toDto() = SamfundetUserDto( - samfundetUserId = SamfundetUserId(this.id), - firstName = this.firstName, - lastName = this.lastName, - username = this.username, - email = Email(this.email), - profilePicturePath = this.profilePicture, - phoneNumber = PhoneNumber(this.phoneNumber), - securityLevel = this.securityLevel.toDto(), - sex = this.sex -) + +fun SamfundetUser.toDto() = + SamfundetUserDto( + samfundetUserId = SamfundetUserId(this.id), + firstName = this.firstName, + lastName = this.lastName, + username = this.username, + email = Email(this.email), + profilePicturePath = this.profilePicture, + phoneNumber = PhoneNumber(this.phoneNumber), + securityLevel = this.securityLevel.toDto(), + sex = this.sex + ) object SamfundetUsers : BaseTable("samfundet_user") { val firstName = varchar("first_name").bindTo { it.firstName } @@ -52,4 +54,5 @@ object SamfundetUsers : BaseTable("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) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index 17d8440b..561c916c 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -1,48 +1,104 @@ package no.fg.hilflingbackend.repository +import javax.persistence.EntityNotFoundException 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.find -import me.liuwj.ktorm.entity.toList +import me.liuwj.ktorm.entity.update 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 @Repository -open class SamfundetUserRepository { - @Autowired - open lateinit var database: Database - - fun findById(id: UUID): SamfundetUser? { - return database.samfundet_users.find { it.id eq id } - } - - fun findAll(): List { - return database.samfundet_users.toList() - } - - 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 - } +open class SamfundetUserRepository(database: Database) : + BaseRepository( + table = SamfundetUsers, + database = database + ) { + + 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]!! + ) + ) + ) + + override fun create(dto: SamfundetUserDto): Int { + return database.samfundet_users.add(dto.toEntity()) + } + + 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 + } } + +// open class SamfundetUserRepository { +// @Autowired +// open lateinit var database: Database + +// fun findById(id: UUID): SamfundetUser? { +// return database.samfundet_users.find { it.id eq id } +// } + +// fun findAll(): List { +// return database.samfundet_users.toList() +// } + +// 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 +// } +// } diff --git a/static-files/blob_storage/__azurite_db_queue__.json b/static-files/blob_storage/__azurite_db_queue__.json index 687fb6e7..7529f67a 100644 --- a/static-files/blob_storage/__azurite_db_queue__.json +++ b/static-files/blob_storage/__azurite_db_queue__.json @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/static-files/blob_storage/__azurite_db_queue_extent__.json b/static-files/blob_storage/__azurite_db_queue_extent__.json index 373ca9d2..5d08341e 100644 --- a/static-files/blob_storage/__azurite_db_queue_extent__.json +++ b/static-files/blob_storage/__azurite_db_queue_extent__.json @@ -1 +1 @@ -{"filename":"/data/__azurite_db_queue_extent__.json","collections":[{"name":"$EXTENTS_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"id":{"name":"id","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$EXTENTS_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"} \ No newline at end of file +{"filename":"/data/__azurite_db_queue_extent__.json","collections":[{"name":"$EXTENTS_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"id":{"name":"id","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$EXTENTS_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"} \ No newline at end of file diff --git a/static-files/blob_storage/__azurite_db_table__.json b/static-files/blob_storage/__azurite_db_table__.json index 7c4d06de..9cdd9ed2 100644 --- a/static-files/blob_storage/__azurite_db_table__.json +++ b/static-files/blob_storage/__azurite_db_table__.json @@ -1 +1 @@ -{"filename":"/data/__azurite_db_table__.json","collections":[{"name":"$TABLES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"account":{"name":"account","dirty":false,"values":[]},"table":{"name":"table","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$TABLES_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":"$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":[]}],"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"} \ No newline at end of file +{"filename":"/data/__azurite_db_table__.json","collections":[{"name":"$TABLES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"account":{"name":"account","dirty":false,"values":[]},"table":{"name":"table","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$TABLES_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":"$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":[]}],"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"} \ No newline at end of file From 478417aebaa8a5051e0a104ab8102c0325f249fc Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 19 Sep 2024 19:56:14 +0200 Subject: [PATCH 02/16] Changed workflow to install docker compose first --- .github/workflows/ci-cd.yml | 70 +++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index b749985c..355d795a 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,34 +2,40 @@ # Runs on push to master name: CI-CD -# Controls when the action will run. on: - # Triggers the workflow on push or pull request events but only for the master branch push: - branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab + branches: [master] workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + + - name: Install Docker Compose + run: | + # Install Docker Compose + sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + + # Create a symbolic link to ensure it's accessible globally + sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose + + # Verify Docker Compose installation + docker-compose --version + - name: Build docker stack run: | - docker network create traefik - docker-compose -f docker-compose.yml -f docker-compose.test.yml up run-tests + docker network create traefik + docker-compose -f docker-compose.yml -f docker-compose.test.yml up run-tests - # This workflow contains a single job called "build" build-and-deploy: - # The type of runner that the job will run on runs-on: ubuntu-latest needs: test - # Steps represent a sequence of tasks that will be executed as part of the job steps: - uses: actions/checkout@v2 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -38,14 +44,13 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push Docker images - # You may pin to the exact commit or the version. - # uses: docker/build-push-action@0db984c1826869dcd0740ff26ff75ff543238fd9 uses: docker/build-push-action@v2.2.1 with: - tags: # optional - fotogjengen/hilfling-backend:latest - push: true #optional, default is false + tags: fotogjengen/hilfling-backend:latest + push: true + - name: "Package app outside docker" run: "mvn clean package spring-boot:repackage" @@ -59,25 +64,14 @@ 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]. - - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run ktlint with reviewdog + uses: ScaCap/action-ktlint@1.3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + level: error + reporter: github-pr-check + fail_on_error: false + relative: true From 834ab03716c6a64061db1c1e45b632271c584506 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 19 Sep 2024 20:20:51 +0200 Subject: [PATCH 03/16] Fixed some eslint, checking if done right --- .github/workflows/ci-cd.yml | 50 +++++++++++-------- .../controller/SamfundetUserController.kt | 5 +- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 355d795a..f7cfdba9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,40 +2,34 @@ # Runs on push to master name: CI-CD +# Controls when the action will run. on: + # Triggers the workflow on push or pull request events but only for the master branch push: branches: [master] + + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - - name: Install Docker Compose - run: | - # Install Docker Compose - sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose - - # Create a symbolic link to ensure it's accessible globally - sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose - - # Verify Docker Compose installation - docker-compose --version - - name: Build docker stack run: | docker network create traefik docker-compose -f docker-compose.yml -f docker-compose.test.yml up run-tests + # This workflow contains a single job called "build" build-and-deploy: + # The type of runner that the job will run on runs-on: ubuntu-latest needs: test + # Steps represent a sequence of tasks that will be executed as part of the job steps: - uses: actions/checkout@v2 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -44,13 +38,14 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push Docker images + # You may pin to the exact commit or the version. + # uses: docker/build-push-action@0db984c1826869dcd0740ff26ff75ff543238fd9 uses: docker/build-push-action@v2.2.1 with: - tags: fotogjengen/hilfling-backend:latest - push: true - + tags: # optional + fotogjengen/hilfling-backend:latest + push: true #optional, default is false - name: "Package app outside docker" run: "mvn clean package spring-boot:repackage" @@ -68,10 +63,21 @@ jobs: 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 }} - level: error - reporter: github-pr-check - fail_on_error: false - relative: true + # 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 diff --git a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt index e67d673e..04376333 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt @@ -9,8 +9,9 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/users") -open class SamfundetUserController(override val repository: SamfundetUserRepository) : - BaseController(repository) +open class SamfundetUserController( + override val repository: SamfundetUserRepository + ) : BaseController(repository) // class SamfundetUserController { // @Autowired lateinit var repository: SamfundetUserRepository From 75345d6e7f863ecb065fa674829676b65aecd388 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 26 Sep 2024 12:31:40 +0200 Subject: [PATCH 04/16] made some lint changes --- .../controller/SamfundetUserController.kt | 4 +- .../hilflingbackend/dto/SamfundetUserDto.kt | 44 ++++++++++--------- .../fg/hilflingbackend/model/SamfundetUser.kt | 22 +++++----- .../repository/SamfundetUserRepository.kt | 8 ++-- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt index 04376333..afa8933d 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt @@ -10,8 +10,8 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/users") open class SamfundetUserController( - override val repository: SamfundetUserRepository - ) : BaseController(repository) + override val repository: SamfundetUserRepository, +) : BaseController(repository) // class SamfundetUserController { // @Autowired lateinit var repository: SamfundetUserRepository diff --git a/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt b/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt index 6f58d9ad..c22f879d 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt @@ -1,33 +1,33 @@ package no.fg.hilflingbackend.dto -import java.util.UUID import no.fg.hilflingbackend.model.SamfundetUser import no.fg.hilflingbackend.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber +import java.util.UUID data class SamfundetUserPatchRequestDto( - val samfundetUserId: SamfundetUserId, - val firstName: String?, - val lastName: String?, - val username: String?, - val phoneNumber: PhoneNumber?, - val email: Email?, - val profilePicturePath: String?, - val sex: String?, - val securityLevel: SecurityLevelDto? + val samfundetUserId: SamfundetUserId, + val firstName: String?, + val lastName: String?, + val username: String?, + val phoneNumber: PhoneNumber?, + val email: Email?, + val profilePicturePath: String?, + val sex: String?, + val securityLevel: SecurityLevelDto?, ) data class SamfundetUserDto( - val samfundetUserId: SamfundetUserId = SamfundetUserId(), - val firstName: String, - val lastName: String, - val username: String, - val phoneNumber: PhoneNumber, - val email: Email, - // TODO: Rename SQL-scheme and interface to match this variablename - val profilePicturePath: String, - val sex: String, - val securityLevel: SecurityLevelDto + val samfundetUserId: SamfundetUserId = SamfundetUserId(), + val firstName: String, + val lastName: String, + val username: String, + val phoneNumber: PhoneNumber, + val email: Email, + // TODO: Rename SQL-scheme and interface to match this variablename + val profilePicturePath: String, + val sex: String, + val securityLevel: SecurityLevelDto, ) // Extend Dto object with a converter to ktorm interface @@ -46,6 +46,8 @@ fun SamfundetUserDto.toEntity(): SamfundetUser { } } -data class SamfundetUserId(override val id: UUID = UUID.randomUUID()) : UuidId { +data class SamfundetUserId( + override val id: UUID = UUID.randomUUID(), + ) : UuidId { override fun toString(): String = id.toString() } diff --git a/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt b/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt index 71e1b2d2..0527a25a 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt @@ -28,17 +28,17 @@ interface SamfundetUser : BaseModel { } fun SamfundetUser.toDto() = - SamfundetUserDto( - samfundetUserId = SamfundetUserId(this.id), - firstName = this.firstName, - lastName = this.lastName, - username = this.username, - email = Email(this.email), - profilePicturePath = this.profilePicture, - phoneNumber = PhoneNumber(this.phoneNumber), - securityLevel = this.securityLevel.toDto(), - sex = this.sex - ) + SamfundetUserDto( + samfundetUserId = SamfundetUserId(this.id), + firstName = this.firstName, + lastName = this.lastName, + username = this.username, + email = Email(this.email), + profilePicturePath = this.profilePicture, + phoneNumber = PhoneNumber(this.phoneNumber), + securityLevel = this.securityLevel.toDto(), + sex = this.sex, + ) object SamfundetUsers : BaseTable("samfundet_user") { val firstName = varchar("first_name").bindTo { it.firstName } diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index 561c916c..de515cd4 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -19,10 +19,12 @@ import no.fg.hilflingbackend.value_object.PhoneNumber import org.springframework.stereotype.Repository @Repository -open class SamfundetUserRepository(database: Database) : +open class SamfundetUserRepository( + database: Database + ) : BaseRepository( - table = SamfundetUsers, - database = database + table = SamfundetUsers, + database = database ) { override fun convertToClass(qrs: QueryRowSet): SamfundetUserDto = From 69294ac5ab52ef18b3999dbca87bc0718ae4eac1 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 26 Sep 2024 12:45:35 +0200 Subject: [PATCH 05/16] Made even more lint fixes --- .../hilflingbackend/dto/SamfundetUserDto.kt | 2 +- .../fg/hilflingbackend/model/SamfundetUser.kt | 2 +- .../repository/SamfundetUserRepository.kt | 95 +++++++++---------- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt b/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt index c22f879d..a79ac8a6 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/dto/SamfundetUserDto.kt @@ -48,6 +48,6 @@ fun SamfundetUserDto.toEntity(): SamfundetUser { data class SamfundetUserId( override val id: UUID = UUID.randomUUID(), - ) : UuidId { +) : UuidId { override fun toString(): String = id.toString() } diff --git a/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt b/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt index 0527a25a..779e314b 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/model/SamfundetUser.kt @@ -37,7 +37,7 @@ fun SamfundetUser.toDto() = profilePicturePath = this.profilePicture, phoneNumber = PhoneNumber(this.phoneNumber), securityLevel = this.securityLevel.toDto(), - sex = this.sex, + sex = this.sex, ) object SamfundetUsers : BaseTable("samfundet_user") { diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index de515cd4..b539614d 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -20,57 +20,56 @@ import org.springframework.stereotype.Repository @Repository open class SamfundetUserRepository( - database: Database - ) : - BaseRepository( - table = SamfundetUsers, - database = database - ) { + database: Database, +) : + BaseRepository( + table = SamfundetUsers, + database = database, + ) { - 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]!! - ) - ) - ) + 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]!!, + ), + ), + ) - override fun create(dto: SamfundetUserDto): Int { - return database.samfundet_users.add(dto.toEntity()) - } + override fun create(dto: SamfundetUserDto): Int { + return database.samfundet_users.add(dto.toEntity()) + } - 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 - } + 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 + } } // open class SamfundetUserRepository { From 7e17de3739f838c3177bf9c3284d6a008449c6fb Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 26 Sep 2024 12:51:53 +0200 Subject: [PATCH 06/16] some more lint fixes --- .../repository/SamfundetUserRepository.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index b539614d..3603185f 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -1,31 +1,32 @@ package no.fg.hilflingbackend.repository import javax.persistence.EntityNotFoundException +import javax.sql.DataSource +import kotlin.reflect.KClass + import me.liuwj.ktorm.database.Database 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 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.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber + import org.springframework.stereotype.Repository @Repository open class SamfundetUserRepository( database: Database, -) : - BaseRepository( - table = SamfundetUsers, - database = database, - ) { +) : BaseRepository( + table = SamfundetUsers, + database = database, + ) { override fun convertToClass(qrs: QueryRowSet): SamfundetUserDto = SamfundetUserDto( @@ -46,9 +47,7 @@ open class SamfundetUserRepository( ), ) - override fun create(dto: SamfundetUserDto): Int { - return database.samfundet_users.add(dto.toEntity()) - } + override fun create(dto: SamfundetUserDto): Int = database.samfundet_users.add(dto.toEntity()) override fun patch(dto: SamfundetUserPatchRequestDto): SamfundetUserDto { val fromDb = @@ -62,13 +61,13 @@ open class SamfundetUserRepository( username = dto.username ?: fromDb.username, phoneNumber = dto.phoneNumber ?: fromDb.phoneNumber, email = dto.email ?: fromDb.email, - profilePicturePath = dto.profilePicturePath - ?: fromDb.profilePicturePath, + 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 + return if (updated == 1) newDto else fromDb } } From b1deb5ed655d48a4f33205b45d000a563991a6f3 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 26 Sep 2024 12:56:59 +0200 Subject: [PATCH 07/16] More lint changes --- .../repository/SamfundetUserRepository.kt | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index 3603185f..5985e04c 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -1,15 +1,11 @@ package no.fg.hilflingbackend.repository import javax.persistence.EntityNotFoundException -import javax.sql.DataSource -import kotlin.reflect.KClass - import me.liuwj.ktorm.database.Database 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 no.fg.hilflingbackend.dto.SamfundetUserDto import no.fg.hilflingbackend.dto.SamfundetUserId import no.fg.hilflingbackend.dto.SamfundetUserPatchRequestDto @@ -17,16 +13,15 @@ import no.fg.hilflingbackend.model.SamfundetUser import no.fg.hilflingbackend.model.SamfundetUsers import no.fg.hilflingbackend.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber - import org.springframework.stereotype.Repository @Repository open class SamfundetUserRepository( database: Database, ) : BaseRepository( - table = SamfundetUsers, - database = database, - ) { + table = SamfundetUsers, + database = database, + ) { override fun convertToClass(qrs: QueryRowSet): SamfundetUserDto = SamfundetUserDto( @@ -47,7 +42,7 @@ open class SamfundetUserRepository( ), ) - override fun create(dto: SamfundetUserDto): Int = database.samfundet_users.add(dto.toEntity()) + override fun create(dto: SamfundetUserDto): Int = database.samfundet_users.add(dto.toEntity()) override fun patch(dto: SamfundetUserPatchRequestDto): SamfundetUserDto { val fromDb = @@ -61,13 +56,13 @@ open class SamfundetUserRepository( username = dto.username ?: fromDb.username, phoneNumber = dto.phoneNumber ?: fromDb.phoneNumber, email = dto.email ?: fromDb.email, - profilePicturePath = + 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 + return if (updated == 1) newDto else fromDb } } From 95bdd11155a1a687c8cce13ef2566f3b2ea951db Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 26 Sep 2024 12:59:21 +0200 Subject: [PATCH 08/16] final lint changes --- .../no/fg/hilflingbackend/repository/SamfundetUserRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index 5985e04c..e98c2bd5 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -1,6 +1,5 @@ package no.fg.hilflingbackend.repository -import javax.persistence.EntityNotFoundException import me.liuwj.ktorm.database.Database import me.liuwj.ktorm.dsl.QueryRowSet import me.liuwj.ktorm.entity.add @@ -14,6 +13,7 @@ import no.fg.hilflingbackend.model.SamfundetUsers import no.fg.hilflingbackend.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber import org.springframework.stereotype.Repository +import javax.persistence.EntityNotFoundException @Repository open class SamfundetUserRepository( From 7a453c93f04c63690f3ce5a6ef823ac8324eb75c Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 26 Sep 2024 13:21:37 +0200 Subject: [PATCH 09/16] Changing docker-compose to docker compose in ci and ci-cd files --- .github/workflows/ci-cd.yml | 2 +- .github/workflows/ci.yml | 44 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index f7cfdba9..269a6377 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -20,7 +20,7 @@ jobs: - name: Build docker stack run: | docker network create traefik - docker-compose -f docker-compose.yml -f docker-compose.test.yml up run-tests + docker compose -f docker-compose.yml -f docker-compose.test.yml up run-tests # This workflow contains a single job called "build" build-and-deploy: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb553d9..d95bdd52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -20,26 +20,26 @@ jobs: - uses: actions/checkout@v2 - name: Build docker stack run: | - docker network create traefik - docker-compose -f docker-compose.yml -f docker-compose.test.yml up run-tests + 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 From cf23037e196f717caa6e5b8948983b30de219b73 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Thu, 3 Oct 2024 19:05:00 +0200 Subject: [PATCH 10/16] added imports that had been deleted (accidentally) --- .../fg/hilflingbackend/repository/SamfundetUserRepository.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index e98c2bd5..df1a7745 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -8,8 +8,12 @@ import me.liuwj.ktorm.entity.find 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.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber import org.springframework.stereotype.Repository From ae0318e37a42d8c8e799aa00bcbefd857bb3f618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C3=B8lset=20Gisleberg?= Date: Fri, 11 Oct 2024 17:20:52 +0200 Subject: [PATCH 11/16] added configuration for multipart upload --- .../configurations/FileUploadConfiguration.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt diff --git a/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt b/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt new file mode 100644 index 00000000..23e5ea31 --- /dev/null +++ b/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt @@ -0,0 +1,15 @@ +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 MultipartConfig { + + @Bean + fun multipartResolver(): MultipartResolver { + return StandardServletMultipartResolver() + } +} From 1c80bf3b20dff4f65ef787651d8725e4ec0c1ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C3=B8lset=20Gisleberg?= Date: Thu, 17 Oct 2024 18:06:23 +0200 Subject: [PATCH 12/16] endret sonarcloud java version fra 11 til 21 --- .github/workflows/master_hilfling-backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/master_hilfling-backend.yml b/.github/workflows/master_hilfling-backend.yml index 4b9efeae..62b28c53 100644 --- a/.github/workflows/master_hilfling-backend.yml +++ b/.github/workflows/master_hilfling-backend.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Java version uses: actions/setup-java@v1 with: - java-version: '11' + java-version: '21' - name: Build with Maven run: mvn clean install From cda0d01e73dd49832120ad06df62f557a3a37731 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Sat, 26 Oct 2024 13:19:24 +0200 Subject: [PATCH 13/16] Fixed issue of totalrecords not showing the right amount --- .../no/fg/hilflingbackend/repository/BaseRepository.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/BaseRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/BaseRepository.kt index c60b4877..b0ef9c59 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/BaseRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/BaseRepository.kt @@ -37,9 +37,9 @@ abstract class BaseRepository, D, R>(val table: BaseTable, 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) } ) } From 0ae63760598bcfe5cda89c794724e6e24d673f79 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Sat, 26 Oct 2024 14:17:30 +0200 Subject: [PATCH 14/16] Removed some comments --- .../configurations/FileUploadConfiguration.kt | 3 +- .../controller/SamfundetUserController.kt | 19 ----------- .../repository/SamfundetUserRepository.kt | 32 ------------------- 3 files changed, 1 insertion(+), 53 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt b/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt index 23e5ea31..3107ab19 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt @@ -6,8 +6,7 @@ import org.springframework.web.multipart.MultipartResolver import org.springframework.web.multipart.support.StandardServletMultipartResolver @Configuration -class MultipartConfig { - +class FileUploadConfiguration { @Bean fun multipartResolver(): MultipartResolver { return StandardServletMultipartResolver() diff --git a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt index afa8933d..145a995e 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.kt @@ -12,22 +12,3 @@ import org.springframework.web.bind.annotation.RestController open class SamfundetUserController( override val repository: SamfundetUserRepository, ) : BaseController(repository) - -// class SamfundetUserController { -// @Autowired lateinit var repository: SamfundetUserRepository - -// @GetMapping("/{id}") -// fun getById(@PathVariable("id") id: UUID): SamfundetUser? { -// return repository.findById(id) -// } - -// @GetMapping -// fun getAll(): List { -// return repository.findAll() -// } - -// @PostMapping -// fun create(@RequestBody user: SamfundetUserDto): SamfundetUserDto? { -// return repository.create(user) -// } -// } diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index df1a7745..802ab01e 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -69,35 +69,3 @@ open class SamfundetUserRepository( return if (updated == 1) newDto else fromDb } } - -// open class SamfundetUserRepository { -// @Autowired -// open lateinit var database: Database - -// fun findById(id: UUID): SamfundetUser? { -// return database.samfundet_users.find { it.id eq id } -// } - -// fun findAll(): List { -// return database.samfundet_users.toList() -// } - -// 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 -// } -// } From feac8dc1944a22efcd3b8332ac8c2d840584b722 Mon Sep 17 00:00:00 2001 From: Philip Torvund Bennett Date: Sat, 26 Oct 2024 15:49:55 +0200 Subject: [PATCH 15/16] Fixed som eslint --- .../hilflingbackend/configurations/FileUploadConfiguration.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt b/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt index 3107ab19..b0567961 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.kt @@ -8,7 +8,5 @@ import org.springframework.web.multipart.support.StandardServletMultipartResolve @Configuration class FileUploadConfiguration { @Bean - fun multipartResolver(): MultipartResolver { - return StandardServletMultipartResolver() - } + fun multipartResolver(): MultipartResolver = StandardServletMultipartResolver() } From f11461f34cf64e63e70e0c9fd8800a03d6dab53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C3=B8lset=20Gisleberg?= Date: Sun, 27 Oct 2024 08:41:56 +0100 Subject: [PATCH 16/16] changed import from javax to jakarta --- .../no/fg/hilflingbackend/repository/SamfundetUserRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt index 802ab01e..e051aac3 100644 --- a/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt +++ b/src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.kt @@ -17,7 +17,7 @@ import no.fg.hilflingbackend.model.samfundet_users import no.fg.hilflingbackend.value_object.Email import no.fg.hilflingbackend.value_object.PhoneNumber import org.springframework.stereotype.Repository -import javax.persistence.EntityNotFoundException +import jakarta.persistence.EntityNotFoundException @Repository open class SamfundetUserRepository(