-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* vinvoor: init * zess: development docker * vingo: customizable redirect * zess: add -c option * vinvoor: add login * vingo: add cors * vingo: add json serialization * vinvoor: add login and logout * vinvoor: add a cards page * zess: add development instructions * vinvoor: add a theme * vinvoor: refactor * vinvoor: add support for dark and light mode * vinvoor: move url's to .env * zess: start vinvoor as non root user * vinvoor: add a cards overview * vingo: more serialization * vinvoor: refactor the cards page * vinvoor: change to camelCase * vinvoor: add a leaderboard * vinvoor: add a welcome page * zess: change env var to export in dev script * vingo: add database migrations * vingo: fix api returning null when no results * vingo: add card register via api * vingo: add card id and name * vinvoor: add a github activity style overview * vinvoor: support adding new cards * vinvoor: show current checkin status * vinvoor: show current streak days * vinvoor: show the user's most common days * vinvoor: simple overview page * vinvoor: fix crash when no scans are registered * vinvoor: center graphs in the overview * vinvoor: add support for new comers * vingo: move to gorm * vingo: go get -u && go mod tidy * vingo: card register status endpoint * vingo: ability to add name to card * vingo: return if last register was success * vingo: return extra stats for cards * vingo: time remaining on card status endpoint * vinvoor: support new card features * vingo: add leaderboard position change * vingo: pieter post pieter post pieter post verdient de kost (met zijn post) * vinvoor: pieter post deed ambetant * vinvoor: show position changes in the leaderboard * vinvoor: show a scan overview * vingo: fix scans * vingo: card handlers to receivers * vingo: settings endpoint * vingo: cleanup * vinvoor: add a new zess logo --------- Co-authored-by: Topvennie <[email protected]>
- Loading branch information
1 parent
2edb53a
commit c697694
Showing
72 changed files
with
2,750 additions
and
1,447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,35 @@ | ||
package database | ||
|
||
import "time" | ||
|
||
type Card struct { | ||
Serial string `json:"serial"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
} | ||
|
||
var ( | ||
cardsCreateStmt = ` | ||
CREATE TABLE IF NOT EXISTS cards ( | ||
serial TEXT NOT NULL PRIMARY KEY UNIQUE, | ||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
user_id INTEGER NOT NULL REFERENCES users(id) | ||
); | ||
` | ||
) | ||
|
||
func CreateCard(serial string, user_id int) error { | ||
_, err := db.Exec("INSERT INTO cards (serial, user_id) VALUES ($1, $2);", serial, user_id) | ||
return err | ||
return gorm_db.Create(&Card{Serial: serial, UserId: user_id}).Error | ||
} | ||
|
||
func GetCardsForUser(user_id int) ([]Card, error) { | ||
rows, err := db.Query("SELECT serial, created_at FROM cards WHERE user_id = $1;", user_id) | ||
var cards []Card | ||
result := gorm_db.Where("user_id = ?", user_id).Find(&cards) | ||
return cards, result.Error | ||
} | ||
|
||
func GetCardsAndStatsForUser(user_id int) ([]CardAPI, error) { | ||
rows, err := db.Query(` | ||
SELECT cards.id, cards.created_at, serial, name, COUNT(scans.id), (select MAX(scan_time) from scans where card_serial = cards.serial) from cards LEFT JOIN scans on scans.card_serial = serial WHERE | ||
user_id = $1 GROUP BY cards.id; | ||
`, user_id) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
defer rows.Close() | ||
|
||
cards := make([]Card, 0) | ||
cards := []CardAPI{} | ||
for rows.Next() { | ||
var card Card | ||
err := rows.Scan(&card.Serial, &card.CreatedAt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cards = append(cards, card) | ||
var item CardAPI | ||
_ = rows.Scan(&item.Id, &item.CreatedAt, &item.Serial, &item.Name, &item.AmountUsed, &item.LastUsed) | ||
cards = append(cards, item) | ||
} | ||
|
||
return cards, nil | ||
} | ||
|
||
func UpdateCardName(id int, name string, user_id int) error { | ||
return gorm_db.Model(&Card{}).Where("id = ? AND user_id = ?", id, user_id).Update("name", name).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package database | ||
|
||
import ( | ||
"time" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
type BaseModel struct { | ||
Id int `json:"id" gorm:"primarykey"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
UpdatedAt time.Time `json:"updatedAt"` | ||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` | ||
} | ||
|
||
type User struct { | ||
BaseModel | ||
Username string `json:"username"` | ||
Admin bool `json:"admin"` | ||
SettingsId int | ||
Settings Settings `json:"settings"` | ||
Cards []Card `json:"-" gorm:"foreignKey:UserId;references:Id"` | ||
} | ||
|
||
type Settings struct { | ||
BaseModel | ||
ScanInOut bool `json:"scanInOut"` | ||
Leaderboard bool `json:"leaderboard"` | ||
Public bool `json:"public"` | ||
} | ||
|
||
type Card struct { | ||
BaseModel | ||
Serial string `gorm:"uniqueIndex"` | ||
Name string | ||
UserId int | ||
User User | ||
Scans []Scan `gorm:"foreignKey:CardSerial;references:Serial"` | ||
} | ||
|
||
func Card_to_API(card Card) CardAPI { | ||
var lastUsed time.Time = card.CreatedAt | ||
if len(card.Scans) != 0 { | ||
lastUsed = card.Scans[len(card.Scans)-1].ScanTime | ||
} | ||
|
||
return CardAPI{ | ||
Id: card.Id, | ||
Serial: card.Serial, | ||
Name: card.Name, | ||
LastUsed: lastUsed, | ||
AmountUsed: len(card.Scans), | ||
} | ||
} | ||
|
||
type CardAPI struct { | ||
Id int `json:"id"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
Serial string `json:"serial"` | ||
Name string `json:"name"` | ||
LastUsed time.Time `json:"lastUsed"` | ||
AmountUsed int `json:"amountUsed"` | ||
} | ||
|
||
type Scan struct { | ||
BaseModel | ||
ScanTime time.Time `json:"scanTime"` | ||
CardSerial string `json:"cardSerial" gorm:"index"` | ||
Card Card `json:"-" gorm:"foreignKey:CardSerial;references:Serial"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.