edit: field Shortcode dan expire duration

This commit is contained in:
mario
2025-05-17 09:38:40 +07:00
parent ed3feb77d2
commit 3aa155dfbc
7 changed files with 56 additions and 19 deletions

View File

@@ -110,14 +110,16 @@ func (s *ShortLinkService) GenerateShortLink(req *models.GenerateShortLinkReques
s.logger.Info("Returning existing active shortlink",
zap.String("patientID", req.PatientID),
zap.String("studyUID", req.StudyUID),
zap.String("token", existingShortLink.Token))
zap.String("token", existingShortLink.Shortcode))
// Generate the full URL using the configured base URL
fullURL := fmt.Sprintf("%s/short-auth?short=%s", s.baseURL, existingShortLink.Token)
// Generate the full URL and URI
uri := fmt.Sprintf("short-auth?short=%s", existingShortLink.Shortcode)
fullURL := fmt.Sprintf("%s/%s", s.baseURL, uri)
return &models.GenerateShortLinkResponse{
ShortToken: existingShortLink.Token,
ShortToken: existingShortLink.Shortcode,
FullURL: fullURL,
URI: uri,
ExpiresAt: existingShortLink.ExpiresAt,
IsExisting: true,
}, nil
@@ -161,7 +163,7 @@ func (s *ShortLinkService) GenerateShortLink(req *models.GenerateShortLinkReques
// Create the short link record
shortLink := &models.ShortLink{
Token: *unusedShortcode,
Shortcode: *unusedShortcode,
PatientID: req.PatientID,
StudyUID: req.StudyUID,
HashedDOB: hashedDOB,
@@ -181,14 +183,14 @@ func (s *ShortLinkService) GenerateShortLink(req *models.GenerateShortLinkReques
// Get the ID of the created shortlink
var shortlinkID int
err = tx.Get(&shortlinkID, "SELECT ShortlinkID FROM shortlink WHERE ShortlinkCode = ?", shortLink.Token)
err = tx.Get(&shortlinkID, "SELECT ShortlinkID FROM shortlink WHERE ShortlinkCode = ?", shortLink.Shortcode)
if err != nil {
s.logger.Error("Failed to get shortlink ID", zap.Error(err))
return nil, ErrCreationFailed
}
// Mark the shortcode as used
err = s.shortCodeRepo.MarkShortCodeAsUsed(tx, shortLink.Token, shortlinkID)
err = s.shortCodeRepo.MarkShortCodeAsUsed(tx, shortLink.Shortcode, shortlinkID)
if err != nil {
s.logger.Error("Failed to mark shortcode as used", zap.Error(err))
return nil, ErrCreationFailed
@@ -203,12 +205,14 @@ func (s *ShortLinkService) GenerateShortLink(req *models.GenerateShortLinkReques
// Clear the tx to prevent the deferred rollback
tx = nil
// Generate the full URL using the configured base URL
fullURL := fmt.Sprintf("%s/short-auth?short=%s", s.baseURL, shortLink.Token)
// Generate the full URL and URI
uri := fmt.Sprintf("short-auth?short=%s", shortLink.Shortcode)
fullURL := fmt.Sprintf("%s/%s", s.baseURL, uri)
return &models.GenerateShortLinkResponse{
ShortToken: shortLink.Token,
ShortToken: shortLink.Shortcode,
FullURL: fullURL,
URI: uri,
ExpiresAt: shortLink.ExpiresAt,
IsExisting: false,
}, nil