add: register and login with DB query AND some struct type correction

This commit is contained in:
mario
2025-05-15 09:46:32 +07:00
parent dd4451c2a8
commit c13f834b92
16 changed files with 465 additions and 25 deletions

View File

@@ -13,7 +13,7 @@ import (
// DBShortLink represents a shortlink from the database
type DBShortLink struct {
ShortlinkID int `db:"ShortlinkID"`
ShortlinKCode string `db:"ShortlinKCode"`
ShortlinkCode string `db:"ShortlinkCode"`
Shortlink_PatientID string `db:"Shortlink_PatientID"`
Shortlink_Study_IUID string `db:"Shortlink_Study_IUID"`
ShortlinkHashDoB string `db:"ShortlinkHashDoB"`
@@ -40,7 +40,7 @@ func NewShortLinkRepository() *ShortLinkRepository {
func (s *DBShortLink) ToShortLink() *models.ShortLink {
return &models.ShortLink{
ID: fmt.Sprintf("%d", s.ShortlinkID),
Token: s.ShortlinKCode,
Token: s.ShortlinkCode,
PatientID: s.Shortlink_PatientID,
StudyUID: s.Shortlink_Study_IUID,
HashedDOB: s.ShortlinkHashDoB,
@@ -56,7 +56,7 @@ func (s *DBShortLink) ToShortLink() *models.ShortLink {
func (r *ShortLinkRepository) GetShortLinkByToken(token string) (*models.ShortLink, error) {
var dbShortLink DBShortLink
query := `SELECT * FROM shortlink WHERE ShortlinKCode = ?`
query := `SELECT * FROM shortlink WHERE ShortlinkCode = ?`
err := database.DB.Get(&dbShortLink, query, token)
if err != nil {
@@ -72,7 +72,7 @@ func (r *ShortLinkRepository) GetShortLinkByToken(token string) (*models.ShortLi
// CreateShortLink stores a new shortlink in the database
func (r *ShortLinkRepository) CreateShortLink(shortLink *models.ShortLink) error {
query := `INSERT INTO shortlink (
ShortlinKCode,
ShortlinkCode,
Shortlink_PatientID,
Shortlink_Study_IUID,
ShortlinkHashDoB,
@@ -118,7 +118,7 @@ func (r *ShortLinkRepository) UpdateShortLink(shortLink *models.ShortLink) error
ShortlinkIsRevoked = ?,
ShortlinkRemainingTries = ?,
ShortlinkExpiredAt = ?
WHERE ShortlinKCode = ?`
WHERE ShortlinkCode = ?`
expiresAt, err := time.Parse(time.RFC3339, shortLink.ExpiresAt)
if err != nil {