Esempio n. 1
0
func GetMembers(eventRepository *repository.EventsRepository, usersRepository *repository.UsersRepository) func(c *gin.Context) {
	return func(c *gin.Context) {
		event := eventRepository.Get(c.Param("id"))

		if event == nil {
			c.JSON(http.StatusNotFound, gin.H{"devMessage": "Event not found."})
			return
		}

		skill := c.Query("skill")

		if skill == "" {
			if event.Members == nil {
				c.JSON(http.StatusOK, make([]entity.User, 0))
				return
			}

			c.JSON(200, event.Members)
			return
		}

		emails := make([]string, 0)

		if event.Members == nil {
			c.JSON(http.StatusOK, make([]entity.User, 0))
			return
		}

		for _, member := range event.Members {
			emails = append(emails, member.Email)
		}

		fullMembers := usersRepository.GetAllByEmails(emails)

		members := make([]entity.User, 0)

		skills := strings.Split(skill, ",")

	user:
		for _, fullUser := range fullMembers {
			for _, userSkill := range fullUser.Skills {
				for _, querySkill := range skills {
					if strings.EqualFold(querySkill, userSkill) {
						members = append(members, fullUser)
						continue user
					}
				}
			}
		}

		c.JSON(http.StatusOK, members)
	}
}
Esempio n. 2
0
func UpdateUser(usersRepository *repository.UsersRepository) func(c *gin.Context) {
	return func(c *gin.Context) {
		user := &entity.User{}

		if c.BindJSON(&user) == nil {
			if user.Email == "" {
				c.JSON(http.StatusBadRequest, gin.H{"devMessage": "User not contains a email."})
				return
			}

			c.JSON(http.StatusOK, usersRepository.Save(user))
		}
	}
}
Esempio n. 3
0
func GetUser(usersRepository *repository.UsersRepository) func(c *gin.Context) {
	return func(c *gin.Context) {
		email := c.Param("email")

		log.Printf("Email: %s\n", email)

		if email == "" {
			c.JSON(http.StatusBadRequest, gin.H{"devMessage": "Email is required."})
			return
		}

		user := usersRepository.Get(email)

		if user == nil {
			c.JSON(http.StatusNotFound, gin.H{"devMessage": "User not found."})
		}

		c.JSON(200, user)
	}
}
Esempio n. 4
0
func GetUsers(usersRepository *repository.UsersRepository) func(c *gin.Context) {
	return func(c *gin.Context) {
		c.JSON(200, usersRepository.GetAll())
	}
}