Skip to content

Commit

Permalink
likes amd submissions of logged in users and not the user in query pa…
Browse files Browse the repository at this point in the history
…rams
  • Loading branch information
ayoubfaouzi committed May 1, 2021
1 parent 8143709 commit 0b3cd83
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Please refer to the 'Service' section about the detail of those functions.

## References

- https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1
- [Standard Package Layout](https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1)
- [How Do You Structure Your Go Apps? by Kat Zień](https://github.com/katzien/go-structure-examples)
- https://www.calhoun.io/moving-towards-domain-driven-design-in-go/
- https://www.damianopetrungaro.com/posts/ddd-using-golang-strategic-design/
- [Domain Driven Design in Golang - Strategic Design](https://www.damianopetrungaro.com/posts/ddd-using-golang-strategic-design/)
- [Idiometic Go Web Application Structure](http://josebalius.com/posts/go-app-structure/)
- [A clean architecture for Web Application in Go lang](https://medium.com/wesionary-team/a-clean-architecture-for-web-application-in-go-lang-4b802dd130bb)

Expand Down
43 changes: 30 additions & 13 deletions app/handler/user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,8 @@ func Actions(c echo.Context) error {
})
}

// GetActivitiy represents the feed displayed in the landing page for logged in users.
// GetActivitiy represents the feed displayed in the landing page for
// logged in users.
func GetActivitiy(c echo.Context) error {

// get path param
Expand All @@ -940,10 +941,15 @@ func GetActivitiy(c echo.Context) error {
params := make(map[string]interface{}, 1)
params["user"] = username
query := `
SELECT t1.*, f.tags,
ARRAY_COUNT(ARRAY_FLATTEN(array i.infected
for i in OBJECT_VALUES(f.multiav.last_scan)
when i.infected=true end, 1)) as av_count
SELECT t1.*, f.tags, f.submissions[0].filename,
f.ml.pe.predicted_class as class,
CONCAT(
TOSTRING(
ARRAY_COUNT(array_flatten(array i.infected
for i in OBJECT_VALUES(f.multiav.last_scan)
when i.infected=true end, 1))
), "/", TOSTRING(OBJECT_LENGTH(f.multiav.last_scan))
) as multiav
FROM (
SELECT u.username, activity.*
FROM users u
Expand Down Expand Up @@ -998,7 +1004,7 @@ func GetActivities(c echo.Context) error {
params := make(map[string]interface{}, 1)
params["user"] = viper.GetString("app.admin_user")
query := `
SELECT t1.*, f.tags,
SELECT t1.*, f.tags,
ARRAY_COUNT(ARRAY_FLATTEN(array i.infected
for i in OBJECT_VALUES(f.multiav.last_scan)
when i.infected=true end, 1)) as av_count
Expand Down Expand Up @@ -1048,15 +1054,20 @@ func GetLikes(c echo.Context) error {
username := c.Param("username")

// Get user infos.
usr, err := GetByUsername(username)
_, err := GetByUsername(username)
if err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{
"verbose_msg": "Username does not exist"})
}

// extract user from token
u := c.Get("user").(*jwt.Token)
claims := u.Claims.(jwt.MapClaims)
loggedUser := claims["name"].(string)

// Retreieve all likes from user.
params := make(map[string]interface{}, 1)
params["user"] = strings.ToLower(usr.Username)
params["user"] = strings.ToLower(username)
query := `
SELECT sha256, submissions[0].filename,
ml.pe.predicted_class as class, tags,
Expand Down Expand Up @@ -1108,15 +1119,20 @@ func GetSubmissions(c echo.Context) error {
username := c.Param("username")

// Get user infos.
usr, err := GetByUsername(username)
_, err := GetByUsername(username)
if err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{
"verbose_msg": "Username does not exist"})
}

// extract user from token
u := c.Get("user").(*jwt.Token)
claims := u.Claims.(jwt.MapClaims)
username = claims["name"].(string)

// Get all activities from all users.
params := make(map[string]interface{}, 1)
params["user"] = strings.ToLower(usr.Username)
params["user"] = strings.ToLower(username)
query := `
SELECT s.*, f.submissions[0].filename,
f.ml.pe.predicted_class as class, f.tags,
Expand Down Expand Up @@ -1178,11 +1194,12 @@ func GetFollowing(c echo.Context) error {
// Get all activities from all users.
params := make(map[string]interface{}, 1)
params["user"] = strings.ToLower(usr.Username)
query := `
query :=
`
SELECT u.member_since, u.username
FROM users u
USE KEYS` + " [(SELECT raw nu.`following` " +
`FROM users nu USE KEYS $user )[0]]
USE KEYS` + " [(SELECT raw nu.`following` " + `
FROM users nu USE KEYS $user )[0]]
`

// Execute Query
Expand Down

0 comments on commit 0b3cd83

Please sign in to comment.