Skip to content

Commit

Permalink
Merge pull request #39 from Lakshay229/main
Browse files Browse the repository at this point in the history
No Expiry Function added
  • Loading branch information
JeevantVerma authored Jun 26, 2024
2 parents 5ccb64e + 4d23107 commit 3c9d2c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
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
28 changes: 22 additions & 6 deletions frontend/src/Maincontent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FormControl,
InputLabel,
Select,
Switch,
} from "@mui/material";
import dayjs from "dayjs";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
Expand All @@ -35,13 +36,14 @@ const MainContentSection = () => {
const [longUrl, setLongUrl] = useState("");
const [alias, setAlias] = useState("");
const [shortenedUrl, setShortenedUrl] = useState("");
const [expiry, setExpiry] = useState(dayjs().add(1, "week"));
const [expiry, setExpiry] = useState(dayjs().add(10, "second"));
const [expiryOption, setExpiryOption] = useState("1 week");
const [noExpiry, setNoExpiry] = useState(false);
const [snackbarOpen, setSnackbarOpen] = useState(false);
const [error, setError] = useState("");
const [toggle,settoggle] = useState(1);
const [qrimage, setqrimage] = useState("");

const handleShortenUrl = async () => {
const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;
if (!urlRegex.test(longUrl)) {
Expand Down Expand Up @@ -187,7 +189,7 @@ const MainContentSection = () => {
<DatePicker
format="DD/MM/YYYY"
label="Set Expiry Date"
value={expiry}
value={noExpiry ? null : expiry}
fullWidth
minDate={dayjs().startOf('day')}
disabled={(noExpiry)}
Expand Down Expand Up @@ -221,13 +223,27 @@ const MainContentSection = () => {
</FormControl>
</Grid>
<Grid item xs={12} sm={4}>
<Button
<Switch
variant="contained"
color="primary"
onClick={() => setNoExpiry(!noExpiry)}
onChange={() => {
settoggle(toggle => toggle+1)
if (toggle%2 === 0) {
setNoExpiry(false);
}else{setNoExpiry(true)}
//setNoExpiry(true);
//setExpiry(dayjs().add(100, "year"));
}
}
>
{noExpiry ? "Clear No Expiry" : "No Expiry"}
</Button>
</Switch>
<Typography
variant="p1"
align="center"
>
No Expiry
</Typography>
</Grid>
<Grid item xs={12}>
<Button variant="contained" color="primary" onClick={handleShortenUrl}>
Expand Down
7 changes: 7 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,14 @@
resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz"
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==



"@remix-run/[email protected]":
version "1.16.1"
resolved "https://registry.npmjs.org/@remix-run/router/-/router-1.16.1.tgz"
integrity sha512-es2g3dq6Nb07iFxGk5GuHN20RwBZOsuDQN7izWIisUcv9r+d2C5jQxqmgkdebXgReWfiyUabcki6Fg77mSNrig==


"@rollup/[email protected]":
version "4.13.0"
resolved "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.13.0.tgz"
Expand Down Expand Up @@ -2217,7 +2220,9 @@ queue-microtask@^1.2.2:
integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==



"react-dom@^17.0.0 || ^18.0.0", react-dom@^18.2.0, react-dom@>=16.6.0, react-dom@>=16.8, react-dom@>=16.8.0:

version "18.2.0"
resolved "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz"
integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==
Expand Down Expand Up @@ -2271,7 +2276,9 @@ react-transition-group@^4.4.5:
prop-types "^15.6.2"



"react@^17.0.0 || ^18.0.0", react@^18.2.0, react@>=16.6.0, react@>=16.8, react@>=16.8.0:

version "18.2.0"
resolved "https://registry.npmjs.org/react/-/react-18.2.0.tgz"
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
Expand Down

0 comments on commit 3c9d2c1

Please sign in to comment.