diff --git a/modules/commons/src/main/scala/io/renku/commons/Visibility.scala b/modules/commons/src/main/scala/io/renku/commons/Visibility.scala deleted file mode 100644 index 16ef2729..00000000 --- a/modules/commons/src/main/scala/io/renku/commons/Visibility.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2024 Swiss Data Science Center (SDSC) - * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and - * Eidgenössische Technische Hochschule Zürich (ETHZ). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.renku.commons - -import cats.kernel.Order - -enum Visibility: - case Public - case Private - - def name: String = productPrefix.toLowerCase - -object Visibility: - given Order[Visibility] = Order.by(_.ordinal) - - def unsafeFromString(s: String): Visibility = - Visibility.valueOf(s.capitalize) diff --git a/modules/commons/src/main/scala/io/renku/search/model/projects.scala b/modules/commons/src/main/scala/io/renku/search/model/projects.scala index 61cca498..0a24005f 100644 --- a/modules/commons/src/main/scala/io/renku/search/model/projects.scala +++ b/modules/commons/src/main/scala/io/renku/search/model/projects.scala @@ -18,6 +18,7 @@ package io.renku.search.model +import cats.kernel.Order import io.bullet.borer.derivation.MapBasedCodecs.* import io.bullet.borer.{Codec, Decoder, Encoder} import io.renku.search.borer.codecs.all.given @@ -70,9 +71,13 @@ object projects: given Codec[CreationDate] = Codec.of[Instant] enum Visibility derives Codec: - lazy val name: String = productPrefix + lazy val name: String = productPrefix.toLowerCase case Public, Private object Visibility: - def fromCaseInsensitive(v: String): Visibility = + given Order[Visibility] = Order.by(_.ordinal) + given Decoder[Visibility] = Decoder.forString.map(Visibility.unsafeFromString) + given Encoder[Visibility] = Encoder.forString.contramap(_.name) + + def unsafeFromString(v: String): Visibility = valueOf(v.toLowerCase.capitalize) diff --git a/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala b/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala index 2904f1ee..e13bdf82 100644 --- a/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala +++ b/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala @@ -112,7 +112,7 @@ private class SearchProvisionerImpl[F[_]: Async]( projects.Name(pc.name), projects.Slug(pc.slug), pc.repositories.map(projects.Repository(_)), - projects.Visibility.fromCaseInsensitive(pc.visibility.name()), + projects.Visibility.unsafeFromString(pc.visibility.name()), pc.description.map(projects.Description(_)), toUser(pc.createdBy), projects.CreationDate(pc.creationDate), diff --git a/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala b/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala index 9856ce36..68944db8 100644 --- a/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala +++ b/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala @@ -124,7 +124,7 @@ class SearchProvisionerSpec extends CatsEffectSuite with RedisSpec with SearchSo projects.Name(created.name), projects.Slug(created.slug), created.repositories.map(projects.Repository(_)), - projects.Visibility.fromCaseInsensitive(created.visibility.name()), + projects.Visibility.unsafeFromString(created.visibility.name()), created.description.map(projects.Description(_)), toUser(created.createdBy), projects.CreationDate(created.creationDate), diff --git a/modules/search-query/src/main/scala/io/renku/search/query/FieldTerm.scala b/modules/search-query/src/main/scala/io/renku/search/query/FieldTerm.scala index c27f202d..aee0cc5f 100644 --- a/modules/search-query/src/main/scala/io/renku/search/query/FieldTerm.scala +++ b/modules/search-query/src/main/scala/io/renku/search/query/FieldTerm.scala @@ -19,7 +19,7 @@ package io.renku.search.query import cats.data.NonEmptyList -import io.renku.commons.Visibility +import io.renku.search.model.projects.Visibility enum FieldTerm(val field: Field, val cmp: Comparison): case ProjectIdIs(values: NonEmptyList[String]) diff --git a/modules/search-query/src/main/scala/io/renku/search/query/Query.scala b/modules/search-query/src/main/scala/io/renku/search/query/Query.scala index fa6fc963..acf3f00f 100644 --- a/modules/search-query/src/main/scala/io/renku/search/query/Query.scala +++ b/modules/search-query/src/main/scala/io/renku/search/query/Query.scala @@ -21,7 +21,7 @@ package io.renku.search.query import cats.data.NonEmptyList import cats.syntax.all.* import io.bullet.borer.{Decoder, Encoder} -import io.renku.commons.Visibility +import io.renku.search.model.projects.Visibility import io.renku.search.query.FieldTerm.Created import io.renku.search.query.Query.Segment import io.renku.search.query.json.QueryJsonCodec diff --git a/modules/search-query/src/main/scala/io/renku/search/query/json/QueryJsonCodec.scala b/modules/search-query/src/main/scala/io/renku/search/query/json/QueryJsonCodec.scala index 662c1866..21239fb2 100644 --- a/modules/search-query/src/main/scala/io/renku/search/query/json/QueryJsonCodec.scala +++ b/modules/search-query/src/main/scala/io/renku/search/query/json/QueryJsonCodec.scala @@ -21,7 +21,7 @@ package io.renku.search.query.json import cats.data.NonEmptyList import io.bullet.borer.compat.cats.* import io.bullet.borer.{Decoder, Encoder, Reader, Writer} -import io.renku.commons.Visibility +import io.renku.search.model.projects.Visibility import io.renku.search.query.* import io.renku.search.query.FieldTerm.* import io.renku.search.query.Query.Segment @@ -44,10 +44,6 @@ import scala.collection.mutable.ListBuffer * }}} */ private[query] object QueryJsonCodec: - // temporary - given Decoder[Visibility] = Decoder.forString.map(Visibility.unsafeFromString) - given Encoder[Visibility] = Encoder.forString.contramap(_.name) - private[this] val freeTextField = "_text" enum Name: diff --git a/modules/search-query/src/main/scala/io/renku/search/query/parse/QueryParser.scala b/modules/search-query/src/main/scala/io/renku/search/query/parse/QueryParser.scala index 326c3f83..d7f54a42 100644 --- a/modules/search-query/src/main/scala/io/renku/search/query/parse/QueryParser.scala +++ b/modules/search-query/src/main/scala/io/renku/search/query/parse/QueryParser.scala @@ -20,7 +20,7 @@ package io.renku.search.query.parse import cats.data.NonEmptyList import cats.parse.{Parser as P, Parser0 as P0} -import io.renku.commons.Visibility +import io.renku.search.model.projects.Visibility import io.renku.search.query.* private[query] object QueryParser { diff --git a/modules/search-query/src/test/scala/io/renku/search/query/QueryGenerators.scala b/modules/search-query/src/test/scala/io/renku/search/query/QueryGenerators.scala index 36b73ca9..6c016caa 100644 --- a/modules/search-query/src/test/scala/io/renku/search/query/QueryGenerators.scala +++ b/modules/search-query/src/test/scala/io/renku/search/query/QueryGenerators.scala @@ -20,7 +20,7 @@ package io.renku.search.query import cats.data.NonEmptyList import cats.syntax.all.* -import io.renku.commons.Visibility +import io.renku.search.model.projects.Visibility import io.renku.search.query.parse.QueryUtil import org.scalacheck.Gen import org.scalacheck.cats.implicits.*