Browse Source

Add public houses endpoint

T280
tags/v1.0
Matt Baer 8 years ago
parent
commit
c20a51dfff
3 changed files with 29 additions and 3 deletions
  1. +1
    -0
      app.go
  2. +13
    -0
      construction.go
  3. +15
    -3
      models.go

+ 1
- 0
app.go View File

@@ -56,6 +56,7 @@ func (app *app) initRouter() {
api := app.router.PathPrefix("/⌂/").Subrouter()
api.HandleFunc("/create", app.handler(createHouse)).Methods("POST").Name("create")
api.HandleFunc("/{house:[A-Za-z0-9.-]{8}}", app.handler(renovateHouse)).Methods("POST").Name("update")
api.HandleFunc("/public", app.handler(getPublicHousesData)).Methods("GET").Name("browse-api")

admin := app.router.PathPrefix("/admin/").Subrouter()
admin.HandleFunc("/unpublish", app.handler(banHouse)).Methods("POST").Name("unpublish")


+ 13
- 0
construction.go View File

@@ -198,6 +198,19 @@ func getHouseHTML(app *app, houseID string) (string, error) {
return html, nil
}

func getPublicHousesData(app *app, w http.ResponseWriter, r *http.Request) error {
houses, err := getPublicHouses(app)
if err != nil {
return err
}

for i := range *houses {
(*houses)[i].process(app)
}

return impart.WriteSuccess(w, houses, http.StatusOK)
}

// regular expressions for extracting data
var (
htmlReg = regexp.MustCompile("<html( ?.*)>")


+ 15
- 3
models.go View File

@@ -1,10 +1,15 @@
package htmlhouse

import (
"fmt"
)

type (
PublicHouse struct {
ID string
Title string
ThumbURL string
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
ThumbURL string `json:"thumb_url"`
}

HouseStats struct {
@@ -17,3 +22,10 @@ type (
Label string
}
)

func (h *PublicHouse) process(app *app) {
h.URL = fmt.Sprintf("%s/%s.html", app.cfg.HostName, h.ID)
if h.ThumbURL != "" {
h.ThumbURL = "https://peeper.html.house/" + h.ThumbURL
}
}

Loading…
Cancel
Save