Fixed no shortcode

This commit is contained in:
cdricms
2025-02-11 10:12:37 +01:00
parent 60dd966f3e
commit 2c2be9fdba
6 changed files with 644 additions and 104 deletions

View File

@@ -1 +0,0 @@
.env

View File

@@ -6,10 +6,14 @@ COPY . .
RUN go mod download
RUN go build -o /app .
RUN go build -o /app/main .
RUN go build -o /app/migrate ./cmd/migrate
FROM scratch AS final
COPY --from=build /app /app
WORKDIR /app
CMD ["/app"]
COPY .env /app/
COPY --from=build /app/main /app/migrate /app/cmd/migrate/migrations/ /app/
CMD ["/app/main"]

View File

@@ -12,12 +12,21 @@ import (
func HandleShortcode(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("shortcode")
var shortcode models.Shortcode
err := core.DB.NewSelect().
count, err := core.DB.NewSelect().
Model(&shortcode).
Where("code = ?", code).
Relation("Media").
Limit(1).
Scan(context.Background())
ScanAndCount(context.Background())
if count == 0 {
core.JSONSuccess{
Status: core.Success,
Message: "Shortcode has not been found",
}.Respond(w, http.StatusNotFound)
return
}
if err != nil {
core.JSONError{
Status: core.Error,