Skip to content

Commit 515bbe1

Browse files
committed
Many things
Passing flags replaces the configured values in config Grammar fixes Can replace wish values with nothing Removed option to migrate to V2
1 parent b3098a5 commit 515bbe1

File tree

10 files changed

+188
-187
lines changed

10 files changed

+188
-187
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cSpell.words": [
33
"poenskelisten",
4+
"Pønskelisten",
45
"xhttp"
56
]
67
}

Dockerfile

+1-15
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@ FROM debian:bullseye-slim as runtime
1313

1414
LABEL org.opencontainers.image.source=https://github.com/aunefyren/poenskelisten
1515

16-
ENV port=8080
17-
ENV timezone=Europe/Oslo
18-
ENV dbip=localhost
19-
ENV dbport=3306
20-
ENV dbname=poenskelisten
21-
ENV dbusername=root
22-
ENV dbpassword=root
23-
ENV generateinvite=false
24-
ENV disablesmtp=false
25-
ENV smtphost=smtp.gmail.com
26-
ENV smtpport=25
27-
ENV smtpusername=mycoolusernameformysmtpserver@justanexample.org
28-
ENV smtppassword=password123
29-
3016
WORKDIR /app
3117

3218
COPY --from=builder /app .
3319

3420
RUN apt update
3521
RUN apt install -y curl
3622

37-
ENTRYPOINT /app/poenskelisten -port ${port} -timezone ${timezone} -generateinvite ${generateinvite} -dbip ${dbip} -dbport ${dbport} -dbname ${dbname} -dbusername ${dbusername} -dbpassword ${dbpassword} -disablesmtp ${disablesmtp} -smtphost ${smtphost} -smtpport ${smtpport} -smtpusername ${smtpusername} -smtppassword ${smtppassword}
23+
ENTRYPOINT /app/entrypoint.sh

