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

added endpoints #296

Closed
wants to merge 18 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import java.util.UUID

@RestController
@RequestMapping("/albums")
Expand All @@ -23,4 +26,13 @@ class AlbumController(override val repository: AlbumRepository, val service: Alb
dto
)
}

@GetMapping("/getUuidByTitle")
fun getAlbumIdByName(
@RequestParam(
"albumTitle",
) albumTitle: String,
): UUID? {
return repository.findUuidByMotive(albumTitle)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class MotiveController {
return repository.findAll(page ?: 0, pageSize ?: 100)
}

@GetMapping("/getUuidByTitle")
fun getAlbumIdByName(
@RequestParam(
"motiveTitle",
) motiveTitle: String,
): UUID? {
return repository.findUuidByMotive(motiveTitle)
}

@PostMapping
fun create(
@RequestBody dto: MotiveDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ import no.fg.hilflingbackend.dto.PlaceDto
import no.fg.hilflingbackend.dto.PlacePatchRequestDto
import no.fg.hilflingbackend.model.Place
import no.fg.hilflingbackend.repository.PlaceRepository
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.UUID

@RestController
@RequestMapping("/places")
open class PlaceController(override val repository: PlaceRepository) : BaseController<Place, PlaceDto, PlacePatchRequestDto>(repository)
open class PlaceController(override val repository: PlaceRepository) : BaseController<Place, PlaceDto, PlacePatchRequestDto>(repository) {
@GetMapping("/getUuidByTitle")
fun getUuidByPlace(
@RequestParam(
"placeTitle",
) placeTitle: String,
): UUID? {
return repository.findUuidByPlace(placeTitle)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package no.fg.hilflingbackend.repository

import me.liuwj.ktorm.database.Database
import me.liuwj.ktorm.dsl.QueryRowSet
import me.liuwj.ktorm.dsl.eq
import me.liuwj.ktorm.entity.find
import me.liuwj.ktorm.entity.add
import me.liuwj.ktorm.entity.update
import no.fg.hilflingbackend.dto.AlbumDto
Expand All @@ -13,6 +15,7 @@ import no.fg.hilflingbackend.model.Albums
import no.fg.hilflingbackend.model.albums
import org.springframework.stereotype.Repository
import javax.persistence.EntityNotFoundException
import java.util.UUID

@Repository
open class AlbumRepository(database: Database) : BaseRepository<Album, AlbumDto, AlbumPatchRequestDto>(table = Albums, database = database) {
Expand All @@ -38,4 +41,15 @@ open class AlbumRepository(database: Database) : BaseRepository<Album, AlbumDto,

return if (updated == 1) newDto else fromDb
}

fun findUuidByMotive(title: String): UUID? {
val motive =
database.albums.find {
it.title eq title
}
?: throw EntityNotFoundException(
"could not find motive title",
)
return motive.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ open class MotiveRepository {

return if (updated == 1) newDto else fromDb
}

fun findUuidByMotive(motiveName: String): UUID? {
val motive =
database.motives.find {
it.title eq motiveName
}
?: throw EntityNotFoundException(
"could not find matching place",
)
return motive.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import no.fg.hilflingbackend.model.places
import no.fg.hilflingbackend.model.toDto
import org.springframework.stereotype.Repository
import javax.persistence.EntityNotFoundException
import java.util.UUID

@Repository
open class PlaceRepository(database: Database) : BaseRepository<Place, PlaceDto, PlacePatchRequestDto>(table = Places, database = database) {
Expand Down Expand Up @@ -47,4 +48,15 @@ open class PlaceRepository(database: Database) : BaseRepository<Place, PlaceDto,

return if (updated == 1) newDto else fromDb
}

fun findUuidByPlace(name: String): UUID? {
val place =
database.places.find {
it.name eq name
}
?: throw EntityNotFoundException(
"could not find matching place",
)
return place.id
}
}
Loading