Skip to content

Commit

Permalink
(api) just use type
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed May 19, 2024
1 parent af630a5 commit 7d49b26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/frontend/src/components/ReadmeDashboard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
<h2 class="font-bold text-slate-200 pb-1 select-none">Stats</h2>
<template x-if="types.length > 0">
<img
class="inline select-none mt-5 mb-5"
class="inline select-none mt-5 mb-5 rounded-lg"
is:raw
:src="`//${url}/table?org=${org}&repo=${repo}&branch=${branch}&theme=dark`"
/>
Expand Down Expand Up @@ -152,7 +152,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
<div class="border-slate-800 border-2 rounded p-2 text-center">
<template x-for="t in types">
<img
class="inline select-none"
class="inline select-none rounded-lg p-1"
is:raw
:src="`//${url}/chart?org=${org}&repo=${repo}&branch=${branch}&type=${t.name}&theme=dark&line=fill&width=120&height=120&output=svg`"
/>
Expand Down Expand Up @@ -202,7 +202,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
<div class="text-center">
<template x-for="t in types">
<img
class="inline select-none"
class="inline select-none p-1 rounded-lg"
is:raw
:src="`//${url}/chart?org=${org}&repo=${repo}&branch=${branch}&type=${t.name}&theme=dark&line=fill&width=150&height=150&output=svg`"
/>
Expand Down Expand Up @@ -275,12 +275,12 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
<div class="pb-2 select-none flex justify-center items-center">
<img
is:raw
:src="`//${url}/chart?org=${org}&repo=${repo}&branch=${branch}&types=${ts.map(t => t.name).join(',')}&theme=dark`"
:src="`//${url}/chart?org=${org}&repo=${repo}&branch=${branch}&type=${ts.map(t => t.name).join(',')}&theme=dark`"
alt="Chart"
/>
</div>
<code class="font-mono text-slate-500 break-words text-sm">
![<span x-text="ts.map(t => t.name).join(',')"></span>](https://<span x-text="url"></span>/chart?org=<span x-text="org"></span>&repo=<span x-text="repo"></span>&branch=<span x-text="branch"></span>&types=<span x-text="ts.map(t => t.name).join(',')"></span>)
![<span x-text="ts.map(t => t.name).join(',')"></span>](https://<span x-text="url"></span>/chart?org=<span x-text="org"></span>&repo=<span x-text="repo"></span>&branch=<span x-text="branch"></span>&type=<span x-text="ts.map(t => t.name).join(',')"></span>)
</code>
</dd>
</div>
Expand Down
14 changes: 8 additions & 6 deletions app/pkg/chart_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ type ChartRequest struct {
Branch string `json:"branch" query:"branch" validate:"ascii" message:"ascii branch is required"`
User string `json:"user" query:"user" validate:"ascii,excludes=/" message:"ascii user is required"`
BaseBranch string `json:"base_branch" query:"base_branch" validate:"ascii" message:"ascii base_branch is required"`
Type string `json:"type" query:"type" validate:"ascii" message:"ascii type is required"`
Types string `json:"types" query:"types" validate:"ascii" message:"ascii types are required"`
Type string `json:"type" query:"type" validate:"required,ascii" message:"ascii type is required"`
Branches string `json:"branches" query:"branches" validate:"ascii" message:"ascii branches is required"`
Users string `json:"users" query:"users" validate:"ascii" message:"ascii users is required"`
PRNum int `json:"pr_num" query:"pr_num"`
Expand All @@ -52,15 +51,18 @@ func (h *ChartHandler) Get(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusUnprocessableEntity, msgs)
}
if req.Types == "" && req.Type == "" {
return echo.NewHTTPError(http.StatusUnprocessableEntity, "types or type is required")

typesMany := []string{}
if strings.Contains(req.Type, ",") {
typesMany = strings.Split(req.Type, ",")
}
if req.Types != "" {

if len(typesMany) > 1 {
if req.Branch == "" {
return echo.NewHTTPError(http.StatusUnprocessableEntity, "branch for types is required")
}
types := []*models.Type{}
for _, t := range strings.Split(req.Types, ",") {
for _, t := range typesMany {
tt, err := h.Chart.GetType(t)
if err != nil {
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error())
Expand Down

0 comments on commit 7d49b26

Please sign in to comment.