Example #1
0
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,
	})
}
Example #2
0
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)
}
Example #3
0
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)
}
Example #4
0
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)
}
Example #5
0
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)
}
Example #6
0
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)
}
Example #7
0
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)
}
Example #8
0
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)
}
Example #9
0
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)
}
Example #10
0
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)
}
Example #11
0
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)
}
Example #12
0
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{})
}
Example #13
0
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{})
}
Example #14
0
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)
}
Example #15
0
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)
}
Example #16
0
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()})
}
Example #17
0
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)
}
Example #18
0
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)
}
Example #19
0
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)
}
Example #20
0
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)
}
Example #21
0
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)
}
Example #22
0
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)
}
Example #23
0
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)
}
Example #24
0
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{})
}
Example #25
0
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)
}
Example #26
0
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)
}
Example #27
0
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)
}
Example #28
0
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)
}
Example #29
0
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)
}
Example #30
0
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)
}