001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.petstore.console.dev;
018
019import java.util.*;
020
021import org.apache.juneau.petstore.console.*;
022import org.apache.juneau.petstore.console.pages.*;
023import org.apache.juneau.rest.server.*;
024import org.apache.juneau.rest.server.view.*;
025
026/**
027 * Charts: the chart-core demo page, built with {@link DevPageBuilders#charts()} only (it has no template twin).
028 *
029 * <h5 class='section'>Example:</h5>
030 * <p class='bcode'>
031 *    GET /console/dev/charts
032 *    GET /console/dev/charts/daily
033 * </p>
034 */
035@Rest(path="/charts", title="Charts")
036@SuppressWarnings({
037   "java:S110" // Inheritance depth comes from the BasicRestServlet hierarchy, not this page.
038})
039public class ChartsRest extends PetstoreConsolePage {
040
041   private static final long serialVersionUID = 1L;
042
043   private static final String[] DAYS = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
044   private static final int[] PLACED = {3, 5, 4, 7, 6, 2, 1};
045   private static final int[] DELIVERED = {1, 2, 4, 5, 6, 2, 1};
046
047   /**
048    * Renders the Charts page.
049    *
050    * @param req The request.
051    * @return The page.
052    */
053   @RestGet(path="/")
054   public View page(RestRequest req) {
055      return twin(req, DevPageBuilders.charts());
056   }
057
058   /**
059    * The week's order counts the chart and the table draw.
060    *
061    * @return One row per day.
062    */
063   @RestGet(path="/daily")
064   public List<Map<String,Object>> daily() {
065      var l = new ArrayList<Map<String,Object>>();
066      for (var i = 0; i < DAYS.length; i++)
067         l.add(Map.of("day", DAYS[i], "placed", PLACED[i], "delivered", DELIVERED[i]));
068      return l;
069   }
070}