-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begining support for flexible cards in Urchin
- Loading branch information
1 parent
d915e1c
commit da40c88
Showing
14 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package admin_app | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/matheusgomes28/urchin/common" | ||
"github.com/matheusgomes28/urchin/database" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func postCardHandler(database database.Database) func(*gin.Context) { | ||
return func(c *gin.Context) { | ||
var add_card_request AddCardRequest | ||
if c.Request.Body == nil { | ||
c.JSON(http.StatusBadRequest, common.MsgErrorRes("no request body provided")) | ||
return | ||
} | ||
decoder := json.NewDecoder(c.Request.Body) | ||
err := decoder.Decode(&add_card_request) | ||
|
||
if err != nil { | ||
log.Warn().Msgf("invalid post request: %v", err) | ||
c.JSON(http.StatusBadRequest, common.ErrorRes("invalid request body", err)) | ||
return | ||
} | ||
|
||
// TODO : Sanity checks that everything inside the | ||
// TODO : request makes sense. I.e. content is json, | ||
// TODO : i.e json content matches the schema, etc. | ||
// err = checkRequiredData(add_card_request) | ||
// if err != nil { | ||
// log.Error().Msgf("failed to add post required data is missing: %v", err) | ||
// c.JSON(http.StatusBadRequest, common.ErrorRes("missing required data", err)) | ||
// return | ||
// } | ||
|
||
id, err := database.AddCard( | ||
add_card_request.Title, | ||
add_card_request.Image, | ||
add_card_request.Schema, | ||
add_card_request.Content, | ||
) | ||
if err != nil { | ||
log.Error().Msgf("failed to add card: %v", err) | ||
c.JSON(http.StatusBadRequest, common.ErrorRes("could not add post", err)) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, CardIdResponse{ | ||
id, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/matheusgomes28/urchin/common" | ||
"github.com/matheusgomes28/urchin/database" | ||
"github.com/matheusgomes28/urchin/views" | ||
) | ||
|
||
func productHandler(c *gin.Context, app_settings common.AppSettings, db database.Database) ([]byte, error) { | ||
return renderHtml(c, views.MakeProductPage(app_settings.AppNavbar.Links)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package common | ||
|
||
type Card struct { | ||
Id string `json:"id"` | ||
Title string `json:"title"` | ||
Image string `json:"image"` | ||
Schema string `json:"schema"` | ||
Content string `json:"content"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TABLE cards ( | ||
uuid VARCHAR(36) DEFAULT(UUID()) PRIMARY KEY, | ||
image_location TEXT NOT NULL, | ||
json_data TEXT NOT NULL, | ||
json_schema TEXT NOT NULL | ||
); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP TABLE cards; | ||
-- +goose StatementEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package views | ||
|
||
import "github.com/matheusgomes28/urchin/common" | ||
|
||
templ makeCard(title string, slogan string) { | ||
<a href="#" class="relative block rounded-tr-3xl border border-gray-100"> | ||
<span | ||
class="absolute -right-px -top-px rounded-bl-3xl rounded-tr-3xl bg-gray-700 px-6 py-4 font-medium uppercase tracking-widest text-white" | ||
> | ||
{slogan} | ||
</span> | ||
|
||
<!-- TODO : Take the image as param --> | ||
<img | ||
src="https://images.unsplash.com/photo-1485955900006-10f4d324d411?q=80&w=2672&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | ||
alt="" | ||
class="h-80 w-full rounded-tr-3xl object-cover" | ||
/> | ||
|
||
<div class="p-4 text-center"> | ||
<strong class="text-xl font-medium text-gray-900 dark:text-gray-100"> {title} </strong> | ||
|
||
<p class="mt-2 text-pretty text-gray-700 dark:text-gray-100"> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet officia rem vel voluptatum in | ||
eum vitae aliquid at sed dignissimos. | ||
</p> | ||
|
||
<span | ||
class="mt-4 block rounded-md border border-indigo-900 bg-indigo-900 px-5 py-3 text-sm font-medium uppercase tracking-widest text-white transition-colors dark:text-gray-100 hover:bg-white hover:text-indigo-900" | ||
> | ||
Learn More | ||
</span> | ||
</div> | ||
</a> | ||
} | ||
|
||
templ makeCardGrid() { | ||
<div class="grid grid-cols-3 gap-4 content-center justify-center items-center"> | ||
<div class="max-w-sm"> | ||
@makeCard("Card One", "Save 10%") | ||
</div> | ||
<div class="max-w-sm"> | ||
@makeCard("Card One", "Save 10%") | ||
</div> | ||
<div class="max-w-sm"> | ||
@makeCard("Card One", "Save 10%") | ||
</div> | ||
<div class="max-w-sm"> | ||
@makeCard("Card One", "Save 10%") | ||
</div> | ||
<div class="max-w-sm"> | ||
@makeCard("Card One", "Save 10%") | ||
</div> | ||
</div> | ||
} | ||
|
||
templ MakeProductPage(links []common.Link) { | ||
@MakeLayout("Product Page", links, makeCardGrid()) | ||
|
||
// TODO : for each product coming from the database | ||
// TODO : we're going to create a card for it | ||
} |