admin core func done
This commit is contained in:
@@ -19,6 +19,8 @@ import (
|
||||
func PostsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
userID := r.Context().Value("user_id").(int)
|
||||
role := r.Context().Value("user_role").(int)
|
||||
username,_ := models.GetCurrentUserName(r)
|
||||
|
||||
|
||||
if r.Method == http.MethodPost {
|
||||
// Parse multipart form
|
||||
@@ -103,14 +105,18 @@ func PostsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
CurrentUserID := models.GetCurrentUserID(w, r)
|
||||
|
||||
|
||||
// GET request: fetch posts
|
||||
rows, err := models.DB.Query(`
|
||||
SELECT p.post_id, p.author_id, u.first_name || ' ' || u.last_name AS author_name,
|
||||
p.content, COALESCE(p.image_url, '') as image_url, p.created_at
|
||||
FROM post p
|
||||
JOIN users u ON p.author_id = u.user_id
|
||||
WHERE p.author_id = $1
|
||||
ORDER BY p.created_at DESC
|
||||
`)
|
||||
`, CurrentUserID)
|
||||
if err != nil {
|
||||
fmt.Printf("Database query error: %v\n", err)
|
||||
http.Error(w, "Failed to fetch posts", http.StatusInternalServerError)
|
||||
@@ -147,6 +153,7 @@ func PostsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"IsAuthenticated": true,
|
||||
"ShowAdminNav": showAdminNav,
|
||||
"ShowVolunteerNav": showVolunteerNav,
|
||||
"UserName": username,
|
||||
"Posts": posts,
|
||||
"ActiveSection": "posts",
|
||||
})
|
||||
@@ -155,6 +162,6 @@ func PostsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Helper function (add this to your main.go if not already there)
|
||||
func getNavFlags(role int) (bool, bool) {
|
||||
showAdminNav := role == 1 // Admin role
|
||||
showVolunteerNav := role == 3 // Volunteer role
|
||||
showVolunteerNav := role == 3 || role == 2
|
||||
return showAdminNav, showVolunteerNav
|
||||
}
|
||||
Reference in New Issue
Block a user