navigate(`/post/${role}/${post.id}`)}
+ onClick={() => navigate(`/posts/${role}/${post.id}`)}
className={`${theme.cardBg} relative border border-gray-200/80 rounded-xl shadow-sm hover:shadow-md hover:-translate-y-0.5 transition-all duration-300 cursor-pointer group flex min-h-[140px]`}
>
{/* Left accent bar (Linear / Vercel style) */}
diff --git a/app/src/components/layout/Footer.tsx b/app/src/components/layout/Footer.tsx
index 6aaa1c6..e4348d5 100644
--- a/app/src/components/layout/Footer.tsx
+++ b/app/src/components/layout/Footer.tsx
@@ -5,9 +5,9 @@ import { Link, useNavigate } from 'react-router-dom';
type Profile = { department?: string; hostel?: string; building?: string } | null;
function getPostRoute(profile: NonNullable
): string {
- if ('department' in profile) return '/faculty/post';
- if ('hostel' in profile) return '/warden/post';
- return '/centre-head/post';
+ if ('department' in profile) return '/faculty/posts';
+ if ('hostel' in profile) return '/warden/posts';
+ return '/centre-head/posts';
}
export function Footer() {
diff --git a/app/src/pages/Landing.tsx b/app/src/pages/Landing.tsx
index e94228b..e4449ed 100644
--- a/app/src/pages/Landing.tsx
+++ b/app/src/pages/Landing.tsx
@@ -6,9 +6,9 @@ import { MainLayout } from '../components/layout/MainLayout';
type Profile = { department?: string; hostel?: string; building?: string } | null;
function getPostRoute(profile: NonNullable): string {
- if ('department' in profile) return '/faculty/post';
- if ('hostel' in profile) return '/warden/post';
- return '/centre-head/post';
+ if ('department' in profile) return '/faculty/posts';
+ if ('hostel' in profile) return '/warden/posts';
+ return '/centre-head/posts';
}
export function Landing() {
diff --git a/app/src/pages/admin/AdminPostView.tsx b/app/src/pages/admin/AdminPostView.tsx
index eda686e..889a73d 100644
--- a/app/src/pages/admin/AdminPostView.tsx
+++ b/app/src/pages/admin/AdminPostView.tsx
@@ -314,9 +314,16 @@ export function AdminPostView() {
})
.catch((err: Error & { status?: number }) => {
if (!silent) {
+ // Not an admin — this is just the non-admin viewer of the same
+ // post, bounce straight to the plain (non-admin) post view instead
+ // of showing an access-denied screen.
+ if (err.status === 403) {
+ navigate(`/posts/${role}/${post_id}`, { replace: true });
+ return;
+ }
setError({ message: err.message, status: err.status });
setLoading(false);
- if (err.status === 401 || err.status === 403) setTimeout(() => navigate('/'), 4000);
+ if (err.status === 401) setTimeout(() => navigate('/'), 4000);
}
});
}, [role, post_id, navigate]);
diff --git a/app/src/pages/post/CentreHeadPost.tsx b/app/src/pages/post/CentreHeadPost.tsx
index 287b702..25fa78d 100644
--- a/app/src/pages/post/CentreHeadPost.tsx
+++ b/app/src/pages/post/CentreHeadPost.tsx
@@ -29,7 +29,7 @@ export function CentreHeadPost() {
setMessage('');
try {
- const response = await fetch('/api/post/centrehead', {
+ const response = await fetch('/api/posts/centrehead', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
@@ -43,7 +43,7 @@ export function CentreHeadPost() {
setMessage(data.success || 'Complaint submitted successfully!');
setFormData({ type_of_post: '', title: '', description: '' });
if (data.post?.id) {
- navigate(`/post/centrehead/${data.post.id}`);
+ navigate(`/posts/centrehead/${data.post.id}`);
}
} else {
setStatus('error');
diff --git a/app/src/pages/post/FacultyPost.tsx b/app/src/pages/post/FacultyPost.tsx
index 800679a..977d7d6 100644
--- a/app/src/pages/post/FacultyPost.tsx
+++ b/app/src/pages/post/FacultyPost.tsx
@@ -30,7 +30,7 @@ export function FacultyPost() {
setMessage('');
try {
- const response = await fetch('/api/post/faculty', {
+ const response = await fetch('/api/posts/faculty', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
@@ -44,7 +44,7 @@ export function FacultyPost() {
setMessage(data.success || 'Complaint submitted successfully!');
setFormData({ place: '', type_of_post: '', title: '', description: '' });
if (data.post?.id) {
- navigate(`/post/faculty/${data.post.id}`);
+ navigate(`/posts/faculty/${data.post.id}`);
}
} else {
setStatus('error');
diff --git a/app/src/pages/post/PostView.tsx b/app/src/pages/post/PostView.tsx
index 5665456..e3dacda 100644
--- a/app/src/pages/post/PostView.tsx
+++ b/app/src/pages/post/PostView.tsx
@@ -104,7 +104,7 @@ export function PostView() {
const fetchPost = useCallback(async () => {
try {
- const res = await fetch(`/api/post/${role}/${post_id}`, { credentials: 'include' });
+ const res = await fetch(`/api/posts/${role}/${post_id}`, { credentials: 'include' });
if (!res.ok) {
throw new Error(`Failed to fetch post details (${res.status})`);
}
@@ -189,8 +189,8 @@ export function PostView() {
const comments = post.comments ?? [];
const editExpired = isEditWindowExpired(post.created_at);
- 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';
+ const editBase = isFaculty ? '/api/posts/faculty/edit' : isWarden ? '/api/posts/warden/edit' : '/api/posts/centrehead/edit';
+ const deleteBase = isFaculty ? '/api/posts/faculty/delete' : isWarden ? '/api/posts/warden/delete' : '/api/posts/centrehead/delete';
function startEdit() {
if (!post) return;
@@ -261,7 +261,7 @@ export function PostView() {
setCommentSubmitting(true);
setCommentError(null);
try {
- const res = await fetch(`/api/post/${role}/comment/${post.id}`, {
+ const res = await fetch(`/api/posts/${role}/comment/${post.id}`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
diff --git a/app/src/pages/post/WardenPost.tsx b/app/src/pages/post/WardenPost.tsx
index 94fee2a..65e41ad 100644
--- a/app/src/pages/post/WardenPost.tsx
+++ b/app/src/pages/post/WardenPost.tsx
@@ -30,7 +30,7 @@ export function WardenPost() {
setMessage('');
try {
- const response = await fetch('/api/post/warden', {
+ const response = await fetch('/api/posts/warden', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
@@ -44,7 +44,7 @@ export function WardenPost() {
setMessage(data.success || 'Complaint submitted successfully!');
setFormData({ room_number: '', type_of_post: '', title: '', description: '' });
if (data.post?.id) {
- navigate(`/post/warden/${data.post.id}`);
+ navigate(`/posts/warden/${data.post.id}`);
}
} else {
setStatus('error');
diff --git a/app/src/pages/profile/Profile.tsx b/app/src/pages/profile/Profile.tsx
index 8a88f19..e742043 100644
--- a/app/src/pages/profile/Profile.tsx
+++ b/app/src/pages/profile/Profile.tsx
@@ -55,9 +55,9 @@ export function Profile() {
const fetchPosts = useCallback((silent = false) => {
if (!profile) return;
let endpoint: string;
- 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/centrehead';
+ if ('department' in profile) endpoint = '/api/posts/faculty';
+ else if ('hostel' in profile) endpoint = '/api/posts/warden';
+ else if ('building' in profile) endpoint = '/api/posts/centrehead';
else return;
if (!silent) setPostsLoading(true);
@@ -116,12 +116,12 @@ export function Profile() {
let roleLabel = 'User';
let registerRoute = '/';
let role: Role = 'centrehead';
- if (isFaculty) { roleLabel = 'Faculty Member'; registerRoute = '/faculty/post'; role = 'faculty'; }
- else if (isWarden) { roleLabel = 'Hostel Warden'; registerRoute = '/warden/post'; role = 'warden'; }
- else if (isCentreHead) { roleLabel = 'Centre Head'; registerRoute = '/centre-head/post'; role = 'centrehead'; }
+ if (isFaculty) { roleLabel = 'Faculty Member'; registerRoute = '/faculty/posts'; role = 'faculty'; }
+ else if (isWarden) { roleLabel = 'Hostel Warden'; registerRoute = '/warden/posts'; role = 'warden'; }
+ else if (isCentreHead) { roleLabel = 'Centre Head'; registerRoute = '/centre-head/posts'; role = 'centrehead'; }
- 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';
+ const editBase = isFaculty ? '/api/posts/faculty/edit' : isWarden ? '/api/posts/warden/edit' : '/api/posts/centrehead/edit';
+ const deleteBase = isFaculty ? '/api/posts/faculty/delete' : isWarden ? '/api/posts/warden/delete' : '/api/posts/centrehead/delete';
const handleLogout = async () => {
try { await fetch('/api/auth/logout', { method: 'POST' }); } catch { /* ignore */ }
diff --git a/routes/post.go b/routes/post.go
index 50d092e..4e633f5 100644
--- a/routes/post.go
+++ b/routes/post.go
@@ -9,28 +9,28 @@ import (
func PostRoute(e *gin.Engine, h *handlers.PostHandler) {
// APIs for new post
- e.POST("/api/post/faculty", middleware.IsAuthenticated(), h.FacultyPost)
- e.POST("/api/post/warden", middleware.IsAuthenticated(), h.WardenPost)
- e.POST("/api/post/centrehead", middleware.IsAuthenticated(), h.CentreheadPost)
+ e.POST("/api/posts/faculty", middleware.IsAuthenticated(), h.FacultyPost)
+ e.POST("/api/posts/warden", middleware.IsAuthenticated(), h.WardenPost)
+ e.POST("/api/posts/centrehead", middleware.IsAuthenticated(), h.CentreheadPost)
// APIs for updating the post
- e.PATCH("/api/post/faculty/edit/:post_id", middleware.IsAuthenticated(), h.FacultyPostEdit)
- e.PATCH("/api/post/warden/edit/:post_id", middleware.IsAuthenticated(), h.WardenPostEdit)
- e.PATCH("/api/post/centrehead/edit/:post_id", middleware.IsAuthenticated(), h.CentreheadPostEdit)
+ e.PATCH("/api/posts/faculty/edit/:post_id", middleware.IsAuthenticated(), h.FacultyPostEdit)
+ e.PATCH("/api/posts/warden/edit/:post_id", middleware.IsAuthenticated(), h.WardenPostEdit)
+ e.PATCH("/api/posts/centrehead/edit/:post_id", middleware.IsAuthenticated(), h.CentreheadPostEdit)
// APIs for deleting the post
- e.DELETE("/api/post/faculty/delete/:post_id", middleware.IsAuthenticated(), h.FacultyPostDelete)
- e.DELETE("/api/post/warden/delete/:post_id", middleware.IsAuthenticated(), h.WardenPostDelete)
- e.DELETE("/api/post/centrehead/delete/:post_id", middleware.IsAuthenticated(), h.CentreheadPostDelete)
+ e.DELETE("/api/posts/faculty/delete/:post_id", middleware.IsAuthenticated(), h.FacultyPostDelete)
+ e.DELETE("/api/posts/warden/delete/:post_id", middleware.IsAuthenticated(), h.WardenPostDelete)
+ e.DELETE("/api/posts/centrehead/delete/:post_id", middleware.IsAuthenticated(), h.CentreheadPostDelete)
// APIs for getting the posts
- e.GET("/api/post/faculty", middleware.IsAuthenticated(), h.GetFacultyPosts)
- e.GET("/api/post/warden", middleware.IsAuthenticated(), h.GetWardenPosts)
- e.GET("/api/post/centrehead", middleware.IsAuthenticated(), h.GetCentreheadPosts)
- e.GET("/api/post/:role/:post_id", middleware.IsAuthenticated(), h.GetPostByID)
+ e.GET("/api/posts/faculty", middleware.IsAuthenticated(), h.GetFacultyPosts)
+ e.GET("/api/posts/warden", middleware.IsAuthenticated(), h.GetWardenPosts)
+ e.GET("/api/posts/centrehead", middleware.IsAuthenticated(), h.GetCentreheadPosts)
+ e.GET("/api/posts/:role/:post_id", middleware.IsAuthenticated(), h.GetPostByID)
// APIs for comments on the posts
- e.POST("/api/post/faculty/comment/:post_id", middleware.IsAuthenticated() ,h.FacultyPostComment)
- e.POST("/api/post/warden/comment/:post_id", middleware.IsAuthenticated(), h.WardenPostComment)
- e.POST("/api/post/centrehead/comment/:post_id", middleware.IsAuthenticated(), h.CentreheadPostComment)
+ e.POST("/api/posts/faculty/comment/:post_id", middleware.IsAuthenticated() ,h.FacultyPostComment)
+ e.POST("/api/posts/warden/comment/:post_id", middleware.IsAuthenticated(), h.WardenPostComment)
+ e.POST("/api/posts/centrehead/comment/:post_id", middleware.IsAuthenticated(), h.CentreheadPostComment)
}
diff --git a/test/centrehead_post_test.go b/test/centrehead_post_test.go
index a508ffa..7274af8 100644
--- a/test/centrehead_post_test.go
+++ b/test/centrehead_post_test.go
@@ -20,7 +20,7 @@ func TestCentreheadPost_Create_Success(t *testing.T) {
"title": "Broken door",
"description": "Main entrance door of LHC is jammed",
}
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead", body)
assertStatus(t, rec, 201)
@@ -35,7 +35,7 @@ func TestCentreheadPost_Create_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
body := map[string]any{"type_of_post": "Civil", "title": "x", "description": "y"}
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead", body)
assertStatus(t, rec, 401)
}
@@ -43,7 +43,7 @@ func TestCentreheadPost_Create_InvalidBody(t *testing.T) {
db := newTestDB(t)
ch := seedCentrehead(t, db, "ch.badbody@iit.ac.in")
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead", []string{"bad"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead", []string{"bad"})
assertStatus(t, rec, 400)
}
@@ -51,7 +51,7 @@ func TestCentreheadPost_Create_UserNotFound(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, authAs(999, "ghost.ch@iit.ac.in"))
body := map[string]any{"type_of_post": "Civil", "title": "x", "description": "y"}
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead", body)
assertStatus(t, rec, 401)
}
@@ -64,7 +64,7 @@ func TestCentreheadPostEdit_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/centrehead/edit/1", map[string]any{
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/centrehead/edit/1", map[string]any{
"title": "new title",
"description": "new desc",
})
@@ -82,7 +82,7 @@ func TestCentreheadPostEdit_NotFound(t *testing.T) {
db := newTestDB(t)
ch := seedCentrehead(t, db, "ch.editnf@iit.ac.in")
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/centrehead/edit/999", map[string]any{"title": "x"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/centrehead/edit/999", map[string]any{"title": "x"})
assertStatus(t, rec, 404)
}
@@ -94,14 +94,14 @@ func TestCentreheadPostEdit_WrongAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/centrehead/edit/1", map[string]any{"title": "hijack"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/centrehead/edit/1", map[string]any{"title": "hijack"})
assertStatus(t, rec, 403)
}
func TestCentreheadPostEdit_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodPatch, "/api/post/centrehead/edit/1", map[string]any{"title": "x"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/centrehead/edit/1", map[string]any{"title": "x"})
assertStatus(t, rec, 401)
}
@@ -113,7 +113,7 @@ func TestCentreheadPostEdit_ExpiredWindow(t *testing.T) {
db.Model(&post).Update("created_at", time.Now().Add(-31*time.Minute))
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/centrehead/edit/1", map[string]any{"title": "new"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/centrehead/edit/1", map[string]any{"title": "new"})
assertStatus(t, rec, 403)
}
@@ -126,7 +126,7 @@ func TestCentreheadPostDelete_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/centrehead/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/centrehead/delete/1", nil)
assertStatus(t, rec, 200)
@@ -141,7 +141,7 @@ func TestCentreheadPostDelete_NotFound(t *testing.T) {
db := newTestDB(t)
ch := seedCentrehead(t, db, "ch.delnf@iit.ac.in")
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/centrehead/delete/77", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/centrehead/delete/77", nil)
assertStatus(t, rec, 404)
}
@@ -153,14 +153,14 @@ func TestCentreheadPostDelete_WrongAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/centrehead/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/centrehead/delete/1", nil)
assertStatus(t, rec, 403)
}
func TestCentreheadPostDelete_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodDelete, "/api/post/centrehead/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/centrehead/delete/1", nil)
assertStatus(t, rec, 401)
}
@@ -172,7 +172,7 @@ func TestCentreheadPostDelete_ExpiredWindow(t *testing.T) {
db.Model(&post).Update("created_at", time.Now().Add(-31*time.Minute))
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/centrehead/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/centrehead/delete/1", nil)
assertStatus(t, rec, 403)
}
@@ -185,7 +185,7 @@ func TestGetCentreheadPosts_Success(t *testing.T) {
db.Create(&models.CentreheadPost{CentreheadID: ch.ID, TypeOfPost: models.TypeElectrical, Title: "b", Description: "d"})
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/centrehead", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/centrehead", nil)
assertStatus(t, rec, 200)
out := decodeBody(t, rec)
@@ -203,7 +203,7 @@ func TestGetCentreheadPosts_OnlyOwn(t *testing.T) {
db.Create(&models.CentreheadPost{CentreheadID: theirs.ID, TypeOfPost: models.TypeCivil, Title: "theirs", Description: "d"})
e := newPostRouter(db, authAs(mine.ID, mine.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/centrehead", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/centrehead", nil)
assertStatus(t, rec, 200)
out := decodeBody(t, rec)
@@ -215,6 +215,6 @@ func TestGetCentreheadPosts_OnlyOwn(t *testing.T) {
func TestGetCentreheadPosts_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodGet, "/api/post/centrehead", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/centrehead", nil)
assertStatus(t, rec, 401)
}
diff --git a/test/faculty_post_test.go b/test/faculty_post_test.go
index f1fa323..0b92e0c 100644
--- a/test/faculty_post_test.go
+++ b/test/faculty_post_test.go
@@ -21,7 +21,7 @@ func TestFacultyPost_Create_Success(t *testing.T) {
"title": "Leaking roof",
"description": "Roof leaks in lab 3",
}
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty", body)
assertStatus(t, rec, 201)
@@ -37,7 +37,7 @@ func TestFacultyPost_Create_Unauthenticated(t *testing.T) {
e := newPostRouter(db, noAuth())
body := map[string]any{"place": "Departmental", "type_of_post": "Civil", "title": "x", "description": "y"}
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty", body)
assertStatus(t, rec, 401)
}
@@ -48,7 +48,7 @@ func TestFacultyPost_Create_InvalidBody(t *testing.T) {
e := newPostRouter(db, authAs(f.ID, f.Email))
// Send a JSON array where an object is expected.
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty", []string{"not", "an", "object"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty", []string{"not", "an", "object"})
assertStatus(t, rec, 400)
}
@@ -59,7 +59,7 @@ func TestFacultyPost_Create_UserNotFound(t *testing.T) {
e := newPostRouter(db, authAs(999, "ghost@iit.ac.in"))
body := map[string]any{"place": "Departmental", "type_of_post": "Civil", "title": "x", "description": "y"}
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty", body)
assertStatus(t, rec, 401)
}
@@ -73,7 +73,7 @@ func TestFacultyPostEdit_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/faculty/edit/1", map[string]any{
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/faculty/edit/1", map[string]any{
"title": "new title",
"description": "new desc",
})
@@ -92,7 +92,7 @@ func TestFacultyPostEdit_NotFound(t *testing.T) {
f := seedFaculty(t, db, "fac.editnf@iit.ac.in")
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/faculty/edit/424242", map[string]any{"title": "x"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/faculty/edit/424242", map[string]any{"title": "x"})
assertStatus(t, rec, 404)
}
@@ -105,7 +105,7 @@ func TestFacultyPostEdit_WrongAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/faculty/edit/1", map[string]any{"title": "hijack"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/faculty/edit/1", map[string]any{"title": "hijack"})
assertStatus(t, rec, 403)
}
@@ -113,7 +113,7 @@ func TestFacultyPostEdit_WrongAuthor(t *testing.T) {
func TestFacultyPostEdit_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodPatch, "/api/post/faculty/edit/1", map[string]any{"title": "x"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/faculty/edit/1", map[string]any{"title": "x"})
assertStatus(t, rec, 401)
}
@@ -125,7 +125,7 @@ func TestFacultyPostEdit_ExpiredWindow(t *testing.T) {
db.Model(&post).Update("created_at", time.Now().Add(-31*time.Minute))
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/faculty/edit/1", map[string]any{"title": "new"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/faculty/edit/1", map[string]any{"title": "new"})
assertStatus(t, rec, 403)
}
@@ -138,7 +138,7 @@ func TestFacultyPostDelete_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/faculty/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/faculty/delete/1", nil)
assertStatus(t, rec, 200)
@@ -153,7 +153,7 @@ func TestFacultyPostDelete_NotFound(t *testing.T) {
db := newTestDB(t)
f := seedFaculty(t, db, "fac.delnf@iit.ac.in")
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/faculty/delete/123", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/faculty/delete/123", nil)
assertStatus(t, rec, 404)
}
@@ -165,7 +165,7 @@ func TestFacultyPostDelete_WrongAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/faculty/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/faculty/delete/1", nil)
assertStatus(t, rec, 403)
}
@@ -173,7 +173,7 @@ func TestFacultyPostDelete_WrongAuthor(t *testing.T) {
func TestFacultyPostDelete_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodDelete, "/api/post/faculty/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/faculty/delete/1", nil)
assertStatus(t, rec, 401)
}
@@ -185,7 +185,7 @@ func TestFacultyPostDelete_ExpiredWindow(t *testing.T) {
db.Model(&post).Update("created_at", time.Now().Add(-31*time.Minute))
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/faculty/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/faculty/delete/1", nil)
assertStatus(t, rec, 403)
}
@@ -198,7 +198,7 @@ func TestGetFacultyPosts_Success(t *testing.T) {
db.Create(&models.FacultyPost{FacultyID: f.ID, Place: models.PlaceResidential, TypeOfPost: models.TypeElectrical, Title: "b", Description: "d"})
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/faculty", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/faculty", nil)
assertStatus(t, rec, 200)
out := decodeBody(t, rec)
@@ -216,7 +216,7 @@ func TestGetFacultyPosts_OnlyOwn(t *testing.T) {
db.Create(&models.FacultyPost{FacultyID: theirs.ID, Place: models.PlaceDepartmental, TypeOfPost: models.TypeCivil, Title: "theirs", Description: "d"})
e := newPostRouter(db, authAs(mine.ID, mine.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/faculty", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/faculty", nil)
assertStatus(t, rec, 200)
out := decodeBody(t, rec)
@@ -229,6 +229,6 @@ func TestGetFacultyPosts_OnlyOwn(t *testing.T) {
func TestGetFacultyPosts_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodGet, "/api/post/faculty", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/faculty", nil)
assertStatus(t, rec, 401)
}
diff --git a/test/helpers_test.go b/test/helpers_test.go
index a49ed39..0f11d71 100644
--- a/test/helpers_test.go
+++ b/test/helpers_test.go
@@ -133,26 +133,26 @@ func newPostRouter(db *gorm.DB, auth gin.HandlerFunc) *gin.Engine {
e := gin.New()
h := &handlers.PostHandler{DB: db}
- e.POST("/api/post/faculty", auth, h.FacultyPost)
- e.POST("/api/post/warden", auth, h.WardenPost)
- e.POST("/api/post/centrehead", auth, h.CentreheadPost)
-
- e.PATCH("/api/post/faculty/edit/:post_id", auth, h.FacultyPostEdit)
- e.PATCH("/api/post/warden/edit/:post_id", auth, h.WardenPostEdit)
- e.PATCH("/api/post/centrehead/edit/:post_id", auth, h.CentreheadPostEdit)
-
- e.DELETE("/api/post/faculty/delete/:post_id", auth, h.FacultyPostDelete)
- e.DELETE("/api/post/warden/delete/:post_id", auth, h.WardenPostDelete)
- e.DELETE("/api/post/centrehead/delete/:post_id", auth, h.CentreheadPostDelete)
-
- e.GET("/api/post/faculty", auth, h.GetFacultyPosts)
- e.GET("/api/post/warden", auth, h.GetWardenPosts)
- e.GET("/api/post/centrehead", auth, h.GetCentreheadPosts)
- e.GET("/api/post/:role/:post_id", auth, h.GetPostByID)
-
- e.POST("/api/post/faculty/comment/:post_id", auth, h.FacultyPostComment)
- e.POST("/api/post/warden/comment/:post_id", auth, h.WardenPostComment)
- e.POST("/api/post/centrehead/comment/:post_id", auth, h.CentreheadPostComment)
+ e.POST("/api/posts/faculty", auth, h.FacultyPost)
+ e.POST("/api/posts/warden", auth, h.WardenPost)
+ e.POST("/api/posts/centrehead", auth, h.CentreheadPost)
+
+ e.PATCH("/api/posts/faculty/edit/:post_id", auth, h.FacultyPostEdit)
+ e.PATCH("/api/posts/warden/edit/:post_id", auth, h.WardenPostEdit)
+ e.PATCH("/api/posts/centrehead/edit/:post_id", auth, h.CentreheadPostEdit)
+
+ e.DELETE("/api/posts/faculty/delete/:post_id", auth, h.FacultyPostDelete)
+ e.DELETE("/api/posts/warden/delete/:post_id", auth, h.WardenPostDelete)
+ e.DELETE("/api/posts/centrehead/delete/:post_id", auth, h.CentreheadPostDelete)
+
+ e.GET("/api/posts/faculty", auth, h.GetFacultyPosts)
+ e.GET("/api/posts/warden", auth, h.GetWardenPosts)
+ e.GET("/api/posts/centrehead", auth, h.GetCentreheadPosts)
+ e.GET("/api/posts/:role/:post_id", auth, h.GetPostByID)
+
+ e.POST("/api/posts/faculty/comment/:post_id", auth, h.FacultyPostComment)
+ e.POST("/api/posts/warden/comment/:post_id", auth, h.WardenPostComment)
+ e.POST("/api/posts/centrehead/comment/:post_id", auth, h.CentreheadPostComment)
return e
}
diff --git a/test/post_comment_test.go b/test/post_comment_test.go
index cc187e3..356f426 100644
--- a/test/post_comment_test.go
+++ b/test/post_comment_test.go
@@ -21,7 +21,7 @@ func TestFacultyPostComment_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty/comment/1", handlers.CommentType{Content: "my issue persists"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty/comment/1", handlers.CommentType{Content: "my issue persists"})
assertStatus(t, rec, 201)
var doc models.Comment
@@ -47,14 +47,14 @@ func TestFacultyPostComment_NotAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty/comment/1", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty/comment/1", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 403)
}
func TestFacultyPostComment_UserNotFound(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, authAs(999, "ghost@iit.ac.in"))
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty/comment/1", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty/comment/1", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 404)
}
@@ -62,7 +62,7 @@ func TestFacultyPostComment_PostNotFound(t *testing.T) {
db := newTestDB(t)
f := seedFaculty(t, db, "fac.pnf@iit.ac.in")
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty/comment/9999", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty/comment/9999", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 404)
}
@@ -70,7 +70,7 @@ func TestFacultyPostComment_BadPostID(t *testing.T) {
db := newTestDB(t)
f := seedFaculty(t, db, "fac.badpid@iit.ac.in")
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/faculty/comment/not-a-number", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/faculty/comment/not-a-number", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 500)
}
@@ -81,7 +81,7 @@ func TestFacultyPostComment_InvalidBody(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequestRaw(t, e, http.MethodPost, "/api/post/faculty/comment/1", "{not json")
+ rec := doRequestRaw(t, e, http.MethodPost, "/api/posts/faculty/comment/1", "{not json")
assertStatus(t, rec, 400)
}
@@ -94,7 +94,7 @@ func TestWardenPostComment_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden/comment/1", handlers.CommentType{Content: "still broken"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden/comment/1", handlers.CommentType{Content: "still broken"})
assertStatus(t, rec, 201)
var doc models.Comment
@@ -120,14 +120,14 @@ func TestWardenPostComment_NotAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden/comment/1", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden/comment/1", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 403)
}
func TestWardenPostComment_UserNotFound(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, authAs(999, "ghost@iit.ac.in"))
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden/comment/1", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden/comment/1", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 404)
}
@@ -135,7 +135,7 @@ func TestWardenPostComment_PostNotFound(t *testing.T) {
db := newTestDB(t)
w := seedWarden(t, db, "war.pnf@iit.ac.in")
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden/comment/9999", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden/comment/9999", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 404)
}
@@ -143,7 +143,7 @@ func TestWardenPostComment_BadPostID(t *testing.T) {
db := newTestDB(t)
w := seedWarden(t, db, "war.badpid@iit.ac.in")
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden/comment/not-a-number", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden/comment/not-a-number", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 500)
}
@@ -154,7 +154,7 @@ func TestWardenPostComment_InvalidBody(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequestRaw(t, e, http.MethodPost, "/api/post/warden/comment/1", "{not json")
+ rec := doRequestRaw(t, e, http.MethodPost, "/api/posts/warden/comment/1", "{not json")
assertStatus(t, rec, 400)
}
@@ -167,7 +167,7 @@ func TestCentreheadPostComment_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead/comment/1", handlers.CommentType{Content: "needs urgent fix"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead/comment/1", handlers.CommentType{Content: "needs urgent fix"})
assertStatus(t, rec, 201)
var doc models.Comment
@@ -193,14 +193,14 @@ func TestCentreheadPostComment_NotAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead/comment/1", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead/comment/1", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 403)
}
func TestCentreheadPostComment_UserNotFound(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, authAs(999, "ghost@iit.ac.in"))
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead/comment/1", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead/comment/1", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 404)
}
@@ -208,7 +208,7 @@ func TestCentreheadPostComment_PostNotFound(t *testing.T) {
db := newTestDB(t)
ch := seedCentrehead(t, db, "ch.pnf@iit.ac.in")
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead/comment/9999", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead/comment/9999", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 404)
}
@@ -216,7 +216,7 @@ func TestCentreheadPostComment_BadPostID(t *testing.T) {
db := newTestDB(t)
ch := seedCentrehead(t, db, "ch.badpid@iit.ac.in")
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/centrehead/comment/not-a-number", handlers.CommentType{Content: "x"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/centrehead/comment/not-a-number", handlers.CommentType{Content: "x"})
assertStatus(t, rec, 500)
}
@@ -227,6 +227,6 @@ func TestCentreheadPostComment_InvalidBody(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(ch.ID, ch.Email))
- rec := doRequestRaw(t, e, http.MethodPost, "/api/post/centrehead/comment/1", "{not json")
+ rec := doRequestRaw(t, e, http.MethodPost, "/api/posts/centrehead/comment/1", "{not json")
assertStatus(t, rec, 400)
}
diff --git a/test/post_get_test.go b/test/post_get_test.go
index 5aec81f..f639e9d 100644
--- a/test/post_get_test.go
+++ b/test/post_get_test.go
@@ -31,7 +31,7 @@ func TestFacultyPost_GetByID_Success(t *testing.T) {
db.Create(&comment)
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/faculty/1", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/faculty/1", nil)
assertStatus(t, rec, 200)
@@ -63,7 +63,7 @@ func TestWardenPost_GetByID_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/warden/1", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/warden/1", nil)
assertStatus(t, rec, 200)
@@ -84,7 +84,7 @@ func TestFacultyPost_GetByID_NotFound(t *testing.T) {
f := seedFaculty(t, db, "fac.getidnf@iit.ac.in")
e := newPostRouter(db, authAs(f.ID, f.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/faculty/999", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/faculty/999", nil)
assertStatus(t, rec, 404)
}
@@ -105,7 +105,7 @@ func TestFacultyPost_GetByID_WrongUser(t *testing.T) {
// User 2 tries to access User 1's post
e := newPostRouter(db, authAs(f2.ID, f2.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/faculty/1", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/faculty/1", nil)
// Should not find the post as it filters by user ID
assertStatus(t, rec, 404)
diff --git a/test/warden_post_test.go b/test/warden_post_test.go
index 72af71c..6eb07b0 100644
--- a/test/warden_post_test.go
+++ b/test/warden_post_test.go
@@ -21,7 +21,7 @@ func TestWardenPost_Create_Success(t *testing.T) {
"title": "Fan not working",
"description": "Ceiling fan dead in B-204",
}
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden", body)
assertStatus(t, rec, 201)
@@ -36,7 +36,7 @@ func TestWardenPost_Create_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
body := map[string]any{"type_of_post": "Civil", "room_number": "1", "title": "x", "description": "y"}
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden", body)
assertStatus(t, rec, 401)
}
@@ -44,7 +44,7 @@ func TestWardenPost_Create_InvalidBody(t *testing.T) {
db := newTestDB(t)
w := seedWarden(t, db, "war.badbody@iit.ac.in")
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden", []string{"bad"})
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden", []string{"bad"})
assertStatus(t, rec, 400)
}
@@ -52,7 +52,7 @@ func TestWardenPost_Create_UserNotFound(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, authAs(999, "ghost.warden@iit.ac.in"))
body := map[string]any{"type_of_post": "Civil", "room_number": "1", "title": "x", "description": "y"}
- rec := doRequest(t, e, http.MethodPost, "/api/post/warden", body)
+ rec := doRequest(t, e, http.MethodPost, "/api/posts/warden", body)
assertStatus(t, rec, 401)
}
@@ -65,7 +65,7 @@ func TestWardenPostEdit_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/warden/edit/1", map[string]any{
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/warden/edit/1", map[string]any{
"room_number": "A-2",
"title": "new title",
})
@@ -83,7 +83,7 @@ func TestWardenPostEdit_NotFound(t *testing.T) {
db := newTestDB(t)
w := seedWarden(t, db, "war.editnf@iit.ac.in")
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/warden/edit/999", map[string]any{"title": "x"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/warden/edit/999", map[string]any{"title": "x"})
assertStatus(t, rec, 404)
}
@@ -95,14 +95,14 @@ func TestWardenPostEdit_WrongAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/warden/edit/1", map[string]any{"title": "hijack"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/warden/edit/1", map[string]any{"title": "hijack"})
assertStatus(t, rec, 403)
}
func TestWardenPostEdit_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodPatch, "/api/post/warden/edit/1", map[string]any{"title": "x"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/warden/edit/1", map[string]any{"title": "x"})
assertStatus(t, rec, 401)
}
@@ -114,7 +114,7 @@ func TestWardenPostEdit_ExpiredWindow(t *testing.T) {
db.Model(&post).Update("created_at", time.Now().Add(-31*time.Minute))
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodPatch, "/api/post/warden/edit/1", map[string]any{"title": "new"})
+ rec := doRequest(t, e, http.MethodPatch, "/api/posts/warden/edit/1", map[string]any{"title": "new"})
assertStatus(t, rec, 403)
}
@@ -127,7 +127,7 @@ func TestWardenPostDelete_Success(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/warden/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/warden/delete/1", nil)
assertStatus(t, rec, 200)
@@ -142,7 +142,7 @@ func TestWardenPostDelete_NotFound(t *testing.T) {
db := newTestDB(t)
w := seedWarden(t, db, "war.delnf@iit.ac.in")
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/warden/delete/55", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/warden/delete/55", nil)
assertStatus(t, rec, 404)
}
@@ -154,14 +154,14 @@ func TestWardenPostDelete_WrongAuthor(t *testing.T) {
db.Create(&post)
e := newPostRouter(db, authAs(other.ID, other.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/warden/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/warden/delete/1", nil)
assertStatus(t, rec, 403)
}
func TestWardenPostDelete_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodDelete, "/api/post/warden/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/warden/delete/1", nil)
assertStatus(t, rec, 401)
}
@@ -173,7 +173,7 @@ func TestWardenPostDelete_ExpiredWindow(t *testing.T) {
db.Model(&post).Update("created_at", time.Now().Add(-31*time.Minute))
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodDelete, "/api/post/warden/delete/1", nil)
+ rec := doRequest(t, e, http.MethodDelete, "/api/posts/warden/delete/1", nil)
assertStatus(t, rec, 403)
}
@@ -186,7 +186,7 @@ func TestGetWardenPosts_Success(t *testing.T) {
db.Create(&models.WardenPost{WardenID: w.ID, RoomNumber: "A-2", TypeOfPost: models.TypeElectrical, Title: "b", Description: "d"})
e := newPostRouter(db, authAs(w.ID, w.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/warden", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/warden", nil)
assertStatus(t, rec, 200)
out := decodeBody(t, rec)
@@ -204,7 +204,7 @@ func TestGetWardenPosts_OnlyOwn(t *testing.T) {
db.Create(&models.WardenPost{WardenID: theirs.ID, RoomNumber: "A-2", TypeOfPost: models.TypeCivil, Title: "theirs", Description: "d"})
e := newPostRouter(db, authAs(mine.ID, mine.Email))
- rec := doRequest(t, e, http.MethodGet, "/api/post/warden", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/warden", nil)
assertStatus(t, rec, 200)
out := decodeBody(t, rec)
@@ -216,6 +216,6 @@ func TestGetWardenPosts_OnlyOwn(t *testing.T) {
func TestGetWardenPosts_Unauthenticated(t *testing.T) {
db := newTestDB(t)
e := newPostRouter(db, noAuth())
- rec := doRequest(t, e, http.MethodGet, "/api/post/warden", nil)
+ rec := doRequest(t, e, http.MethodGet, "/api/posts/warden", nil)
assertStatus(t, rec, 401)
}