Skip to content

Commit

Permalink
Adopt code for new visibility type
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Feb 14, 2024
1 parent 8e33685 commit 7d3a408
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 46 deletions.
33 changes: 0 additions & 33 deletions modules/commons/src/main/scala/io/renku/commons/Visibility.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down

0 comments on commit 7d3a408

Please sign in to comment.