Skip to content

Commit

Permalink
fix (short) : using absolute url links instead unique code only & upd…
Browse files Browse the repository at this point in the history
…ate responses when create short url
  • Loading branch information
PickHD committed Jun 9, 2023
1 parent 362a9cc commit 9fc5e51
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion user/cmd/v1/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ MINIO_ACCESSKEY=singkatin
MINIO_SECRETKEY=singkatin@dev
MINIO_BUCKET=public
MINIO_USE_SSL=true
MINIO_LOCATION=us-east-1
MINIO_LOCATION=us-east-1

SHORTENER_BASE_API_URL=http://localhost:8081/v1
22 changes: 15 additions & 7 deletions user/internal/v1/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import "github.com/PickHD/singkatin-revamp/user/internal/v1/helper"

type (
Configuration struct {
Server *Server
Common *Common
Database *Database
RabbitMQ *RabbitMQ
Secret *Secret
Tracer *Tracer
MinIO *MinIO
Server *Server
Common *Common
Database *Database
RabbitMQ *RabbitMQ
Secret *Secret
Tracer *Tracer
MinIO *MinIO
HttpService *HttpService
}

Common struct {
Expand Down Expand Up @@ -58,6 +59,10 @@ type (
UseSSL bool
Location string
}

HttpService struct {
ShortenerBaseAPIURL string
}
)

func loadConfiguration() *Configuration {
Expand Down Expand Up @@ -101,6 +106,9 @@ func loadConfiguration() *Configuration {
UseSSL: helper.GetEnvBool("MINIO_USE_SSL"),
Location: helper.GetEnvString("MINIO_LOCATION"),
},
HttpService: &HttpService{
ShortenerBaseAPIURL: helper.GetEnvString("SHORTENER_BASE_API_URL"),
},
}
}

Expand Down
1 change: 1 addition & 0 deletions user/internal/v1/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type (
// ShortUserResponse consist response data when success generate/update short users
ShortUserResponse struct {
ShortURL string `json:"short_url"`
Method string `json:"method"`
}

// GenerateShortUserMessage consist message short users to publish
Expand Down
3 changes: 2 additions & 1 deletion user/internal/v1/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (us *UserServiceImpl) GenerateUserShorts(userID string, req *model.ShortUse
msg := model.GenerateShortUserMessage{
FullURL: req.FullURL,
UserID: userID,
ShortURL: helper.RandomStringBytesMaskImprSrcSB(8),
ShortURL: fmt.Sprintf("%s/%s", us.Config.HttpService.ShortenerBaseAPIURL, helper.RandomStringBytesMaskImprSrcSB(8)),
}

err := us.UserRepo.PublishCreateUserShortener(us.Context, &msg)
Expand All @@ -108,6 +108,7 @@ func (us *UserServiceImpl) GenerateUserShorts(userID string, req *model.ShortUse

return &model.ShortUserResponse{
ShortURL: msg.ShortURL,
Method: "GET",
}, nil
}

Expand Down

0 comments on commit 9fc5e51

Please sign in to comment.