// Delete deletes the resume. // // Method POST // // Route /resume/delete/:id // // Restrictions Yes // // Template None func Delete(ctx *echo.Context) error { var flashMessages = flash.New() id, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } user := ctx.Get("User").(*models.Person) resume, err := query.GetResumeByID(id) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage) } // Users are allowed to delete resumes that they don't own. if resume.PersonID != user.ID { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } err = query.Delete(resume) if err != nil { utils.SetData(ctx, "Message", tmpl.ServerErrorMessage) return ctx.Render(http.StatusInternalServerError, tmpl.ErrServerTpl, utils.GetData(ctx)) } flashMessages.Success("resume successful deleted") flashMessages.Save(ctx) ctx.Redirect(http.StatusFound, "/resume/") return nil }
// RegionsJobPaginate a route frr /jobs/regions/:name/:from/:to. It handles pagination where // form to is offset and limit respectively. // // For example route "/jobs/regions/mza/2/4" will render from 2nd to 4th latest jobs from mwanza. // // Method GET // // Route /jobs/regions/:name/:from/:to // // Restrictions None // // Template base/regions.html func RegionsJobPaginate(ctx *echo.Context) error { name := ctx.Param("name") offset, err := utils.GetInt(ctx.Param("from")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } limit, err := utils.GetInt(ctx.Param("to")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } jobs, err := query.GetJobByRegionPaginate(name, offset, limit) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } utils.SetData(ctx, settings.JobsListKey, jobs) return ctx.Render(http.StatusOK, tmpl.BaseRegionsPaginateTpl, utils.GetData(ctx)) }
// View displays the resume. // // Method GET // // Route /resume/view // // Restrictions Yes // // Template resume/view.html func View(ctx *echo.Context) error { iid, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } resume, err := query.GetResumeByID(iid) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage) } utils.SetData(ctx, "resume", resume) return ctx.Render(http.StatusOK, tmpl.ResumeViewTpl, utils.GetData(ctx)) }
// JobView displays a single job by the given job id. // // // Method GET // // Route /jobs/view/:id // // Restrictions None // // Template base/jobs_view.html func JobView(ctx *echo.Context) error { id, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } job, err := query.GetJobByID(id) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx)) } if job != nil { utils.SetData(ctx, "Job", job) } return ctx.Render(http.StatusOK, tmpl.BaseJobsViewTpl, utils.GetData(ctx)) }
// Update renders the resume update page. // // Method GET // // Route /resume/update/:id // // Restrictions Yes // // Template None func Update(ctx *echo.Context) error { id, err := utils.GetInt(ctx.Param("id")) if err != nil { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } user := ctx.Get("User").(*models.Person) resume, err := query.GetResumeByID(id) if err != nil { utils.SetData(ctx, "Message", tmpl.NotFoundMessage) return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage) } // Users are allowed to update resumes that they own. if resume.PersonID != user.ID { utils.SetData(ctx, "Message", tmpl.BadRequestMessage) return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx)) } utils.SetData(ctx, "resume", resume) return ctx.Render(http.StatusOK, tmpl.ResumeUpddateTpl, utils.GetData(ctx)) }