Skip to content

Commit

Permalink
feat: add profile http endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Rajiv Harlalka <[email protected]>
  • Loading branch information
rajivharlalka committed Oct 7, 2024
1 parent d4bc225 commit 86a2fab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions backend/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ func HandleFileUpload(w http.ResponseWriter, r *http.Request) {
sendResponse(w, http.StatusAccepted, response)
}

func HandleProfile(w http.ResponseWriter, r *http.Request) {
approverUsername := r.Context().Value(CLAIMS_KEY).(*Claims).Username
sendResponse(w, http.StatusOK, map[string]string{"username": approverUsername})
}

func HandleDeletePaper(w http.ResponseWriter, r *http.Request) {
approverUsername := r.Context().Value(CLAIMS_KEY).(*Claims).Username
db := db.GetDB()
Expand Down Expand Up @@ -387,11 +392,12 @@ func populateDB(filename string) error {

year, _ := strconv.Atoi(qpData[2])
exam := qpData[3]
semester := qpData[4]
fromLibrary := false
fileLink := filepath.Join(config.Get().UploadedQPsPath, filename+".pdf")
query := "INSERT INTO iqps (course_code, course_name, year, exam, filelink, from_library) VALUES ($1, $2, $3, $4, $5, $6);"
query := "INSERT INTO iqps (course_code, course_name, year, exam, filelink, from_library, semester) VALUES ($1, $2, $3, $4, $5, $6. $7);"

_, err := db.Db.Exec(context.Background(), query, courseCode, courseName, year, exam, fileLink, fromLibrary)
_, err := db.Db.Exec(context.Background(), query, courseCode, courseName, year, exam, fileLink, fromLibrary, semester)
if err != nil {
return fmt.Errorf("failed to add qp to database: %v", err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
http.Handle("GET /all", JWTMiddleware(http.HandlerFunc(ListAllPapers)))
http.Handle("POST /approve", JWTMiddleware(http.HandlerFunc(HandleApprovePaper)))
http.Handle("POST /delete", JWTMiddleware(http.HandlerFunc(HandleDeletePaper)))
http.Handle("GET /profile", JWTMiddleware(http.HandlerFunc(HandleProfile)))

logger := config.Get().Logger
c := cors.New(cors.Options{
Expand Down

0 comments on commit 86a2fab

Please sign in to comment.