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

21 lines
662 B
Java
Raw Normal View History

2020-07-03 13:05:23 +02:00
package nouritsu.types;
2020-07-09 21:57:51 +02:00
import com.fasterxml.jackson.annotation.JsonProperty;
import io.vavr.collection.List;
import io.vavr.collection.Seq;
import io.vavr.control.Either;
2020-07-03 13:05:23 +02:00
/**
* A store with an ordered list of sections from entrance to exit.
*/
2020-07-09 21:57:51 +02:00
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));
}
2020-07-03 13:05:23 +02:00
}