Skip to content

Commit

Permalink
Merge branch 'front-test' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
PreetinderSinghBadesha authored Jul 4, 2024
2 parents e7fa57e + 0ecab01 commit 61f538d
Show file tree
Hide file tree
Showing 16 changed files with 1,165 additions and 125 deletions.
1 change: 0 additions & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"os"

auth "github.com/MicrosoftStudentChapter/Link-Generator/pkg/auth"
router "github.com/MicrosoftStudentChapter/Link-Generator/pkg/router"
"github.com/gorilla/mux"
"github.com/redis/go-redis/v9"
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/mapping/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Link struct {
Link string `redis:"Link" json:"link"`
ShortURL string `redis:"ShortURL" json:"shortURL"`
Expire string `redis:"Expire" json:"expire"`
}

func AddURL(linkURL string, shortURL string, exp string, ctx context.Context, conn *redis.Client) (Link, error) {
Expand All @@ -21,6 +22,7 @@ func AddURL(linkURL string, shortURL string, exp string, ctx context.Context, co
return Link{
Link: existingMap["Link"],
ShortURL: existingMap["ShortURL"],
Expire: existingMap["Expire"],
}, nil
} else {
return Link{}, fmt.Errorf("shortURL already exists")
Expand All @@ -44,6 +46,7 @@ func AddURL(linkURL string, shortURL string, exp string, ctx context.Context, co
mapping := Link{
Link: linkURL,
ShortURL: shortURL,
Expire: exp,
}
err = conn.HSet(ctx, shortURL, mapping).Err()
if err != nil {
Expand Down Expand Up @@ -78,6 +81,7 @@ func GetAllLinks(ctx context.Context, conn *redis.Client) []Link {
links = append(links, Link{
Link: link["Link"],
ShortURL: link["ShortURL"],
Expire: link["Expire"],
})
}
return links
Expand Down
7 changes: 6 additions & 1 deletion backend/pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ func GetAllLinks(w http.ResponseWriter, r *http.Request) {
var linksData []string
for _, link := range links {
// w.Write([]byte(fmt.Sprintf("%s - %s\n", link.ShortURL, link.Link)))
linksData = append(linksData, fmt.Sprintf("%s - %s\n", link.ShortURL, link.Link))
if link.Expire == "" {
linksData = append(linksData, fmt.Sprintf("%s - %s - %s\n", link.ShortURL, link.Link, "No Expiry"))
} else {

linksData = append(linksData, fmt.Sprintf("%s - %s - %s\n", link.ShortURL, link.Link, link.Expire))
}
}
page.Execute(w, linksData)
}
Expand Down
Loading

0 comments on commit 61f538d

Please sign in to comment.