func Checkout(eventRepository *repository.EventsRepository) 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."}) } var user entity.User if c.BindJSON(&user) == nil { if user.Email == "" { c.JSON(http.StatusBadRequest, gin.H{"devMessage": "User not contains a email."}) return } members := make([]entity.User, 0) for _, member := range event.Members { if strings.EqualFold(member.Email, user.Email) { continue } members = append(members, member) } event.Members = members c.JSON(http.StatusOK, eventRepository.Save(event)) } } }
func CreateEvent(eventRepository *repository.EventsRepository) func(c *gin.Context) { return func(c *gin.Context) { event := &entity.Event{} if c.BindJSON(&event) == nil { if event.Owner.Email == "" { c.JSON(http.StatusBadRequest, gin.H{"devMessage": "Event not contains a owner."}) return } c.JSON(http.StatusOK, eventRepository.Save(event)) } } }
func Checkin(eventRepository *repository.EventsRepository) 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."}) } var user entity.User if c.BindJSON(&user) == nil { if user.Email == "" { c.JSON(http.StatusBadRequest, gin.H{"devMessage": "User not contains a email."}) return } event.Members = append(event.Members, user) c.JSON(http.StatusOK, eventRepository.Save(event)) } } }