nouritsu/src/main/java/nouritsu/types/Store.java

21 lines
662 B
Java

package nouritsu.types;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.vavr.collection.List;
import io.vavr.collection.Seq;
import io.vavr.control.Either;
/**
* A store with an ordered list of sections from entrance to exit.
*/
public record Store(
@JsonProperty("name") String name,
@JsonProperty("sections") Seq<Section> sections
) {
public static Either<Resp, Store> tryParse(String name, String sections) {
return Either.traverse(List.of(sections.split(",")), Section::tryParse)
.mapLeft(errors -> Resp.BAD_REQUEST.apply(errors.mkString("\n") + Section.valuesAsString()))
.map(secs -> new Store(name, secs));
}
}