cleanup api a bit, load assets live

This commit is contained in:
Aaron Bieber 2023-04-30 06:59:29 -06:00
parent ab35fe1ea1
commit be40114e72
No known key found for this signature in database
4 changed files with 57 additions and 17 deletions

View File

@ -329,14 +329,7 @@ func linkDELETE(w http.ResponseWriter, r *http.Request) {
}
var templateFuncs = template.FuncMap{
"includeWatch": func(repo string, number int, ignoreList []data.PullRequestIgnore) bool {
for _, pri := range ignoreList {
if pri.Repo == repo && pri.Number == int64(number) {
return false
}
}
return true
},
"includeWatch": includeWatch,
"remaining": func(d time.Time) string {
ct := time.Now()
left := d.Sub(ct)

View File

@ -104,16 +104,13 @@ func main() {
}
}()
fileServer := http.FileServer(http.FS(assets))
liveServer := http.FileServer(http.Dir("./assets"))
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(OwnerCtx)
r.Mount("/assets", fileServer)
r.Route("/", func(r chi.Router) {
r.Get("/", index)
})
r.Mount("/", liveServer)
r.Route("/pullrequests", func(r chi.Router) {
r.Use(render.SetContentType(render.ContentTypeJSON))
r.Get("/", pullrequestsGET)

View File

@ -1,4 +1,22 @@
module Data exposing (Node, RepoInfo, Watch)
module Data exposing (Link, Links, Node, RepoInfo, Watch, Watches)
type alias Watches =
List Watch
type alias Links =
List Link
type alias Link =
{ id : Int
, createdAt : String
, url : String
, name : String
, logoURL : String
, shared : Bool
}
type alias Watch =
@ -6,7 +24,7 @@ type alias Watch =
, name : String
, repo : String
, resultCount : Int
, results : Maybe (List Node)
, results : List Node
}

View File

@ -9,6 +9,8 @@ import (
"net/http"
"sort"
"time"
"suah.dev/gostart/data"
)
const gqEndPoint = "https://api.github.com/graphql"
@ -57,16 +59,47 @@ type GQLQuery struct {
type WatchResults []WatchResult
func includeWatch(repo string, number int, ignoreList []data.PullRequestIgnore) bool {
for _, pri := range ignoreList {
if pri.Repo == repo && pri.Number == int64(number) {
return false
}
}
return true
}
func (w *WatchResults) forID(ownerID int64) *WatchResults {
newResults := WatchResults{}
tmpResults := WatchResults{}
ctx := context.Background()
ignores, _ := app.queries.GetAllPullRequestIgnores(ctx, ownerID)
for _, r := range *w {
if r.OwnerID == ownerID {
newResults = append(newResults, r)
if r.Results == nil {
r.Results = make([]Node, 0)
}
tmpResults = append(tmpResults, r)
}
}
sort.Slice(newResults, func(i, j int) bool {
return newResults[i].Name < newResults[j].Name
})
for _, r := range tmpResults {
tmpResultList := []Node{}
for _, entry := range r.Results {
if includeWatch(entry.Repository.NameWithOwner, entry.Number, ignores) {
tmpResultList = append(tmpResultList, entry)
}
}
r.Results = tmpResultList
r.ResultCount = len(tmpResultList)
newResults = append(newResults, r)
}
return &newResults
}
@ -100,7 +133,6 @@ func UpdateWatches(ghToken string) (*WatchResults, error) {
wr.OwnerID = watch.OwnerID
wr.Name = watch.Name
wr.Repo = watch.Repo
wr.ResultCount = wr.Data.Search.IssueCount
for _, dr := range wr.Data.Search.Edges {
wr.Results = append(wr.Results, dr.Node)
}