Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed search #242

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "rfac: changed logic for checking valid paths"
This reverts commit 8934f5d.
NanoNish committed Dec 24, 2022

Verified

This commit was signed with the committer’s verified signature.
jenniferarnesen Jen Jones Arnesen
commit 0970bff0fcff307a8266c226c8f11d6a0badc3a5
11 changes: 0 additions & 11 deletions conf/constants.go
Original file line number Diff line number Diff line change
@@ -58,14 +58,3 @@ const (
StatusMemoryLimitExceeded = "MLE"
StatusPartial = "PTL"
)

var ValidPaths = []string{"username", "fullname", "handle.codechef", "handle.codeforces", "handle.hackerearth", "handle.hackerrank", "handle.spoj"}

func IsPathValid(s string) bool {
for _, path := range ValidPaths {
if path == s {
return true
}
}
return false
}
12 changes: 9 additions & 3 deletions controllers/search.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"strconv"

"github.com/getsentry/sentry-go"
. "github.com/mdg-iitr/Codephile/conf"
. "github.com/mdg-iitr/Codephile/errors"
"github.com/mdg-iitr/Codephile/models"
)
@@ -37,9 +36,16 @@ func (u *UserController) Search() {
}
path := u.GetString("path")
//Checking for possible fields, default is "username"
if !IsPathValid(path) {
var possible_path []string
var good_path bool = false
possible_path = []string{"username", "fullname", "handle.codechef", "handle.codeforces", "handle.hackerearth", "handle.hackerrank", "handle.spoj"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-check the list of platforms. Leetcode is missing and hackerearth is extra.

for _, itr := range possible_path {
if itr == path {
good_path = true
}
}
if !good_path {
path = "username"
return
}
results, err := models.SearchUser(query, c, path)
if err != nil {
7 changes: 3 additions & 4 deletions routers/router.go
Original file line number Diff line number Diff line change
@@ -9,14 +9,13 @@
package routers

import (
"net/http"
"os"
"path"

"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/mdg-iitr/Codephile/controllers"
"github.com/mdg-iitr/Codephile/middleware"
"net/http"
"os"
"path"
)

func init() {