Miki Tebeka avatar Miki Tebeka committed 5f1b336

userURLs

Comments (0)

Files changed (1)

shortie/shortie.go

 	return datastore.NewKey(ctx, urlKind, short, 0, nil)
 }
 
-func getUrl(ctx appengine.Context, short string) (*URL, os.Error) {
+func getURL(ctx appengine.Context, short string) (*URL, os.Error) {
 	key := urlKey(ctx, short)
 	url := new(URL)
 	err := datastore.Get(ctx, key, url)
 
 func incHits(ctx appengine.Context, short string) os.Error {
 	return datastore.RunInTransaction(ctx, func(ctx appengine.Context) os.Error {
-		url, err := getUrl(ctx, short)
+		url, err := getURL(ctx, short)
 		if err != nil {
 			return err
 		}
 	}, nil)
 }
 
+func userURLs(ctx appengine.Context, user string) ([]*URL, os.Error) {
+	 query := datastore.NewQuery(urlKind).
+		Filter("User =", user).
+		Order("-Created").
+		Limit(1000)
+	buff := []*URL{}
+	it := query.Run(ctx)
+
+	for {
+		var url URL
+		_, err := it.Next(&url)
+		if err == datastore.Done {
+			break
+		}
+		if err != nil {
+			return nil, err
+		}
+		buff = append(buff, &url)
+	}
+
+	return buff, nil
+}
+
 var homeTemplate *template.Template
 
 func init() {
 	Count      int64
 	Error      string
 	ShortURL   string
+	URLs	   []*URL
 }
 
 func rootHandler(w http.ResponseWriter, r *http.Request) {
 
 
 	if r.Method == "POST" {
-		longUrl := strings.TrimSpace(r.FormValue("url"))
-		if len(longUrl) == 0 {
+		longURL := strings.TrimSpace(r.FormValue("url"))
+		if len(longURL) == 0 {
 			params.Error = "Empty URL"
 			return
 		}
 		}
 
 		url := &URL{
-			Long: longUrl,
+			Long: longURL,
 			User: params.User,
 			Created: datastore.SecondsToTime(time.Seconds()),
 			Hits: 0,
 	ctx := appengine.NewContext(r)
 	path := r.URL.Path[1:]
 
-	url, err := getUrl(ctx, path)
+	url, err := getURL(ctx, path)
 	if err != nil {
 		http.NotFound(w, r)
 		return
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.