func Login(c *gin.Context) { loginData := LoginData{} err := c.Bind(&loginData) if err != nil { c.JSON(http.StatusBadRequest, err) return } db := utils.GetDb(c) err, user := userdb.GetOne(db, bson.M{ "username": loginData.Username, }) err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(loginData.Password)) if err != nil { c.JSON(http.StatusUnauthorized, gin.H{ "success": false, "message": "The username or password don't match", }) return } token, err := CreateJwtToken(user.ID.Hex()) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, gin.H{ "success": true, "id_token": token, }) }
func sendMeta(name string, c *gin.Context) { db := utils.GetDb(c) err, res := getData(db, name) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, res) }
func GetList(c *gin.Context) { db := utils.GetDb(c) query := BuildQuery(c) err, subs := subdb.GetList(db, query) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, subs) }
func GetOne(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, sub := subdb.GetOne(db, id) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, sub) }
func GetList(c *gin.Context) { db := utils.GetDb(c) err, users := userdb.GetList(db, &bson.M{}) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, users) }
func Delete(c *gin.Context) { db := utils.GetDb(c) userID := utils.GetUserId(c) id := c.Params.ByName("id") err, interview := interviewdb.Delete(db, userID, id) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, interview) }
func GetList(c *gin.Context) { db := utils.GetDb(c) query := BuildQuery(c) err, companies := companydb.GetList(db, query) if err != nil { log.Error(err.Error()) c.JSON(http.StatusNotFound, companyNotFoundError) return } c.JSON(http.StatusOK, companies) }
func GetFeedback(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, feedback := interviewdb.GetFeedback(db, id) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, feedback) }
func Delete(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, user := userdb.Delete(db, id) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, user) }
func GetOne(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, company := companydb.GetOne(db, id) if err != nil { c.JSON(http.StatusNotFound, companyNotFoundError) return } c.JSON(http.StatusOK, company) }
func GetComments(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, comments := companydb.GetComments(db, id) if err != nil { c.JSON(http.StatusBadRequest, err) return } c.JSON(http.StatusOK, comments) }
func End(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err := interviewdb.End(db, id) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, gin.H{}) }
func DeleteComment(c *gin.Context) { db := utils.GetDb(c) companyId := c.Params.ByName("id") commentId := c.Params.ByName("commentId") err := companydb.DeleteComment(db, companyId, commentId) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, gin.H{}) }
func Delete(c *gin.Context) { db := utils.GetDb(c) userId := utils.GetUserId(c) id := c.Params.ByName("id") err, user := vacancydb.DeleteById(db, userId, id) if err != nil { log.Error(err.Error()) c.JSON(http.StatusNotFound, notFoundError) return } c.JSON(http.StatusOK, user) }
func Delete(c *gin.Context) { db := utils.GetDb(c) userId := utils.GetUserId(c) companyId := c.Params.ByName("id") err, company := companydb.Delete(db, userId, companyId) if err != nil { c.JSON(http.StatusNotFound, companyNotFoundError) return } c.JSON(http.StatusOK, company) }
func Create(c *gin.Context) { file, fileHeader, err := c.Request.FormFile("file") if err != nil { c.Error(err) return } _, h := parseVal("h", c) _, w := parseVal("w", c) _, x := parseVal("x", c) _, y := parseVal("y", c) img, _, err := image.Decode(file) if err != nil { c.Error(err) return } log.Debug("Crop w:%v h:%v x:%v y:%v", w, h, x, y) rect := convertToRectangle(int(w), int(h), int(x), int(y)) log.Debug("Rect", rect) croppedImg := imaging.Crop(img, rect) db := utils.GetDb(c) gridFile, err := db.GridFS("fs").Create(fileHeader.Filename) if err != nil { c.Error(err) return } buffer := new(bytes.Buffer) jpeg.Encode(buffer, croppedImg, nil) gridFile.SetName(fileHeader.Filename) gridFile.SetContentType(fileHeader.Header.Get("Content-Type")) _, err = io.Copy(gridFile, buffer) if err != nil { c.Error(err) return } file.Close() gridFile.Close() c.JSON(http.StatusOK, gin.H{"_id": gridFile.Id()}) }
func GetList(c *gin.Context) { db := utils.GetDb(c) err, query := BuildQuery(c) if err != nil { c.Error(err) return } log.Debug("interviews - GetList, query: ", query) err, interviews := interviewdb.GetList(db, query) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, interviews) }
func GetUserCompanies(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, companies := companydb.GetList(db, &bson.M{ "owner": bson.ObjectIdHex(id), }) if err != nil { c.JSON(http.StatusNotFound, userNotFoundError) return } c.JSON(http.StatusOK, companies) }
func Delete(c *gin.Context) { db := utils.GetDb(c) userId := utils.GetUserId(c) id := c.Params.ByName("id") err, sub := subdb.Delete(db, userId, id) if err != nil { log.Debug(err) c.Error(err) return } interviewdb.GetInterviewC(db).RemoveId(sub.Interview) c.JSON(http.StatusOK, sub) }
func GetVacancySubscriptions(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") query := map[string]interface{}{} query["vacancy"] = id //query["vacancy"] err, subs := subdb.GetList(db, query) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, subs) }
func Create(c *gin.Context) { err, interview := bindInterview(c) if err != nil { c.JSON(http.StatusBadRequest, notValidModel(err)) return } db := utils.GetDb(c) userId := utils.GetUserId(c) err = interviewdb.Create(db, userId, interview) if err != nil { c.Error(err) return } c.JSON(http.StatusCreated, interview) }
func GetOne(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") if id == "me" { id = utils.GetUserId(c) } log.Debug("Userid :%v", id) err, user := userdb.GetOneById(db, id) if err != nil { log.Error(err.Error()) c.JSON(http.StatusNotFound, userNotFoundError) return } c.JSON(http.StatusOK, user) }
func Create(c *gin.Context) { db := utils.GetDb(c) err, user := getUser(c) if err != nil { c.Error(err) return } err = userdb.Create(db, user) if err != nil { c.Error(err) return } c.JSON(http.StatusCreated, user) }
func AddComment(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") err, comment := bindComment(c) if err != nil { log.Error(err.Error()) c.JSON(http.StatusBadRequest, err) return } err = companydb.AddComment(db, id, comment) if err != nil { log.Error(err.Error()) c.JSON(http.StatusBadRequest, err) return } c.JSON(http.StatusCreated, gin.H{}) }
func Update(c *gin.Context) { updateModel := models.CompanyUpdateModel{} err := c.BindJSON(&updateModel) if err != nil { c.JSON(http.StatusBadRequest, notValidModel(err)) return } db := utils.GetDb(c) id := c.Params.ByName("id") userID := utils.GetUserId(c) err, updatedCompany := companydb.Update(db, userID, id, &updateModel) if err != nil { c.JSON(http.StatusNotFound, companyNotFoundError) return } c.JSON(http.StatusOK, updatedCompany) }
func Update(c *gin.Context) { updateModel := models.InterviewUpdateModel{} err := c.BindJSON(&updateModel) if err != nil { c.JSON(http.StatusBadRequest, notValidModel(err)) return } db := utils.GetDb(c) id := c.Params.ByName("id") userID := utils.GetUserId(c) err, updatedInterview := interviewdb.Update(db, userID, id, &updateModel) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, updatedInterview) }
func Create(c *gin.Context) { db := utils.GetDb(c) userId := utils.GetUserId(c) err, sub := getSub(c) if err != nil { log.Error("Binding error", err) c.Error(err) return } err = subdb.Create(db, userId, sub) if err != nil { c.Error(err) return } c.JSON(http.StatusCreated, sub) }
func Create(c *gin.Context) { log.Debug("companies.Create") err, company := bindCompany(c) log.Debug("companies.Create - bindCompany", err, company) if err != nil { c.JSON(http.StatusBadRequest, notValidModel(err)) return } db := utils.GetDb(c) userId := utils.GetUserId(c) err = companydb.Create(db, userId, company) log.Debugf("companies.Create - userId := %v", userId) if err != nil { c.JSON(http.StatusBadRequest, notValidModel(err)) return } c.JSON(http.StatusCreated, company) }
func CreateFeedback(c *gin.Context) { db := utils.GetDb(c) id := c.Params.ByName("id") feedback := models.Feedback{} err := c.BindJSON(&feedback) if err != nil { c.Error(err) return } err = interviewdb.CreateFeedback(db, id, &feedback) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, feedback) }
func Update(c *gin.Context) { id := c.Params.ByName("id") updateModel := models.VacancyUpdateModel{} err := c.BindJSON(&updateModel) if err != nil { c.Error(err) return } db := utils.GetDb(c) userId := utils.GetUserId(c) err, updatedVacancy := vacancydb.Update(db, userId, id, &updateModel) if err != nil { c.Error(err) return } c.JSON(http.StatusOK, updatedVacancy) }