controllers/invite.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func RegisterInvite(context *gin.Context) {
1616

17-
invite, err := database.GenrateRandomInvite()
17+
invite, err := database.GenerateRandomInvite()
1818
if err != nil {
1919
log.Println("Failed to create new invite. Error: " + err.Error())
2020
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create new invite."})

controllers/user.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func SendUserVerificationCode(context *gin.Context) {
450450
}
451451

452452
// Create a new code
453-
_, err = database.GenrateRandomVerificationCodeForuser(userID)
453+
_, err = database.GenerateRandomVerificationCodeForUser(userID)
454454
if err != nil {
455455
log.Println("Failed to generate verification code. Error: " + err.Error())
456456
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to generate verification code."})
@@ -640,7 +640,7 @@ func UpdateUser(context *gin.Context) {
640640
// If user is not verified and SMTP is enabled, send verification e-mail
641641
if config.SMTPEnabled && !*user.Verified {
642642

643-
verificationCode, err := database.GenrateRandomVerificationCodeForuser(userID)
643+
verificationCode, err := database.GenerateRandomVerificationCodeForUser(userID)
644644
if err != nil {
645645
log.Println("Failed to generate verification code. Error: " + err.Error())
646646
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to generate verification code."})

controllers/wish.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func RegisterWish(context *gin.Context) {
353353
}
354354

355355
// Verify unique wish name in wishlist
356-
unique_wish_name, err := database.VerifyUniqueWishNameinWishlist(wish.Name, wishlist_id_int)
356+
unique_wish_name, err := database.VerifyUniqueWishNameInWishlist(wish.Name, wishlist_id_int)
357357
if err != nil {
358358
log.Println("Failed to verify unique wishlist name. Error: " + err.Error())
359359
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to verify unique wishlist name."})
@@ -974,7 +974,7 @@ func APIUpdateWish(context *gin.Context) {
974974
return
975975
}
976976

977-
unique_wish_name, err := database.VerifyUniqueWishNameinWishlist(wish.Name, wishOriginal.WishlistID)
977+
unique_wish_name, err := database.VerifyUniqueWishNameInWishlist(wish.Name, wishOriginal.WishlistID)
978978
if err != nil {
979979
log.Println("Failed to verify wish name. Error: " + err.Error())
980980
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to verify wish name."})
@@ -989,7 +989,7 @@ func APIUpdateWish(context *gin.Context) {
989989
wishOriginal.Name = strings.TrimSpace(wish.Name)
990990
}
991991

992-
if wish.URL != wishOriginal.URL && wish.URL != "" {
992+
if wish.URL != wishOriginal.URL {
993993
// Validate wish URL format
994994
stringMatch, requirements, err := utilities.ValidateTextCharacters(wish.URL)
995995
if err != nil {
@@ -1014,8 +1014,7 @@ func APIUpdateWish(context *gin.Context) {
10141014
wishOriginal.URL = strings.TrimSpace(wish.URL)
10151015
}
10161016

1017-
if wish.Note != wishOriginal.Note && wish.Note != "" {
1018-
1017+
if wish.Note != wishOriginal.Note {
10191018
// Validate wish note format
10201019
stringMatch, requirements, err := utilities.ValidateTextCharacters(wish.Note)
10211020
if err != nil {
@@ -1033,7 +1032,7 @@ func APIUpdateWish(context *gin.Context) {
10331032
wishOriginal.Note = strings.TrimSpace(wish.Note)
10341033
}
10351034

1036-
if wish.Price != wishOriginal.Price && wish.Price != 0 {
1035+
if wish.Price != wishOriginal.Price {
10371036
wishOriginal.Price = wish.Price
10381037
}
10391038

database/client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func Migrate() {
110110
log.Println("Database Migration Completed!")
111111
}
112112

113-
// Genrate a random invite code an return ut
114-
func GenrateRandomInvite() (string, error) {
113+
// Generate a random invite code an return ut
114+
func GenerateRandomInvite() (string, error) {
115115
var invite models.Invite
116116

117117
randomString := randstr.String(16)
@@ -126,8 +126,8 @@ func GenrateRandomInvite() (string, error) {
126126
return invite.Code, nil
127127
}
128128

129-
// Genrate a random verification code an return ut
130-
func GenrateRandomVerificationCodeForuser(userID uuid.UUID) (string, error) {
129+
// Generate a random verification code an return ut
130+
func GenerateRandomVerificationCodeForUser(userID uuid.UUID) (string, error) {
131131

132132
randomString := randstr.String(8)
133133
verificationCode := strings.ToUpper(randomString)
@@ -159,7 +159,7 @@ func VerifyUniqueUserEmail(providedEmail string) (bool, error) {
159159
}
160160

161161
// Verify if user has a verification code set
162-
func VerifyUserHasVerfificationCode(userID uuid.UUID) (bool, error) {
162+
func VerifyUserHasVerificationCode(userID uuid.UUID) (bool, error) {
163163
var user models.User
164164
userrecords := Instance.Where("enabled = ?", true).Where("ID = ?", userID).Find(&user)
165165
if userrecords.Error != nil {

database/wishlist.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func GetWishlist(WishlistID uuid.UUID) (models.Wishlist, error) {
193193
}
194194

195195
// Verify if a wish name in wishlist is unique
196-
func VerifyUniqueWishNameinWishlist(WishName string, WishlistID uuid.UUID) (bool, error) {
196+
func VerifyUniqueWishNameInWishlist(WishName string, WishlistID uuid.UUID) (bool, error) {
197197
var wish models.Wish
198198
wishesrecord := Instance.Where("`wishes`.enabled = ?", 1).Where("`wishes`.wishlist_id = ?", WishlistID).Where("`wishes`.name = ?", WishName).Find(&wish)
199199
if wishesrecord.Error != nil {

entrypoint.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
3+
# Initialize the command with the binary
4+
CMD="/app/poenskelisten"
5+
6+
# Add the --port flag if the PORT environment variable is set
7+
if [ -n "$port" ]; then
8+
CMD="$CMD --port $port"
9+
fi
10+
11+
# Add the --timezone flag if the TIMEZONE environment variable is set
12+
if [ -n "$timezone" ]; then
13+
CMD="$CMD --timezone $timezone"
14+
fi
15+
16+
# Add database-related flags if the corresponding environment variables are set
17+
if [ -n "$dbip" ]; then
18+
CMD="$CMD --dbip $dbip"
19+
fi
20+
21+
if [ -n "$dbport" ]; then
22+
CMD="$CMD --dbport $dbport"
23+
fi
24+
25+
if [ -n "$dbname" ]; then
26+
CMD="$CMD --dbname $dbname"
27+
fi
28+
29+
if [ -n "$dbusername" ]; then
30+
CMD="$CMD --dbusername $dbusername"
31+
fi
32+
33+
if [ -n "$dbpassword" ]; then
34+
CMD="$CMD --dbpassword $dbpassword"
35+
fi
36+
37+
# Add flags for invite generation and SMTP settings if those environment variables are set
38+
if [ -n "$generateinvite" ]; then
39+
CMD="$CMD --generateinvite $generateinvite"
40+
fi
41+
42+
if [ -n "$disablesmtp" ]; then
43+
CMD="$CMD --disablesmtp $disablesmtp"
44+
fi
45+
46+
if [ -n "$smtphost" ]; then
47+
CMD="$CMD --smtphost $smtphost"
48+
fi
49+
50+
if [ -n "$smtpport" ]; then
51+
CMD="$CMD --smtpport $smtpport"
52+
fi
53+
54+
if [ -n "$smtpusername" ]; then
55+
CMD="$CMD --smtpusername $smtpusername"
56+
fi
57+
58+
if [ -n "$smtppassword" ]; then
59+
CMD="$CMD --smtppassword $smtppassword"
60+
fi
61+
62+
# Execute the final command
63+
exec $CMD

0 commit comments

Comments
 (0)