Exemplo n.º 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,
	})
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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{})
}
Exemplo n.º 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{})
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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()})
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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{})
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}