-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route for getting information for resources /v2/resources/info
includes orderBy [creationDate|lastmodficationDate], and order [ASC|DESC]. Http Example request: GET /v2/resources/info?resourceClass=http%3A%2F%2F0.0.0.0%3A3333%2Fontology%2F0001%2Fanything%2Fv2%23Thing&order=DESC&orderBy=creationDate HTTP/1.1 X-Knora-Accept-Project: http://rdfh.ch/projects/Lw3FC39BSzCwvmdOaTyLqQ Http Example response: { "resources": [ { "resourceIri": "http://rdfh.ch/0001/thing-with-pages", "creationDate": "2021-05-11T10:00:00Z", "lastModificationDate": "2021-05-11T10:00:00Z", "isDeleted": false }, { "resourceIri": "http://rdfh.ch/0001/0JhgKcqoRIeRRG6ownArSw", "creationDate": "2020-04-07T09:12:56.710717Z", "lastModificationDate": "2020-04-07T09:12:56.710717Z", "isDeleted": false }, ... ] }
- Loading branch information
Showing
19 changed files
with
488 additions
and
97 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
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
22 changes: 22 additions & 0 deletions
22
.../src/main/scala/org/knora/webapi/slice/resourceinfo/api/LiveRestResourceInfoService.scala
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,22 @@ | ||
package org.knora.webapi.slice.resourceinfo.api | ||
|
||
import org.knora.webapi.IRI | ||
import org.knora.webapi.slice.resourceinfo.repo.ResourceInfoRepo | ||
import org.knora.webapi.slice.resourceinfo.repo.ResourceInfoRepo.{Order, OrderBy} | ||
import zio.{UIO, ZIO, ZLayer} | ||
|
||
final case class LiveRestResourceInfoService(repo: ResourceInfoRepo) extends RestResourceInfoService { | ||
override def findByProjectAndResourceClass( | ||
projectIri: IRI, | ||
resourceClass: IRI, | ||
ordering: (OrderBy, Order) | ||
): UIO[ListResponseDto] = | ||
for { | ||
result <- repo.findByProjectAndResourceClass(projectIri, resourceClass, ordering).map(_.map(ResourceInfoDto(_))) | ||
} yield ListResponseDto(result) | ||
} | ||
|
||
object LiveRestResourceInfoService { | ||
val layer: ZLayer[ResourceInfoRepo, Nothing, LiveRestResourceInfoService] = | ||
ZLayer.fromZIO(ZIO.service[ResourceInfoRepo].map(new LiveRestResourceInfoService(_))) | ||
} |
34 changes: 34 additions & 0 deletions
34
webapi/src/main/scala/org/knora/webapi/slice/resourceinfo/api/ResourceInfoDto.scala
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,34 @@ | ||
package org.knora.webapi.slice.resourceinfo.api | ||
|
||
import org.knora.webapi.IRI | ||
import org.knora.webapi.slice.resourceinfo.repo.ResourceInfo | ||
import zio.json._ | ||
|
||
import java.time.Instant | ||
|
||
final case class ListResponseDto private (resources: List[ResourceInfoDto], count: Int) | ||
object ListResponseDto { | ||
val empty: ListResponseDto = ListResponseDto(List.empty, 0) | ||
def apply(list: List[ResourceInfoDto]): ListResponseDto = list match { | ||
case Nil => ListResponseDto.empty | ||
case list => ListResponseDto(list, list.size) | ||
} | ||
|
||
implicit val encoder: JsonEncoder[ListResponseDto] = | ||
DeriveJsonEncoder.gen[ListResponseDto] | ||
} | ||
|
||
final case class ResourceInfoDto private ( | ||
resourceIri: IRI, | ||
creationDate: Instant, | ||
lastModificationDate: Instant, | ||
deleteDate: Option[Instant], | ||
isDeleted: Boolean | ||
) | ||
object ResourceInfoDto { | ||
def apply(info: ResourceInfo): ResourceInfoDto = | ||
ResourceInfoDto(info.iri, info.creationDate, info.lastModificationDate, info.deleteDate, info.isDeleted) | ||
|
||
implicit val encoder: JsonEncoder[ResourceInfoDto] = | ||
DeriveJsonEncoder.gen[ResourceInfoDto] | ||
} |
22 changes: 22 additions & 0 deletions
22
webapi/src/main/scala/org/knora/webapi/slice/resourceinfo/api/RestResourceInfoService.scala
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,22 @@ | ||
package org.knora.webapi.slice.resourceinfo.api | ||
|
||
import org.knora.webapi.IRI | ||
import org.knora.webapi.slice.resourceinfo.repo.ResourceInfoRepo.{ASC, Order, OrderBy, lastModificationDate} | ||
import zio.{UIO, ZIO} | ||
|
||
trait RestResourceInfoService { | ||
def findByProjectAndResourceClass( | ||
projectIri: IRI, | ||
resourceClass: IRI, | ||
ordering: (OrderBy, Order) | ||
): UIO[ListResponseDto] | ||
} | ||
|
||
object RestResourceInfoService { | ||
def findByProjectAndResourceClass( | ||
projectIri: IRI, | ||
resourceClass: IRI, | ||
ordering: (OrderBy, Order) = (lastModificationDate, ASC) | ||
): ZIO[RestResourceInfoService, Nothing, ListResponseDto] = | ||
ZIO.service[RestResourceInfoService].flatMap(_.findByProjectAndResourceClass(projectIri, resourceClass, ordering)) | ||
} |
Oops, something went wrong.