-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created samfundetUserController, updated repository to use basereposi…
…tory (#299) * Created samfundetUserController, updated repository to use baserepository * Changed workflow to install docker compose first * Fixed some eslint, checking if done right * made some lint changes * Made even more lint fixes * some more lint fixes * More lint changes * final lint changes * Changing docker-compose to docker compose in ci and ci-cd files * added imports that had been deleted (accidentally) * added configuration for multipart upload * endret sonarcloud java version fra 11 til 21 * Fixed issue of totalrecords not showing the right amount * Removed some comments * Fixed som eslint * changed import from javax to jakarta --------- Co-authored-by: Philip Torvund Bennett <philitb@stud.ntnu.no> Co-authored-by: Marius Bølset Gisleberg <Marius.marcello@live.no>
- Loading branch information
1 parent
8485d3f
commit 2ba4d1d
Showing
11 changed files
with
136 additions
and
85 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
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
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/no/fg/hilflingbackend/configurations/FileUploadConfiguration.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,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() | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/no/fg/hilflingbackend/controller/SamfundetUserController.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,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) |
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
85 changes: 54 additions & 31 deletions
85
src/main/kotlin/no/fg/hilflingbackend/repository/SamfundetUserRepository.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 |
---|---|---|
@@ -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 | ||
} | ||
} |
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 |
---|---|---|
@@ -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"} |
Oops, something went wrong.