Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds seedability to schools, post categoeries, report types, and feedback types #158

Merged
merged 9 commits into from
Aug 28, 2023
Binary file modified .DS_Store
Binary file not shown.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,19 @@ docker exec -it confesi-db psql -U postgres confesi
./scripts/database dbml

# seed data (use the POSTGRES_DSN found in `/scripts/test` not `.env`)
export POSTGRES_DSN="" # TODO: make a new bash env scripts that exports all of this
export MASK_SECRET="" # taken from .env
go run ./scripts/main.go --seed-schools
```
export POSTGRES_DSN=""
export MASK_SECRET="" # Found in `.env`

go run ./scripts/main.go --seed-all # Seed every seedable table

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Code

go run ./scripts/main.go --seed-schools # Seed schools
go run ./scripts/main.go --seed-feedback-types # Seed feedback types
go run ./scripts/main.go --seed-report-types # Seed report types
go run ./scripts/main.go --seed-post-categories # Seed post categories
go run ./scripts/main.go --seed-faculties # Seed faculties
go run ./scripts/main.go --seed-years-of-study # Seed years of study

```

## Redis cache

Expand Down
8 changes: 4 additions & 4 deletions config/builders/fcm_msg_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ func VoteOnPostNoti(vote int, totalVotes int) *messaging.Notification {
func YourSchoolsDailyHottestNoti(occurences int) *messaging.Notification {
if occurences == 1 {
return &messaging.Notification{
Title: "Your school hit the Daily Hottest!",
Body: fmt.Sprintf("Check it out in app!"),
Title: "Daily Hottest",
Body: fmt.Sprintf("🔥 Your school reached the Daily Hottest page today"),
}
}

return &messaging.Notification{
Title: "Your school hit the Daily Hottest!",
Body: fmt.Sprintf("%d times", occurences),
Title: "Daily Hottest",
Body: fmt.Sprintf("🔥 Your school reached the Daily Hottest page %d times today", occurences),
}
}

Expand Down
16 changes: 13 additions & 3 deletions config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,27 @@ const (
DefaultRange = 50000 // default distance to include schools in, in meters
HottestPostNotificationsLowerBound = "00:00" // the lower bound of the hottest post notifications cron job - 24h time
HottestPostNotificationsUpperBound = "23:59" // the upper bound of the hottest post notifications cron job - 24h time
TitleMaxLength = 100 // max length of a post title
BodyMaxLength = 1000 // max length of a post content/body
)

// ----- DEPLOYMENT CONSTANTS

const (
iOSBundleId = "com.confesi.app" // iOS bundle id // TODO: change this
AndroidPackageName = "com.confesi.app" // Android package name // TODO: change this
FirebaseProjectID = "confesi-server-dev" // Firebase project id // TODO: change this
iOSBundleId = "com.confesi.app"
AndroidPackageName = "com.confesi.app"
FirebaseProjectID = "confesi-server-dev" // Firebase project id
Development = true // development mode
)

// ---- AWS CONSTANTS

const (
AwsUserUploadsBucket string = "confesi-uploads"
AwsRekognitionConfidenceThreshold float64 = 80
AwsUserUploadsBucketBaseUrl string = "https://confesi-uploads.s3.us-east-2.amazonaws.com/"
)

// ----- ALT CONSTANTS

// -> pther constants are defined directly in the request struct validation tags, here: ~/lib/validation/models.go
44 changes: 44 additions & 0 deletions db/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql/driver"
"encoding/json"
"fmt"
"strings"

"time"

Expand All @@ -13,6 +14,48 @@ import (
"gorm.io/datatypes"
)

type PgTxtArr []string

func (a *PgTxtArr) Scan(src interface{}) error {
var str string
switch v := src.(type) {
case []byte:
str = string(v)
case string:
str = v
default:
return fmt.Errorf("unable to scan PgTxtArr: unexpected type: %T", src)
}

// Trimming the surrounding curly braces of PostgreSQL arrays
str = strings.Trim(str, "{}")

// If the trimmed string is empty, it means the array was empty.
if str == "" {
*a = []string{}
return nil
}

// Splitting by comma, but be careful about commas inside the URLs
pieces := strings.Split(str, ",")

// Check and handle quoted strings
var cleanPieces []string
for _, piece := range pieces {
if strings.HasPrefix(piece, `"`) && strings.HasSuffix(piece, `"`) {
piece = strings.Trim(piece, `"`)
}
cleanPieces = append(cleanPieces, piece)
}

*a = cleanPieces
return nil
}

func (a PgTxtArr) Value() (driver.Value, error) {
return "{" + strings.Join(a, ",") + "}", nil
}

type EncryptedID struct {
Val uint
}
Expand Down Expand Up @@ -179,6 +222,7 @@ type Post struct {
CategoryID EncryptedID `gorm:"column:category_id" json:"-"`
Category PostCategory `gorm:"foreignKey:CategoryID" json:"category"`
CommentCount uint `gorm:"column:comment_count" json:"comment_count"`
ImgUrls PgTxtArr `gorm:"column:img_urls" json:"img_urls"`
}

// ! Very important that SOME FIELDS ARE NOT EVER SERIALIZED TO PROTECT SENSATIVE DATA (json:"-")
Expand Down
4 changes: 0 additions & 4 deletions env-example
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ HKDF_SECRET="some-secret-string"
# a 16-byte key
MASK_SECRET="your_16_byte_key"

# to generate a new nonce for production:
# go run ./scripts/main.go --new-nonce
CIPHER_NONCE="47363bcf91a1545668f0fd7a"

# Redis connection string
REDIS_CONN="redis:6379"

Expand Down
Loading