Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion app/src/components/ComplaintCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { POST_PLACES } from '../constants/models';

// ── Types ────────────────────────────────────────────────────────────────────────

export type Role = 'faculty' | 'warden' | 'centre_head';
export type Role = 'faculty' | 'warden' | 'centrehead';

export interface CommentAuthor {
id: number;
Expand Down
4 changes: 2 additions & 2 deletions app/src/pages/admin/AEPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface AEPostsResponse {
success: string;
faculty_posts: BasePost[] | BasePost | null;
warden_posts: BasePost[] | BasePost | null;
centre_head_posts: BasePost[] | BasePost | null;
centrehead_posts: BasePost[] | BasePost | null;
}

function normalise(val: BasePost[] | BasePost | null | undefined): BasePost[] {
Expand Down Expand Up @@ -184,7 +184,7 @@ export function AEPostView() {
);
}

const { faculty_posts: fp, warden_posts: wp, centre_head_posts: cp } = data!;
const { faculty_posts: fp, warden_posts: wp, centrehead_posts: cp } = data!;

return (
<MainLayout>
Expand Down
6 changes: 3 additions & 3 deletions app/src/pages/admin/AdminPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ interface WardenPost {

interface CentreHeadPost {
id: number;
centre_head_id: number;
centrehead_id: number;
Author: CentreHeadAuthor;
type_of_post: string;
title: string;
Expand Down Expand Up @@ -136,14 +136,14 @@ const STATUS_STYLES: Record<string, string> = {
const ROLE_TO_STATUS_API: Record<string, string> = {
faculty: 'faculty_posts',
warden: 'warden_posts',
centrehead: 'centre_head_posts',
centrehead: 'centrehead_posts',
};

// Maps URL role param → API segment for the comment endpoint
const ROLE_TO_COMMENT_API: Record<string, string> = {
faculty: 'faculty_posts',
warden: 'wardens_posts',
centrehead: 'centreheads_posts',
centrehead: 'centrehead_posts',
};

// Back-link per admin type
Expand Down
4 changes: 2 additions & 2 deletions app/src/pages/admin/JEPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface JEPostsResponse {
success: string;
faculty_posts: BasePost[] | BasePost | null;
warden_posts: BasePost[] | BasePost | null;
centre_head_posts: BasePost[] | BasePost | null;
centrehead_posts: BasePost[] | BasePost | null;
}

function normalise(val: BasePost[] | BasePost | null | undefined): BasePost[] {
Expand Down Expand Up @@ -184,7 +184,7 @@ export function JEPostView() {
);
}

const { faculty_posts: fp, warden_posts: wp, centre_head_posts: cp } = data!;
const { faculty_posts: fp, warden_posts: wp, centrehead_posts: cp } = data!;

return (
<MainLayout>
Expand Down
4 changes: 2 additions & 2 deletions app/src/pages/admin/XENPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface XENPostsResponse {
// API may return an array, a single object, or null depending on the backend
faculty_posts: BasePost[] | BasePost | null;
warden_posts: BasePost[] | BasePost | null;
centre_head_posts: BasePost[] | BasePost | null;
centrehead_posts: BasePost[] | BasePost | null;
}

// Handles every shape the Go backend might send:
Expand Down Expand Up @@ -192,7 +192,7 @@ export function XENPostView() {
);
}

const { faculty_posts: fp, warden_posts: wp, centre_head_posts: cp } = data!;
const { faculty_posts: fp, warden_posts: wp, centrehead_posts: cp } = data!;

return (
<MainLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/auth/AccountResetPass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MainLayout } from '../../components/layout/MainLayout';
const roleToApi: Record<string, string> = {
faculty: '/api/auth/faculty/reset-password',
warden: '/api/auth/warden/reset-password',
centrehead: '/api/auth/centre_head/reset-password',
centrehead: '/api/auth/centrehead/reset-password',
};

const roleToLoginPath: Record<string, string> = {
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/auth/CentreHeadForgotPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function CentreHeadForgotPassword() {
setMessage('');

try {
const response = await fetch('/api/auth/centre_head/forget-password', {
const response = await fetch('/api/auth/centrehead/forget-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/auth/CentreHeadLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function CentreHeadLogin() {
setMessage('');

try {
const response = await fetch('/api/auth/centre_head/login', {
const response = await fetch('/api/auth/centrehead/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/auth/CentreHeadSignup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function CentreHeadSignup() {
setMessage('');

try {
const response = await fetch('/api/auth/centre_head/signup', {
const response = await fetch('/api/auth/centrehead/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/post/CentreHeadPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function CentreHeadPost() {
setMessage('');

try {
const response = await fetch('/api/post/centre_head', {
const response = await fetch('/api/post/centrehead', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
Expand Down
10 changes: 5 additions & 5 deletions app/src/pages/profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function Profile() {
let endpoint = '';
if ('department' in profile) endpoint = '/api/post/faculty';
else if ('hostel' in profile) endpoint = '/api/post/warden';
else if ('building' in profile) endpoint = '/api/post/centre_head';
else if ('building' in profile) endpoint = '/api/post/centrehead';
else return;

setPostsLoading(true);
Expand Down Expand Up @@ -99,14 +99,14 @@ export function Profile() {
let roleLabel = 'User';
let roleBadgeCls = 'bg-gray-100 text-gray-800 border-gray-200';
let registerRoute = '/';
let role: Role = 'centre_head';
let role: Role = 'centrehead';
if (isFaculty) { roleLabel = 'Faculty Member'; roleBadgeCls = 'bg-emerald-50 text-emerald-700 border-emerald-200'; registerRoute = '/faculty/post'; role = 'faculty'; }
else if (isWarden) { roleLabel = 'Hostel Warden'; roleBadgeCls = 'bg-indigo-50 text-indigo-700 border-indigo-200'; registerRoute = '/warden/post'; role = 'warden'; }
else if (isCentreHead) { roleLabel = 'Centre Head'; roleBadgeCls = 'bg-amber-50 text-amber-700 border-amber-200'; registerRoute = '/centre-head/post'; role = 'centre_head'; }
else if (isCentreHead) { roleLabel = 'Centre Head'; roleBadgeCls = 'bg-amber-50 text-amber-700 border-amber-200'; registerRoute = '/centre-head/post'; role = 'centrehead'; }

// ── API base paths ──
const editBase = isFaculty ? '/api/post/faculty/edit' : isWarden ? '/api/post/warden/edit' : '/api/post/centre_head/edit';
const deleteBase = isFaculty ? '/api/post/faculty/delete' : isWarden ? '/api/post/warden/delete' : '/api/post/centre_head/delete';
const editBase = isFaculty ? '/api/post/faculty/edit' : isWarden ? '/api/post/warden/edit' : '/api/post/centrehead/edit';
const deleteBase = isFaculty ? '/api/post/faculty/delete' : isWarden ? '/api/post/warden/delete' : '/api/post/centrehead/delete';

// ── Handlers ──
const handleLogout = async () => {
Expand Down
4 changes: 2 additions & 2 deletions config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func ConnectDB() {
&models.Admin{},
&models.Faculty{},
&models.Warden{},
&models.CentreHead{},
&models.Centrehead{},
&models.FacultyPost{},
&models.WardenPost{},
&models.CentreHeadPost{},
&models.CentreheadPost{},
&models.Comment{},
)

Expand Down
2 changes: 1 addition & 1 deletion handlers/admin_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (h *AdminHandler) AdminPostComment (c *gin.Context) {
tableMap := map[string]interface{} {
"faculty_posts": &models.FacultyPost{},
"warden_posts": &models.WardenPost{},
"centre_head_posts": &models.CentreHeadPost{},
"centrehead_posts": &models.CentreheadPost{},
}

postType := c.Param("type")
Expand Down
14 changes: 7 additions & 7 deletions handlers/admin_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (h *AdminHandler) GetXENPosts (c *gin.Context) {

var facultyPosts []models.FacultyPost
var wardenPosts []models.WardenPost
var centreheadPosts []models.CentreHeadPost
var centreheadPosts []models.CentreheadPost

// fetch faculty posts
// this api only returns the fields that are required at the
Expand Down Expand Up @@ -79,7 +79,7 @@ func (h *AdminHandler) GetXENPosts (c *gin.Context) {
"success": "posts fetched successfully",
"faculty_posts": facultyPosts,
"warden_posts": wardenPosts,
"centre_head_posts": centreheadPosts,
"centrehead_posts": centreheadPosts,
})
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func (h* AdminHandler) GetAEPosts (c *gin.Context) {

var facultyPosts []models.FacultyPost
var wardenPosts []models.WardenPost
var centreheadPosts []models.CentreHeadPost
var centreheadPosts []models.CentreheadPost

// fetch faculty posts
result = h.DB.Select("id, title, type_of_post, status, assigned_je_id").
Expand Down Expand Up @@ -154,7 +154,7 @@ func (h* AdminHandler) GetAEPosts (c *gin.Context) {
"success": "posts fetched successfully",
"faculty_posts": facultyPosts,
"warden_posts": wardenPosts,
"centre_head_posts": centreheadPosts,
"centrehead_posts": centreheadPosts,
})
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func (h* AdminHandler) GetJEPosts (c *gin.Context) {

var facultyPosts []models.FacultyPost
var wardenPosts []models.WardenPost
var centreheadPosts []models.CentreHeadPost
var centreheadPosts []models.CentreheadPost

// fetch faculty posts
result = h.DB.Select("id, title, type_of_post, status, assigned_je_id").
Expand Down Expand Up @@ -229,7 +229,7 @@ func (h* AdminHandler) GetJEPosts (c *gin.Context) {
"success": "posts fetched successfully",
"faculty_posts": facultyPosts,
"warden_posts": wardenPosts,
"centre_head_posts": centreheadPosts,
"centrehead_posts": centreheadPosts,
})
}

Expand Down Expand Up @@ -297,7 +297,7 @@ func (h *AdminHandler) AdminGetPost (c *gin.Context) {
}
reqPost = post
case "centrehead":
var post models.CentreHeadPost
var post models.CentreheadPost
result := h.DB.Preload("Author", func (db *gorm.DB) (*gorm.DB) {
return db.Select("id, email, building, phone_number")
}).
Expand Down
6 changes: 3 additions & 3 deletions handlers/admin_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ func (h *AdminHandler) AdminWardenPostStatus (c *gin.Context) {
c.JSON(200, gin.H{"success": "status updated"})
}

// AdminCentreHeadPostStatus sets the stage of the centre_head posts
func (h *AdminHandler) AdminCentreHeadPostStatus (c *gin.Context) {
// AdminCentreheadPostStatus sets the stage of the centrehead posts
func (h *AdminHandler) AdminCentreheadPostStatus(c *gin.Context) {
adminEmail, exists := c.Get(middleware.EmailKey)
if !exists {
c.JSON(401, gin.H{"error": "permission denied"})
Expand All @@ -277,7 +277,7 @@ func (h *AdminHandler) AdminCentreHeadPostStatus (c *gin.Context) {
}

// see if this post exists
var post models.CentreHeadPost
var post models.CentreheadPost
result = h.DB.Where("id = ?", uint(postID)).Take(&post)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
Expand Down
4 changes: 2 additions & 2 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (h *AuthHandler) VerifyAccount (c *gin.Context) {
case "warden":
h.DB.Model(&models.Warden{}).Where("email = ?", claims.Email).Update("is_verified", true)
case "centrehead":
h.DB.Model(&models.CentreHead{}).Where("email = ?", claims.Email).Update("is_verified", true)
h.DB.Model(&models.Centrehead{}).Where("email = ?", claims.Email).Update("is_verified", true)
default:
c.JSON(400, gin.H{"error": "role not defined"})
return
Expand Down Expand Up @@ -81,7 +81,7 @@ func (h *AuthHandler) UserProfile (c *gin.Context) {
}
userProfile = profile
case "centrehead":
var profile models.CentreHead
var profile models.Centrehead
result := h.DB.Where("email = ?", email).Take(&profile)
if result.Error != nil {
c.JSON(500, gin.H{"error": "failed to fetch user profile"})
Expand Down
30 changes: 15 additions & 15 deletions handlers/centrehead_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
)


// CentreHeadSignup registers the head of adminstrations.
// CentreheadSignup registers the head of adminstrations.
// On success, sends a verification email with a JWT token link.
func (h *AuthHandler) CentreHeadSignup(c *gin.Context) {
var inputs models.CentreHeadSignup
func (h *AuthHandler) CentreheadSignup(c *gin.Context) {
var inputs models.CentreheadSignup

if err := c.ShouldBindJSON(&inputs); err != nil {
c.JSON(400, gin.H{"error": "invalid request body"})
Expand All @@ -32,7 +32,7 @@ func (h *AuthHandler) CentreHeadSignup(c *gin.Context) {

inputs.Password = string(hashedPass)

centrehead := models.CentreHead{
centrehead := models.Centrehead{
Email: inputs.Email,
Password: inputs.Password,
Building: inputs.Building,
Expand All @@ -41,7 +41,7 @@ func (h *AuthHandler) CentreHeadSignup(c *gin.Context) {
CreatedAt: time.Now(),
}

var existingUser models.CentreHead
var existingUser models.Centrehead
result := h.DB.Where("email = ?", centrehead.Email).Take(&existingUser)
if result.Error == nil {
if !existingUser.IsVerified {
Expand Down Expand Up @@ -71,17 +71,17 @@ func (h *AuthHandler) CentreHeadSignup(c *gin.Context) {
}


// CentreHeadLogin authenticates the head of administrations using email and password.
// CentreheadLogin authenticates the head of administrations using email and password.
// On success, signs a JWT and stores it in an httpOnly cookie.
func (h *AuthHandler) CentreHeadLogin(c *gin.Context) {
var inputs models.CentreHeadLogin
func (h *AuthHandler) CentreheadLogin(c *gin.Context) {
var inputs models.CentreheadLogin

if err := c.ShouldBindJSON(&inputs); err != nil {
c.JSON(400, gin.H{"error": "invalid request body"})
return
}

var head models.CentreHead
var head models.Centrehead
result := h.DB.Where("email = ?", inputs.Email).Take(&head)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
Expand Down Expand Up @@ -123,14 +123,14 @@ func (h *AuthHandler) CentreHeadLogin(c *gin.Context) {
}


// CentreHeadForgetPassword sends an password reset email to the user
func (h* AuthHandler) CentreHeadForgetPassword(c *gin.Context) {
// CentreheadForgetPassword sends an password reset email to the user
func (h* AuthHandler) CentreheadForgetPassword(c *gin.Context) {
var input ForgetPassword
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(400, gin.H{"error": "invalid request body"})
return
}
var head models.CentreHead
var head models.Centrehead
result := h.DB.Where("email = ?", input.Email).Take(&head)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
Expand All @@ -155,8 +155,8 @@ func (h* AuthHandler) CentreHeadForgetPassword(c *gin.Context) {
}


// CentreHeadResetPassword resets the password of the user
func (h *AuthHandler) CentreHeadResetPassword(c *gin.Context) {
// CentreheadResetPassword resets the password of the user
func (h *AuthHandler) CentreheadResetPassword(c *gin.Context) {
// get the user from query parameters
userToken := c.Query("user")

Expand All @@ -166,7 +166,7 @@ func (h *AuthHandler) CentreHeadResetPassword(c *gin.Context) {
return
}

var head models.CentreHead
var head models.Centrehead
result := h.DB.Where("email = ?", claims.Email).Take(&head)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
Expand Down
Loading
Loading