Citymonstret/Kvantum

Add examples

Citymonstret opened this issue · 0 comments

Like:

@KvantumObject
@RequiredArgsConstructor
@Getter
public static class WorkoutStep
{

  @NotNegative( default = "1" )
  @KvantumField
  private int reps;
  @KvantumField( default = "1" )
  private int sets;
  @KvantumField( default = "60" )
  private int rest;
  
  @KvantumConstructor
  public WorkoutStep() {}

}

private static final Validator validator = new Validator();

@ViewMatcher(router = "api/workout/step/create", httpMethod = HttpMethod.POST, outputType = "json")
public JSONObject createWorkoutStep(final AbstractRequest request)
{
  final WorkoutStep step = KvantumObjectFactory.from( WorkoutStep.class ).build( ParameterScope.POST ).of( request ).getParsedObject();
  final KvantumPojo<WorkoutStep> pojo = KvantumPojoFactory.forClass( WorkoutStep.class ).of( step );
  final val validationErrors = validator.validate( pojo );
  if ( !validationErrors.isEmpty() )
  {
    // create error message
    return new JSONObject();
  }
  // Store step in database...
  return pojo.toJson();-
}