-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.go
95 lines (80 loc) · 2.1 KB
/
home.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"mersal/auth"
"mersal/helps"
"net/http"
"os"
"github.com/blockloop/scan"
"github.com/labstack/echo/v4"
)
type User struct {
Id int `db:"Id"`
Username string `db:"Username"`
Password string `db:"Password"`
Email string `db:"Email"`
Gender string `db:"Gender"`
Age int `db:"Age"`
Height int `db:"Height"`
Weight int `db:"Weight"`
Languages string `db:"Languages"`
Profess string `db:"Profess"`
Contry string `db:"Country"`
Descript string `db:"Descript"`
Photos string `db:"Photos"`
}
// getCatigories get all photo name of catigories.
func getRecentUsers() (users []User) {
rows, err := db.Query("SELECT Id, Username, Email, Photos from mersal.users;")
defer rows.Close()
err = scan.Rows(&users, rows)
if err != nil {
helps.PrintError("error from schan.Rows: ", err)
os.Exit(1)
}
return users
}
// HomePage get home page
func HomePage(c echo.Context) error {
username, userid, err := auth.GetSession(c)
helps.PrintError("get session", err)
println("id & username ", userid, username)
data := make(map[string]interface{}, 3)
data["username"] = username
data["userid"] = userid
// TODO add home activites here
//users := getRecentUsers()
// fmt.Print("profile info", ProfileInfo(userid), "\n\n")
//for _ = range users {
//photos := strings.Split(users[i].Photos, "; ")
//users[i].Photos = SetAvatar(users[i].Gender, photos[0])
//fmt.Println(users[i].Photos)
// }
//data["users"] = users
//data["user"] = ProfileInfo(userid)
return c.Render(http.StatusOK, "home.html", data)
}
// get Profile with all info
func ProfileInfo(userid int) (profile User) {
rows, err := db.Query("select * from users where userid = ?", userid)
if err != nil {
fmt.Println("\nat query func owner id db select ", err)
}
defer rows.Close() // ??
err = scan.Rows(&profile, rows)
println(err)
return profile
}
// SetAvatar set real or blank, man or woman avatar
func SetAvatar(gen, photo string) string {
if photo != "" {
return photo
}
if gen == "m" {
return "bman.jpg"
}
if gen == "f" {
return "bwoman.jpg"
}
return ""
}