-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: closes #13 and implementspreview endpoint and logo via base64 i…
…n json body arg 'logo' (#15)
- Loading branch information
Showing
16 changed files
with
338 additions
and
121 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 api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/doutorfinancas/pun-sho/api/request" | ||
"github.com/doutorfinancas/pun-sho/api/response" | ||
"github.com/doutorfinancas/pun-sho/service" | ||
"github.com/doutorfinancas/pun-sho/str" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type previewHandler struct { | ||
qrSvc *service.QRCodeService | ||
} | ||
|
||
func NewPreviewHandler(qrSvc *service.QRCodeService) HTTPHandler { | ||
return &previewHandler{ | ||
qrSvc: qrSvc, | ||
} | ||
} | ||
|
||
func (h *previewHandler) Routes(rg *gin.RouterGroup) { | ||
rg.POST("", h.CreateLink) | ||
rg.POST("/", h.CreateLink) | ||
} | ||
|
||
func (h *previewHandler) Group() *string { | ||
return str.ToStringNil("preview") | ||
} | ||
|
||
func (h *previewHandler) CreateLink(c *gin.Context) { | ||
m := &request.GeneratePreview{} | ||
err := c.BindJSON(m) | ||
|
||
if err != nil { | ||
c.JSON( | ||
http.StatusBadRequest, | ||
response.NewFailure("invalid payload"), | ||
) | ||
return | ||
} | ||
s, err := h.qrSvc.Generate(m.QRCode, m.Link) | ||
if err != nil { | ||
c.JSON( | ||
http.StatusBadRequest, | ||
response.NewFailure("kaput, no save"), | ||
) | ||
return | ||
} | ||
|
||
a := response.NewGeneratePreviewResponse(s, nil) | ||
|
||
c.JSON(http.StatusCreated, a) | ||
} |
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,6 @@ | ||
package request | ||
|
||
type GeneratePreview struct { | ||
Link string `json:"link"` | ||
QRCode *QRCode `json:"qr_code"` | ||
} |
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,11 @@ | ||
package request | ||
|
||
type QRCode struct { | ||
Create bool `json:"create"` | ||
Width int `json:"width"` | ||
BorderWidth int `json:"border_width"` | ||
FgColor string `json:"foreground_color"` | ||
BgColor string `json:"background_color"` | ||
Shape string `json:"shape"` | ||
LogoImage string `json:"logo"` | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
package response | ||
|
||
type GeneratePreviewResponse struct { | ||
BaseResponse | ||
QrCode string `json:"qr_code"` | ||
Message *[]string `json:"message,omitempty"` | ||
} | ||
|
||
// NewGeneratePreviewResponse creates a base preview response | ||
func NewGeneratePreviewResponse(qrCode string, message *[]string) *GeneratePreviewResponse { | ||
return &GeneratePreviewResponse{ | ||
BaseResponse{Status: Ok}, | ||
qrCode, | ||
message, | ||
} | ||
} |
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,21 @@ | ||
package response | ||
|
||
const Ok = "ok" | ||
const Error = "error" | ||
|
||
type BaseResponse struct { | ||
Status string `json:"status"` | ||
} | ||
|
||
type FailureResponse struct { | ||
BaseResponse | ||
Message []string `json:"message,omitempty"` | ||
} | ||
|
||
func NewFailure(message string) *FailureResponse { | ||
return &FailureResponse{BaseResponse{Status: Error}, []string{message}} | ||
} | ||
|
||
func NewOk() *BaseResponse { | ||
return &BaseResponse{Status: Ok} | ||
} |
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
Oops, something went wrong.