16 lines
473 B
Java
16 lines
473 B
Java
package nouritsu.types;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import io.vavr.control.Either;
|
|
|
|
public record ShoppingItem(
|
|
@JsonProperty("name") String name,
|
|
@JsonProperty("section") Section section
|
|
) {
|
|
public static Either<Resp, ShoppingItem> tryParse(String name, String category) {
|
|
return Section.tryParse(category)
|
|
.map(c -> new ShoppingItem(name, c))
|
|
.mapLeft(msg -> Resp.BAD_REQUEST.apply(msg + Section.valuesAsString()));
|
|
}
|
|
}
|