This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type User struct { | |
| ID int64 | |
| IsFamous bool | |
| tweetFactory TweetFactory | |
| } | |
| func (u *User) CreateTweet(content string) (Tweet, error) { | |
| tweet := u.tweetFactory.NewTweet(*u, content) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type TweetFactory struct { | |
| lazyRepository func() TweetRepository | |
| } | |
| func (t *TweetFactory) NewTweet(user User, content string) *Tweet { | |
| charactersLimit := 140 | |
| if user.IsFamous { | |
| charactersLimit = 280 | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | func NewTweet(user User, content string, repository TweetRepository) *Tweet { | |
| return &Tweet{Content: content, User: user, repository: repository} | |
| } | |
| func (u *User) CreateTweet(content string) (Tweet, error) { | |
| charactersLimit := 140 | |
| if u.IsFamous { | |
| charactersLimit = 280 | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | func (u *UserService) CreateTweet(user model.User, content string) error { | |
| tweet, err := user.CreateTweet(content) | |
| if err != nil { | |
| u.logger.Error("could not create tweet", err) | |
| return err | |
| } | |
| u.logger.Debug("tweet created") | |
| u.eventPublisher.PublishTweet("TWEET_CREATED", tweet) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package model | |
| import "fmt" | |
| type User struct { | |
| ID int64 | |
| IsFamous bool | |
| tweetRepository TweetRepository | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | func (u *UserService) CreateTweet(user User, tweet string) error { | |
| charactersLimit := 140 | |
| if user.IsFamous { | |
| charactersLimit := 280 | |
| } | |
| if len(tweet) > charactersLimit { | |
| err := fmt.Errorf( | |
| "max characters exceeded. Received: %d. Max: %d", | |
| len(tweet), charactersLimit, | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | func (u *UserService) CreateTweet(user User, tweet string) error { | |
| charactersLimit := 140 | |
| if user.IsFamous { | |
| charactersLimit := 280 | |
| } | |
| if len(tweet) > charactersLimit { | |
| return fmt.Errorf( | |
| "max characters exceeded. Received: %d. Max: %d", | |
| len(tweet), charactersLimit, | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "log" | |
| "os" | |
| "github.com/davecgh/go-spew/spew" | |
| "github.com/joho/godotenv" | |
| "github.com/streadway/amqp" | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "os" | |
| "github.com/joho/godotenv" | |
| "github.com/streadway/amqp" | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "context" | |
| "encoding/json" | |
| "log" | |
| "net/http" | |
| "time" | |
| "github.com/google/uuid" | 
NewerOlder