From d897f7f5f2dd6c08509a9bbe179d29f5c1244b20 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 22:35:43 +0800 Subject: [PATCH 01/68] style: format --- internal/controllers/users/register.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/controllers/users/register.go b/internal/controllers/users/register.go index 664c22e..d71d818 100644 --- a/internal/controllers/users/register.go +++ b/internal/controllers/users/register.go @@ -5,6 +5,7 @@ import ( "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" "coursebench-backend/pkg/queries" + "github.com/gofiber/fiber/v2" ) From f99f27aec0840d5a13f7840e042c751d89fdfdb7 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 22:36:26 +0800 Subject: [PATCH 02/68] feat(controllers/users.RegisterRequest): accept invitation code --- internal/controllers/users/register.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/controllers/users/register.go b/internal/controllers/users/register.go index d71d818..e1fe7f5 100644 --- a/internal/controllers/users/register.go +++ b/internal/controllers/users/register.go @@ -10,12 +10,13 @@ import ( ) type RegisterRequest struct { - Email string `json:"email"` - Password string `json:"password"` - Year int `json:"year"` - Grade models.GradeType `json:"grade"` - Captcha string `json:"captcha"` - Nickname string `json:"nickname"` + Email string `json:"email"` + Password string `json:"password"` + Year int `json:"year"` + Grade models.GradeType `json:"grade"` + Captcha string `json:"captcha"` + Nickname string `json:"nickname"` + InvitationCode string `json:"invitation_code"` } func Register(c *fiber.Ctx) (err error) { From d18bbeb2f26bb2f3ee27c5ef0a349dfb753ec6b2 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 22:38:46 +0800 Subject: [PATCH 03/68] style: format --- pkg/queries/user.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 1a32e35..084a1f3 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -7,12 +7,13 @@ import ( "coursebench-backend/pkg/mail" "coursebench-backend/pkg/models" "fmt" - "github.com/badoux/checkmail" - "golang.org/x/crypto/bcrypt" - "gorm.io/gorm" "strings" "time" "unicode" + + "github.com/badoux/checkmail" + "golang.org/x/crypto/bcrypt" + "gorm.io/gorm" ) func ResetPassword(db *gorm.DB, email string) error { From 553a09d6e265c5a162017c9e90bce07ed191caad Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 22:42:39 +0800 Subject: [PATCH 04/68] feat(queries.Register): accept invitation code --- pkg/queries/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 084a1f3..40ba4a1 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -72,7 +72,7 @@ func ResetPasswordActive(db *gorm.DB, id uint, code string, password string) (er return nil } -func Register(db *gorm.DB, u *models.User) error { +func Register(db *gorm.DB, u *models.User, invitation_code string) error { if db == nil { db = database.GetDB() } From f1ce55fe43a69be893993cedcde58bcfa4c214c0 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 22:44:49 +0800 Subject: [PATCH 05/68] feat(controllers/users.Register): use invitation code --- internal/controllers/users/register.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controllers/users/register.go b/internal/controllers/users/register.go index e1fe7f5..f0bc152 100644 --- a/internal/controllers/users/register.go +++ b/internal/controllers/users/register.go @@ -40,7 +40,7 @@ func Register(c *fiber.Ctx) (err error) { Avatar: "", IsAnonymous: false, } - if err = queries.Register(nil, &user); err != nil { + if err = queries.Register(nil, &user, userReq.InvitationCode); err != nil { return } if config.GlobalConf.DisableMail { From 5666805cc1dfe7119f8ceea19d51ca6749150c14 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 22:51:02 +0800 Subject: [PATCH 06/68] feat(queries.Register): check invitation code format --- pkg/queries/user.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 40ba4a1..e7b3779 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -96,6 +96,9 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { if !CheckRealName(u.RealName) { return errors.New(errors.InvalidArgument) } + if !CheckInvitationCode(invitation_code) { + return errors.New(errors.InvalidArgument) + } // 检查邮箱是否已存在 user := &models.User{} @@ -375,3 +378,18 @@ func CheckRealName(realname string) bool { } return true } + +func CheckInvitationCode(code string) bool { + if len(code) == 0 { + return true + } + if len(code) != 5 { + return false + } + for _, c := range code { + if (c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') { + return false + } + } + return true +} From f9b7e81d3757a076214672630fae3bcc939d06ea Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:00:08 +0800 Subject: [PATCH 07/68] style: format --- pkg/models/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/models/user.go b/pkg/models/user.go index 79a3b2c..b77842f 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -2,6 +2,7 @@ package models import ( "coursebench-backend/pkg/modelRegister" + "gorm.io/gorm" ) From 4ef88f4a355748c9762972fe6780a0b4256f5a48 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:01:48 +0800 Subject: [PATCH 08/68] feat(models.User): add InvitationCode field --- pkg/models/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/models/user.go b/pkg/models/user.go index b77842f..26c72ee 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -28,6 +28,7 @@ type User struct { IsAnonymous bool IsAdmin bool `gorm:"default:false"` IsCommunityAdmin bool `gorm:"default:false"` + InvitationCode string } func init() { From 4b6cafc863d69c0fc63257523ba410706919005f Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:02:57 +0800 Subject: [PATCH 09/68] feat(errors): add InvitationCodeInvalid error --- pkg/errors/description.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/errors/description.go b/pkg/errors/description.go index 4df8371..71c6a64 100644 --- a/pkg/errors/description.go +++ b/pkg/errors/description.go @@ -33,6 +33,7 @@ var ( CaptchaMismatch = createDescription("CaptchaMismatch", "验证码错误", SILENT, 400) NoCaptchaToken = createDescription("NoCaptchaToken", "未请求过验证码Token,请检查您的 Cookie 设置", SILENT, 400) CaptchaExpired = createDescription("CaptchaExpired", "验证码已过期", SILENT, 400) + InvitationCodeInvalid = createDescription("InvitationCodeInvalid", "邀请码无效", SILENT, 400) TeacherNotExists = createDescription("TeacherNotExists", "未找到教师", SILENT, 400) From 868a5890331d69155caace66c5b877176b8571fa Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:04:19 +0800 Subject: [PATCH 10/68] feat(queries.Register): check invitation code validity --- pkg/queries/user.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index e7b3779..91f9554 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -100,6 +100,19 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { return errors.New(errors.InvalidArgument) } + // check if the invitation code is valid + if invitation_code != "" { + user := &models.User{} + result := db.Where("invitation_code = ?", invitation_code).Take(user) + if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return errors.Wrap(err, errors.DatabaseError) + } + if result.RowsAffected == 0 { + return errors.New(errors.InvitationCodeInvalid) + } + // TODO: Inform the inviter + } + // 检查邮箱是否已存在 user := &models.User{} result := db.Where("email = ?", u.Email).Take(user) From a1370e807682e1c2897802548b45f01977bb3080 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:22:44 +0800 Subject: [PATCH 11/68] feat(queries.Register): generate invitation code --- pkg/queries/user.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 91f9554..e772cbe 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -7,6 +7,7 @@ import ( "coursebench-backend/pkg/mail" "coursebench-backend/pkg/models" "fmt" + "math/rand" "strings" "time" "unicode" @@ -134,6 +135,15 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { u.IsActive = false u.IsAdmin = false + // creaete a invitation code + code := make([]rune, 0, 5) + for i := 0; i < 5; i++ { + code = append(code, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) + } + u.InvitationCode = string(code) + + // TODO: check for invitation code collision + if err = db.Create(u).Error; err != nil { return errors.Wrap(err, errors.DatabaseError) } From 4ae5a28168addf596e812705522d85ffd1f390d4 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:33:55 +0800 Subject: [PATCH 12/68] feat(queries.Register): check for invitation code collision --- pkg/queries/user.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index e772cbe..1393fa7 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -135,14 +135,24 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { u.IsActive = false u.IsAdmin = false - // creaete a invitation code - code := make([]rune, 0, 5) - for i := 0; i < 5; i++ { - code = append(code, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) - } - u.InvitationCode = string(code) + // create a invitation code + for { + code := make([]rune, 0, 5) + for i := 0; i < 5; i++ { + code = append(code, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) + } + u.InvitationCode = string(code) - // TODO: check for invitation code collision + // check for collision + user = &models.User{} + result = db.Where("invitation_code = ?", u.InvitationCode).Take(user) + if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return errors.Wrap(err, errors.DatabaseError) + } + if result.RowsAffected == 0 { + break + } + } if err = db.Create(u).Error; err != nil { return errors.Wrap(err, errors.DatabaseError) From 951039cdc084d4535c75be416ea86c25880a1021 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:45:52 +0800 Subject: [PATCH 13/68] feat(models.ProfileResponse): add InvitationCode field --- pkg/models/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/models/user.go b/pkg/models/user.go index 26c72ee..48bcea4 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -46,4 +46,5 @@ type ProfileResponse struct { IsAnonymous bool `json:"is_anonymous"` IsAdmin bool `json:"is_admin"` IsCommunityAdmin bool `json:"is_community_admin"` + InvitationCode string `json:"invitation_code"` } From c8650f78320eb253d130c3acfe8c0b02ca550aa3 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:50:12 +0800 Subject: [PATCH 14/68] feat(queries.GetProfile): return invitation code --- pkg/queries/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 1393fa7..82a757c 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -346,7 +346,7 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) if user.IsAnonymous && id != uid { return models.ProfileResponse{ID: id, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil } else { - return models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil + return models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, InvitationCode: user.InvitationCode}, nil } } From 1bb6aaa27a208da87bed9dcc4b39aa8cdfeb84a4 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 6 Apr 2024 23:57:30 +0800 Subject: [PATCH 15/68] feat(queries.Login): generate invitation code --- pkg/queries/user.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 82a757c..f660580 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -247,6 +247,32 @@ func Login(db *gorm.DB, email, password string) (*models.User, error) { return nil, errors.New(errors.UserNotActive) } + if user.InvitationCode == "" { + // create a invitation code + for { + code := make([]rune, 0, 5) + for i := 0; i < 5; i++ { + code = append(code, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) + } + user.InvitationCode = string(code) + + // check for collision + u := &models.User{} + result = db.Where("invitation_code = ?", u.InvitationCode).Take(u) + if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errors.Wrap(err, errors.DatabaseError) + } + if result.RowsAffected == 0 { + break + } + } + + err := db.Select("invitation_code").Save(user).Error + if err != nil { + return nil, errors.Wrap(err, errors.DatabaseError) + } + } + return user, nil } From c16b15bbfcfe3d51276dd5506f3e16a42b0bcfe3 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 7 Apr 2024 00:15:27 +0800 Subject: [PATCH 16/68] refactor(queries): extract createInvitationCode --- pkg/queries/user.go | 67 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index f660580..0cd916a 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -135,24 +135,11 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { u.IsActive = false u.IsAdmin = false - // create a invitation code - for { - code := make([]rune, 0, 5) - for i := 0; i < 5; i++ { - code = append(code, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) - } - u.InvitationCode = string(code) - - // check for collision - user = &models.User{} - result = db.Where("invitation_code = ?", u.InvitationCode).Take(user) - if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return errors.Wrap(err, errors.DatabaseError) - } - if result.RowsAffected == 0 { - break - } + code, err := createInvitationCode(db) + if err != nil { + return err } + u.InvitationCode = code if err = db.Create(u).Error; err != nil { return errors.Wrap(err, errors.DatabaseError) @@ -248,26 +235,13 @@ func Login(db *gorm.DB, email, password string) (*models.User, error) { } if user.InvitationCode == "" { - // create a invitation code - for { - code := make([]rune, 0, 5) - for i := 0; i < 5; i++ { - code = append(code, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) - } - user.InvitationCode = string(code) - - // check for collision - u := &models.User{} - result = db.Where("invitation_code = ?", u.InvitationCode).Take(u) - if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return nil, errors.Wrap(err, errors.DatabaseError) - } - if result.RowsAffected == 0 { - break - } + code, err := createInvitationCode(db) + if err != nil { + return nil, err } - err := db.Select("invitation_code").Save(user).Error + user.InvitationCode = code + err = db.Select("invitation_code").Save(user).Error if err != nil { return nil, errors.Wrap(err, errors.DatabaseError) } @@ -452,3 +426,26 @@ func CheckInvitationCode(code string) bool { } return true } + +func createInvitationCode(db *gorm.DB) (string, error) { + // try a few times before giving up + for i := 0; i < 5; i++ { + codeRunes := make([]rune, 0, 5) + for i := 0; i < 5; i++ { + codeRunes = append(codeRunes, []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")[rand.Intn(62)]) + } + code := string(codeRunes) + + // check for collision + u := &models.User{} + result := db.Where("invitation_code = ?", code).Take(u) + if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return "", errors.Wrap(err, errors.DatabaseError) + } + if result.RowsAffected == 0 { + return code, nil + } + } + + return "", errors.New(errors.InternalServerError) +} From 128561dc84765feafba51c912b7f3457ddbcf33d Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 7 Apr 2024 00:22:41 +0800 Subject: [PATCH 17/68] refactor(queries): extract isInvitationCodeTaken --- pkg/queries/user.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 0cd916a..cab5c6b 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -103,14 +103,14 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { // check if the invitation code is valid if invitation_code != "" { - user := &models.User{} - result := db.Where("invitation_code = ?", invitation_code).Take(user) - if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return errors.Wrap(err, errors.DatabaseError) + taken, err := isInvitationCodeTaken(db, invitation_code) + if err != nil { + return err } - if result.RowsAffected == 0 { + if !taken { return errors.New(errors.InvitationCodeInvalid) } + // TODO: Inform the inviter } @@ -436,16 +436,23 @@ func createInvitationCode(db *gorm.DB) (string, error) { } code := string(codeRunes) - // check for collision - u := &models.User{} - result := db.Where("invitation_code = ?", code).Take(u) - if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return "", errors.Wrap(err, errors.DatabaseError) + taken, err := isInvitationCodeTaken(db, code) + if err != nil { + return "", err } - if result.RowsAffected == 0 { + if !taken { return code, nil } } return "", errors.New(errors.InternalServerError) } + +func isInvitationCodeTaken(db *gorm.DB, code string) (bool, error) { + user := &models.User{} + result := db.Where("invitation_code = ?", code).Take(user) + if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return false, errors.Wrap(err, errors.DatabaseError) + } + return result.RowsAffected != 0, nil +} From 1ce82b852bf320af386aa69974886d9a2af76011 Mon Sep 17 00:00:00 2001 From: WA Date: Sun, 7 Apr 2024 20:16:09 +0800 Subject: [PATCH 18/68] CI: Build on all branches --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b6469db..e640eb3 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,7 +1,7 @@ name: Docker Image CI on: push: - branches: [ "master" ] + branches: [ "**" ] jobs: build: From 2df83b9d94a95548d5030545b02d9d7b1ed5b198 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 7 Apr 2024 20:18:41 +0800 Subject: [PATCH 19/68] fix(queries.GetProfile): return invitation code only if accessing user's own profile --- pkg/queries/user.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index cab5c6b..7ed3d5e 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -346,7 +346,11 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) if user.IsAnonymous && id != uid { return models.ProfileResponse{ID: id, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil } else { - return models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, InvitationCode: user.InvitationCode}, nil + r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin} + if id == uid { + r.InvitationCode = user.InvitationCode + } + return r, nil } } From 9432d624a0ddf616da33e6866b236b9efe7b8d33 Mon Sep 17 00:00:00 2001 From: WA Date: Sun, 7 Apr 2024 20:35:05 +0800 Subject: [PATCH 20/68] CI: Push image only at the master branch --- .github/workflows/docker-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index e640eb3..020a160 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -19,4 +19,5 @@ jobs: - name: Build the Docker image run: docker build . --file Dockerfile --tag $tag - name: Push the Docker image1 + if: github.ref == 'refs/heads/master' run: docker push $tag From 4d861c88d981fbfb2be8d28f9bd3884b7cd1eedc Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 22:36:33 +0800 Subject: [PATCH 21/68] feat(models.user): add rewards field for user --- pkg/models/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/models/user.go b/pkg/models/user.go index 48bcea4..606b9f1 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -29,6 +29,7 @@ type User struct { IsAdmin bool `gorm:"default:false"` IsCommunityAdmin bool `gorm:"default:false"` InvitationCode string + Rewards int } func init() { From c84c66f4e62f096f9d8efd259282b52e0ec2aed6 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 22:38:31 +0800 Subject: [PATCH 22/68] feat(models): add RanklistResponse model --- pkg/models/reward.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 pkg/models/reward.go diff --git a/pkg/models/reward.go b/pkg/models/reward.go new file mode 100644 index 0000000..8807ac1 --- /dev/null +++ b/pkg/models/reward.go @@ -0,0 +1,7 @@ +package models + +type RanklistResponse struct { + NickName string `json:"nick_name"` + Rewards int `json:"reward"` + IsAnonymous bool `json:"is_anonymous"` +} From 5363b659332baac4c0b7f0128865e14e3468ca90 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 22:38:42 +0800 Subject: [PATCH 23/68] feat(queries.Ranklist): add query --- pkg/queries/reward.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pkg/queries/reward.go diff --git a/pkg/queries/reward.go b/pkg/queries/reward.go new file mode 100644 index 0000000..0a53cac --- /dev/null +++ b/pkg/queries/reward.go @@ -0,0 +1,34 @@ +package queries + +import ( + "coursebench-backend/pkg/database" + "coursebench-backend/pkg/errors" + "coursebench-backend/pkg/models" + + "gorm.io/gorm" +) + +func Ranklist(db *gorm.DB) ([]models.RanklistResponse, error) { + if db == nil { + db = database.GetDB() + } + + var ranklist []models.RanklistResponse + result := db.Model(&models.User{}). + Select("nick_name", "rewards", "is_anonymous"). + Order("rewards DESC"). + Limit(30). + Scan(&ranklist) + + for i := range ranklist { + if ranklist[i].IsAnonymous { + ranklist[i].NickName = "" + } + } + + if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errors.Wrap(err, errors.DatabaseError) + } + + return ranklist, nil +} From bc784b5bc387ecb126552fd0c96d4df782448fad Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 22:39:42 +0800 Subject: [PATCH 24/68] feat(controllers/reward): add route --- internal/controllers/reward.go | 12 ++++++++++++ internal/controllers/reward/ranklist.go | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 internal/controllers/reward.go create mode 100644 internal/controllers/reward/ranklist.go diff --git a/internal/controllers/reward.go b/internal/controllers/reward.go new file mode 100644 index 0000000..66d84d6 --- /dev/null +++ b/internal/controllers/reward.go @@ -0,0 +1,12 @@ +package controllers + +import ( + "coursebench-backend/internal/controllers/reward" + + "github.com/gofiber/fiber/v2" +) + +func RewardRoutes(r fiber.Router) { + route := r.Group("/reward") + route.Get("/ranklist", reward.Ranklist) +} diff --git a/internal/controllers/reward/ranklist.go b/internal/controllers/reward/ranklist.go new file mode 100644 index 0000000..3996d45 --- /dev/null +++ b/internal/controllers/reward/ranklist.go @@ -0,0 +1,20 @@ +package reward + +import ( + "coursebench-backend/pkg/models" + "coursebench-backend/pkg/queries" + + "github.com/gofiber/fiber/v2" +) + +func Ranklist(c *fiber.Ctx) error { + var response []models.RanklistResponse + response, err := queries.Ranklist(nil) + if err != nil { + return err + } + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) +} From e8d39cb5eed495b053a2137c64bb3d2f85d6914a Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 23:23:59 +0800 Subject: [PATCH 25/68] fix(internal/fiber.Routes): add call to controllers.RewardRoutes --- internal/fiber/route.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/fiber/route.go b/internal/fiber/route.go index 7b19b9a..68669d8 100644 --- a/internal/fiber/route.go +++ b/internal/fiber/route.go @@ -3,6 +3,7 @@ package fiber import ( "coursebench-backend/internal/config" "coursebench-backend/internal/controllers" + "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" ) @@ -17,5 +18,5 @@ func Routes(app *fiber.App) { controllers.CourseRoutes(route) controllers.CommentRoutes(route) controllers.TeacherRoute(route) - + controllers.RewardRoutes(route) } From 45c7230e2d7c4053ce6f9272d2b2120b3bc0cc50 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 23:42:50 +0800 Subject: [PATCH 26/68] fix: name consistency for "reward" --- pkg/models/reward.go | 2 +- pkg/models/user.go | 2 +- pkg/queries/reward.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/models/reward.go b/pkg/models/reward.go index 8807ac1..bf8ebe0 100644 --- a/pkg/models/reward.go +++ b/pkg/models/reward.go @@ -2,6 +2,6 @@ package models type RanklistResponse struct { NickName string `json:"nick_name"` - Rewards int `json:"reward"` + Reward int `json:"reward"` IsAnonymous bool `json:"is_anonymous"` } diff --git a/pkg/models/user.go b/pkg/models/user.go index 606b9f1..635e797 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -29,7 +29,7 @@ type User struct { IsAdmin bool `gorm:"default:false"` IsCommunityAdmin bool `gorm:"default:false"` InvitationCode string - Rewards int + Reward int } func init() { diff --git a/pkg/queries/reward.go b/pkg/queries/reward.go index 0a53cac..655c091 100644 --- a/pkg/queries/reward.go +++ b/pkg/queries/reward.go @@ -15,7 +15,7 @@ func Ranklist(db *gorm.DB) ([]models.RanklistResponse, error) { var ranklist []models.RanklistResponse result := db.Model(&models.User{}). - Select("nick_name", "rewards", "is_anonymous"). + Select("nick_name", "reward", "is_anonymous"). Order("rewards DESC"). Limit(30). Scan(&ranklist) From 584737b46757cc16d3b8377dbc5706204a318df5 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 7 Apr 2024 23:44:17 +0800 Subject: [PATCH 27/68] fix: rename model file --- pkg/models/{reward.go => ranklist_response.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pkg/models/{reward.go => ranklist_response.go} (100%) diff --git a/pkg/models/reward.go b/pkg/models/ranklist_response.go similarity index 100% rename from pkg/models/reward.go rename to pkg/models/ranklist_response.go From 89350c06e8424b98601cea57c440aefcbae87e14 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 7 Apr 2024 23:51:00 +0800 Subject: [PATCH 28/68] fix(queries.Ranklist): correct field name --- pkg/queries/reward.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/reward.go b/pkg/queries/reward.go index 655c091..c660bfc 100644 --- a/pkg/queries/reward.go +++ b/pkg/queries/reward.go @@ -16,7 +16,7 @@ func Ranklist(db *gorm.DB) ([]models.RanklistResponse, error) { var ranklist []models.RanklistResponse result := db.Model(&models.User{}). Select("nick_name", "reward", "is_anonymous"). - Order("rewards DESC"). + Order("reward DESC"). Limit(30). Scan(&ranklist) From d7d4fdfefcfa72b178aed19cd1aa919ca3c5d839 Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Mon, 8 Apr 2024 19:30:38 +0800 Subject: [PATCH 29/68] feat(controllers/comments.CourseGroupComment): add query reward judgement feat(controllers/comments/user): add reward field to CommentResponse --- internal/controllers/comments/course_group.go | 24 +++++++++++++++---- internal/controllers/comments/user.go | 4 +++- internal/controllers/users/profile.go | 23 ++++++++++++++---- pkg/models/comment.go | 2 ++ pkg/models/user.go | 1 + pkg/queries/user.go | 2 +- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/internal/controllers/comments/course_group.go b/internal/controllers/comments/course_group.go index 1ecd459..9745a95 100644 --- a/internal/controllers/comments/course_group.go +++ b/internal/controllers/comments/course_group.go @@ -6,8 +6,10 @@ import ( "coursebench-backend/pkg/database" "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" - "github.com/gofiber/fiber/v2" + "coursebench-backend/pkg/queries" "strconv" + + "github.com/gofiber/fiber/v2" ) func CourseGroupComment(c *fiber.Ctx) (err error) { @@ -37,8 +39,20 @@ func CourseGroupComment(c *fiber.Ctx) (err error) { } var response []CommentResponse response = GenerateResponse(comments, uid, likeResult, true, utils.GetIP(c)) - return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: response, - Error: false, - }) + currentUser, err := queries.GetUserByID(nil, uid) + if err != nil { + return err + } + if currentUser.IsAdmin || currentUser.IsCommunityAdmin { + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) + } else { + response.Reward = -1 + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) + } } diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index 2f80736..40aea02 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -7,8 +7,9 @@ import ( "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" "coursebench-backend/pkg/queries" - "github.com/gofiber/fiber/v2" "strconv" + + "github.com/gofiber/fiber/v2" ) type CommentResponse struct { @@ -43,6 +44,7 @@ type CommentResponse struct { CoverTitle string `json:"cover_title"` CoverContent string `json:"cover_content"` CoverReason string `json:"cover_reason"` + Reward int `json:"reward"` } type CommentLikeResult struct { diff --git a/internal/controllers/users/profile.go b/internal/controllers/users/profile.go index c767eda..53e0f22 100644 --- a/internal/controllers/users/profile.go +++ b/internal/controllers/users/profile.go @@ -5,8 +5,9 @@ import ( "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" "coursebench-backend/pkg/queries" - "github.com/gofiber/fiber/v2" "strconv" + + "github.com/gofiber/fiber/v2" ) func Profile(c *fiber.Ctx) error { @@ -24,8 +25,20 @@ func Profile(c *fiber.Ctx) error { if err != nil { return err } - return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: response, - Error: false, - }) + currentUser, err := queries.GetUserByID(nil, uid) + if err != nil { + return err + } + if uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin { + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) + } else { + response.Reward = -1 + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) + } } diff --git a/pkg/models/comment.go b/pkg/models/comment.go index fba0e2a..24d838e 100644 --- a/pkg/models/comment.go +++ b/pkg/models/comment.go @@ -2,6 +2,7 @@ package models import ( "coursebench-backend/pkg/modelRegister" + "github.com/lib/pq" "gorm.io/gorm" ) @@ -30,6 +31,7 @@ type Comment struct { CoverTitle string CoverContent string CoverReason string + Reward int } type CommentLike struct { diff --git a/pkg/models/user.go b/pkg/models/user.go index 635e797..ab151a1 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -48,4 +48,5 @@ type ProfileResponse struct { IsAdmin bool `json:"is_admin"` IsCommunityAdmin bool `json:"is_community_admin"` InvitationCode string `json:"invitation_code"` + Reward int `json:"reward"` } diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 7ed3d5e..aa87db5 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -346,7 +346,7 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) if user.IsAnonymous && id != uid { return models.ProfileResponse{ID: id, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil } else { - r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin} + r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, Reward: user.Reward} if id == uid { r.InvitationCode = user.InvitationCode } From 5ca3c2a1621d940802aad65403c85603ba429e8a Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Mon, 8 Apr 2024 19:43:28 +0800 Subject: [PATCH 30/68] feat(controllers/comments.GenerateResponse): add reward field in response --- internal/controllers/comments/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index 40aea02..08e4e13 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -111,6 +111,7 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL CoverTitle: v.CoverTitle, CoverContent: v.CoverContent, CoverReason: v.CoverReason, + Reward: v.Reward, } // 该评论未设置匿名,或者是自己的评论,则显示用户信息 if !anonymous || v.User.ID == uid { From b1af5dfd3da5153c91aa9e281de28b78a9a7a4e0 Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Tue, 9 Apr 2024 14:02:38 +0800 Subject: [PATCH 31/68] refactor: avoid duplicate code in controllers/users.Profile, controllers/comments/course_group.CourseGroupComment --- internal/controllers/comments/course_group.go | 20 +++++++++---------- internal/controllers/users/profile.go | 15 +++++--------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/internal/controllers/comments/course_group.go b/internal/controllers/comments/course_group.go index 9745a95..98f50af 100644 --- a/internal/controllers/comments/course_group.go +++ b/internal/controllers/comments/course_group.go @@ -43,16 +43,14 @@ func CourseGroupComment(c *fiber.Ctx) (err error) { if err != nil { return err } - if currentUser.IsAdmin || currentUser.IsCommunityAdmin { - return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: response, - Error: false, - }) - } else { - response.Reward = -1 - return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: response, - Error: false, - }) + if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { + for i := range response { + // 设置评论的 Reward 字段为 -1,表示不可见 + response[i].Reward = -1 + } } + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) } diff --git a/internal/controllers/users/profile.go b/internal/controllers/users/profile.go index 53e0f22..b874134 100644 --- a/internal/controllers/users/profile.go +++ b/internal/controllers/users/profile.go @@ -29,16 +29,11 @@ func Profile(c *fiber.Ctx) error { if err != nil { return err } - if uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin { - return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: response, - Error: false, - }) - } else { + if !(uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin) { response.Reward = -1 - return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: response, - Error: false, - }) } + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: response, + Error: false, + }) } From f4edb4d21916d607ab8831c18e826a1c0bd263c7 Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Tue, 9 Apr 2024 14:21:06 +0800 Subject: [PATCH 32/68] feat(queries.GetProfile): add condition to get comment reward --- pkg/queries/user.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index aa87db5..27a92bd 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -349,6 +349,10 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, Reward: user.Reward} if id == uid { r.InvitationCode = user.InvitationCode + r.Reward = user.Reward + } + if user.IsAdmin || user.IsCommunityAdmin { + r.Reward = user.Reward } return r, nil } From fae771f83fdce8c9b218cb0c31b6dd9376e448f6 Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Tue, 9 Apr 2024 21:22:38 +0800 Subject: [PATCH 33/68] feat(queries.GetProfile): use a new if block to add condition to get comment reward --- pkg/queries/user.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 27a92bd..5454093 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -349,9 +349,8 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, Reward: user.Reward} if id == uid { r.InvitationCode = user.InvitationCode - r.Reward = user.Reward } - if user.IsAdmin || user.IsCommunityAdmin { + if id == uid || user.IsAdmin || user.IsCommunityAdmin { r.Reward = user.Reward } return r, nil From ee5bb74a7bb95bec80a9d8f0fe25352b13aeafdf Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Tue, 9 Apr 2024 21:58:15 +0800 Subject: [PATCH 34/68] feat: move comment reward display condition --- internal/controllers/comments/course_group.go | 11 ----------- internal/controllers/comments/user.go | 7 +++++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/controllers/comments/course_group.go b/internal/controllers/comments/course_group.go index 98f50af..2afd5c4 100644 --- a/internal/controllers/comments/course_group.go +++ b/internal/controllers/comments/course_group.go @@ -6,7 +6,6 @@ import ( "coursebench-backend/pkg/database" "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" - "coursebench-backend/pkg/queries" "strconv" "github.com/gofiber/fiber/v2" @@ -39,16 +38,6 @@ func CourseGroupComment(c *fiber.Ctx) (err error) { } var response []CommentResponse response = GenerateResponse(comments, uid, likeResult, true, utils.GetIP(c)) - currentUser, err := queries.GetUserByID(nil, uid) - if err != nil { - return err - } - if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { - for i := range response { - // 设置评论的 Reward 字段为 -1,表示不可见 - response[i].Reward = -1 - } - } return c.Status(fiber.StatusOK).JSON(models.OKResponse{ Data: response, Error: false, diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index 08e4e13..1d51517 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -114,6 +114,13 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL Reward: v.Reward, } // 该评论未设置匿名,或者是自己的评论,则显示用户信息 + currentUser, err := queries.GetUserByID(nil, uid) + if err != nil { + c.Reward = -2 + } + if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { + c.Reward = -1 + } if !anonymous || v.User.ID == uid { t, _ := queries.GetProfile(nil, v.UserID, uid) c.User = &t From 61d4123ecc1e639da57942e85ad993d3c6aba76c Mon Sep 17 00:00:00 2001 From: Yiyang Tan Date: Wed, 10 Apr 2024 09:08:46 +0800 Subject: [PATCH 35/68] refactor: move personal reward display condition into queries.GetProfile --- internal/controllers/users/profile.go | 7 ------- pkg/queries/user.go | 4 +++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/controllers/users/profile.go b/internal/controllers/users/profile.go index b874134..2eec0ec 100644 --- a/internal/controllers/users/profile.go +++ b/internal/controllers/users/profile.go @@ -25,13 +25,6 @@ func Profile(c *fiber.Ctx) error { if err != nil { return err } - currentUser, err := queries.GetUserByID(nil, uid) - if err != nil { - return err - } - if !(uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin) { - response.Reward = -1 - } return c.Status(fiber.StatusOK).JSON(models.OKResponse{ Data: response, Error: false, diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 5454093..d7802c4 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -346,12 +346,14 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) if user.IsAnonymous && id != uid { return models.ProfileResponse{ID: id, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil } else { - r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, Reward: user.Reward} + r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin} if id == uid { r.InvitationCode = user.InvitationCode } if id == uid || user.IsAdmin || user.IsCommunityAdmin { r.Reward = user.Reward + } else { + r.Reward = -1 } return r, nil } From cf07a3f57856860aad8ccab1789b483bc9a0f9d9 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Fri, 26 Apr 2024 20:45:52 +0800 Subject: [PATCH 36/68] feat(models.User): add HasPostedComments field --- pkg/models/user.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/models/user.go b/pkg/models/user.go index ab151a1..a3adc5a 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -17,19 +17,20 @@ const ( type User struct { gorm.Model - Email string `gorm:"index"` - Password string - NickName string - RealName string - Year int - Grade GradeType - IsActive bool - Avatar string - IsAnonymous bool - IsAdmin bool `gorm:"default:false"` - IsCommunityAdmin bool `gorm:"default:false"` - InvitationCode string - Reward int + Email string `gorm:"index"` + Password string + NickName string + RealName string + Year int + Grade GradeType + IsActive bool + Avatar string + IsAnonymous bool + IsAdmin bool `gorm:"default:false"` + IsCommunityAdmin bool `gorm:"default:false"` + InvitationCode string + Reward int + HasPostedComments bool `gorm:"default:false"` } func init() { From fd7c59682ed4c55c4712b728c076b6a8fd22c7bd Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Fri, 26 Apr 2024 21:02:40 +0800 Subject: [PATCH 37/68] feat(models.User): add InvitedByUserID field --- pkg/models/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/models/user.go b/pkg/models/user.go index a3adc5a..d465272 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -29,6 +29,7 @@ type User struct { IsAdmin bool `gorm:"default:false"` IsCommunityAdmin bool `gorm:"default:false"` InvitationCode string + InvitedByUserID uint Reward int HasPostedComments bool `gorm:"default:false"` } From a3559864d370249bbe439fd4ad7e656627da3e24 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Fri, 26 Apr 2024 21:15:33 +0800 Subject: [PATCH 38/68] feat(queries.GetUserByInvitationCode): rename --- pkg/queries/user.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index d7802c4..be7f9d2 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -103,15 +103,16 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { // check if the invitation code is valid if invitation_code != "" { - taken, err := isInvitationCodeTaken(db, invitation_code) + inviter, err := GetUserByInvitationCode(db, invitation_code) if err != nil { + if errors.Is(err, errors.UserNotExists) { + return errors.New(errors.InvitationCodeInvalid) + } return err } - if !taken { - return errors.New(errors.InvitationCodeInvalid) - } // TODO: Inform the inviter + _ = inviter } // 检查邮箱是否已存在 @@ -445,23 +446,31 @@ func createInvitationCode(db *gorm.DB) (string, error) { } code := string(codeRunes) - taken, err := isInvitationCodeTaken(db, code) + _, err := GetUserByInvitationCode(db, code) if err != nil { + if errors.Is(err, errors.UserNotExists) { + return code, nil + } return "", err } - if !taken { - return code, nil - } } return "", errors.New(errors.InternalServerError) } -func isInvitationCodeTaken(db *gorm.DB, code string) (bool, error) { +func GetUserByInvitationCode(db *gorm.DB, code string) (*models.User, error) { + if db == nil { + db = database.GetDB() + } + user := &models.User{} result := db.Where("invitation_code = ?", code).Take(user) if err := result.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return false, errors.Wrap(err, errors.DatabaseError) + return nil, errors.Wrap(err, errors.DatabaseError) + } + if result.RowsAffected == 0 { + return nil, errors.New(errors.UserNotExists) } - return result.RowsAffected != 0, nil + + return user, nil } From 94fc157b0fb81189499ddc34d5c8863dab3f4dc4 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Fri, 26 Apr 2024 21:20:06 +0800 Subject: [PATCH 39/68] feat(queries.Register): record inviter --- pkg/queries/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index be7f9d2..e4fe0fd 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -112,7 +112,7 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { } // TODO: Inform the inviter - _ = inviter + u.InvitedByUserID = inviter.ID } // 检查邮箱是否已存在 From 14c97dc74dd8ab4a4f2295eaf64547d17d4ce48e Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Fri, 26 Apr 2024 21:20:36 +0800 Subject: [PATCH 40/68] feat(queries.Register): reward inviter --- pkg/queries/user.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index e4fe0fd..c626638 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -111,8 +111,10 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { return err } - // TODO: Inform the inviter u.InvitedByUserID = inviter.ID + // TODO: only once for the inviter? + inviter.Reward += 100 + db.Save(inviter) } // 检查邮箱是否已存在 From 2a3fc6f1342602af86c166866830d215d58eddd7 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Fri, 26 Apr 2024 21:24:49 +0800 Subject: [PATCH 41/68] feat(controllers/comments.Post): reward inviter for first comment --- internal/controllers/comments/post.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/controllers/comments/post.go b/internal/controllers/comments/post.go index f3868cb..203ced3 100644 --- a/internal/controllers/comments/post.go +++ b/internal/controllers/comments/post.go @@ -6,9 +6,10 @@ import ( "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" "coursebench-backend/pkg/queries" + "time" + "github.com/gofiber/fiber/v2" "gorm.io/gorm" - "time" ) type PostRequest struct { @@ -117,6 +118,26 @@ func Post(c *fiber.Ctx) (err error) { if err != nil { return errors.Wrap(err, errors.DatabaseError) } + + // If this is the first time for the poster to post a comment, the reward the inviter. + var user models.User + err = tx.First(&user, uid).Error + if err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + + if user.HasPostedComments { + return nil + } + user.HasPostedComments = true + + inviter, err := queries.GetUserByID(tx, user.InvitedByUserID) + if err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + inviter.Reward += 100 + tx.Save(inviter) + return nil }) if err != nil { From fdf8fb7545b59e477f8451609b323210fe46fbbe Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 27 Apr 2024 00:57:45 +0800 Subject: [PATCH 42/68] feat(controllers/comments.RecentCommentByPage): init --- internal/controllers/comments.go | 2 + .../controllers/comments/recent_by_page.go | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 internal/controllers/comments/recent_by_page.go diff --git a/internal/controllers/comments.go b/internal/controllers/comments.go index d8c8dd0..1d523d0 100644 --- a/internal/controllers/comments.go +++ b/internal/controllers/comments.go @@ -2,6 +2,7 @@ package controllers import ( "coursebench-backend/internal/controllers/comments" + "github.com/gofiber/fiber/v2" ) @@ -14,6 +15,7 @@ func CommentRoutes(r fiber.Router) { route.Get("/course_group/:id", comments.CourseGroupComment) route.Get("/course/:id", comments.CourseComment) route.Get("/recent", comments.RecentComment) + route.Get("/recent/:id", comments.RecentCommentByPage) route.Post("/like", comments.Like) route.Post("/fold", comments.Fold) route.Post("/cover", comments.Cover) diff --git a/internal/controllers/comments/recent_by_page.go b/internal/controllers/comments/recent_by_page.go new file mode 100644 index 0000000..041483c --- /dev/null +++ b/internal/controllers/comments/recent_by_page.go @@ -0,0 +1,52 @@ +package comments + +import ( + "coursebench-backend/internal/middlewares/session" + "coursebench-backend/internal/utils" + "coursebench-backend/pkg/database" + "coursebench-backend/pkg/errors" + "coursebench-backend/pkg/models" + "strconv" + + "github.com/gofiber/fiber/v2" +) + +func RecentCommentByPage(c *fiber.Ctx) (err error) { + uid, err := session.GetUserID(c) + if err != nil { + uid = 0 + } + + id_s := c.Params("id", "1") + id, err := strconv.Atoi(id_s) + if err != nil { + return errors.New(errors.InvalidArgument) + } + + db := database.GetDB() + var comments []models.Comment + result := db.Preload("User").Preload("CourseGroup").Preload("CourseGroup.Course").Preload("CourseGroup.Teachers"). + Order("update_time DESC").Offset((id - 1) * 30).Limit(31).Find(&comments) + if err := result.Error; err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + if result.RowsAffected == 31 { + comments = comments[:30] + } + + var likeResult []CommentLikeResult + if uid != 0 { + db.Raw("SELECT comment_likes.comment_id, comment_likes.is_like from comments, comment_likes where comment_likes.user_id = ? and comment_likes.comment_id = comments.id and comment_likes.deleted_at is NULL and comments.deleted_at is NULL order by create_time desc OFFSET ? LIMIT 30", + (id-1)*30, + uid).Scan(&likeResult) + } + var response []CommentResponse + response = GenerateResponse(comments, uid, likeResult, true, utils.GetIP(c)) + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Data: fiber.Map{ + "has_more": result.RowsAffected == 31, + "comments": response, + }, + Error: false, + }) +} From 53617befbf90c0455b7c30ee58714552056c2fd3 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 27 Apr 2024 01:22:43 +0800 Subject: [PATCH 43/68] feat(controllers/reward.SetComment): init --- internal/controllers/reward.go | 1 + internal/controllers/reward/setcomment.go | 71 +++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 internal/controllers/reward/setcomment.go diff --git a/internal/controllers/reward.go b/internal/controllers/reward.go index 66d84d6..60972ca 100644 --- a/internal/controllers/reward.go +++ b/internal/controllers/reward.go @@ -9,4 +9,5 @@ import ( func RewardRoutes(r fiber.Router) { route := r.Group("/reward") route.Get("/ranklist", reward.Ranklist) + route.Post("/set/:id", reward.SetComment) } diff --git a/internal/controllers/reward/setcomment.go b/internal/controllers/reward/setcomment.go new file mode 100644 index 0000000..368cacf --- /dev/null +++ b/internal/controllers/reward/setcomment.go @@ -0,0 +1,71 @@ +package reward + +import ( + "coursebench-backend/internal/middlewares/session" + "coursebench-backend/pkg/database" + "coursebench-backend/pkg/errors" + "coursebench-backend/pkg/models" + "coursebench-backend/pkg/queries" + "strconv" + + "github.com/gofiber/fiber/v2" + "gorm.io/gorm" +) + +type SetCommentRequest struct { + Reward int `json:"reward"` +} + +func SetComment(c *fiber.Ctx) error { + c.Accepts("application/json") + var request SetCommentRequest + if err := c.BodyParser(&request); err != nil { + return errors.Wrap(err, errors.InvalidArgument) + } + + idRaw := c.Params("id", "GG") + id, err := strconv.Atoi(idRaw) + if err != nil { + return errors.New(errors.InvalidArgument) + } + + uid, err := session.GetUserID(c) + if err != nil { + uid = 0 + } + + db := database.GetDB() + user, err := queries.GetUserByID(db, uid) + if err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + if !(user.IsCommunityAdmin || user.IsAdmin) { + return errors.New(errors.PermissionDenied) + } + + comment := &models.Comment{} + result := db.First(&comment, id) + if result.Error != nil { + return errors.Wrap(result.Error, errors.DatabaseError) + } + + comment.User.Reward -= comment.Reward + comment.Reward = request.Reward + comment.User.Reward += comment.Reward + + if err := db.Transaction(func(tx *gorm.DB) error { + if err := tx.Save(comment).Error; err != nil { + return err + } + if err := tx.Save(user).Error; err != nil { + return err + } + return nil + }); err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + + return c.Status(fiber.StatusOK).JSON(models.OKResponse{ + Error: false, + }) +} From 9dd00e251316efc6e68750f8792c1a320fedc18c Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 28 Apr 2024 09:54:16 +0800 Subject: [PATCH 44/68] fix(controllers/comments.Post): save user changes --- internal/controllers/comments/post.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/controllers/comments/post.go b/internal/controllers/comments/post.go index 203ced3..8743c93 100644 --- a/internal/controllers/comments/post.go +++ b/internal/controllers/comments/post.go @@ -130,6 +130,7 @@ func Post(c *fiber.Ctx) (err error) { return nil } user.HasPostedComments = true + tx.Save(user) inviter, err := queries.GetUserByID(tx, user.InvitedByUserID) if err != nil { From f8ccf07fc6b5233079ff659f8df18ef0f521b3c5 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 28 Apr 2024 09:58:47 +0800 Subject: [PATCH 45/68] fix(controllers/comments.Post): fix when user is not invited --- internal/controllers/comments/post.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/controllers/comments/post.go b/internal/controllers/comments/post.go index 8743c93..d9f277a 100644 --- a/internal/controllers/comments/post.go +++ b/internal/controllers/comments/post.go @@ -132,6 +132,9 @@ func Post(c *fiber.Ctx) (err error) { user.HasPostedComments = true tx.Save(user) + if user.InvitedByUserID == 0 { + return nil + } inviter, err := queries.GetUserByID(tx, user.InvitedByUserID) if err != nil { return errors.Wrap(err, errors.DatabaseError) From 4bf3a1599a7adf3e6036746a20f689359a1ffbb3 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 28 Apr 2024 12:04:33 +0800 Subject: [PATCH 46/68] feat(controllers/comments.RecentCommentByPageResponse): init --- internal/controllers/comments/recent_by_page.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/controllers/comments/recent_by_page.go b/internal/controllers/comments/recent_by_page.go index 041483c..f8eb3fa 100644 --- a/internal/controllers/comments/recent_by_page.go +++ b/internal/controllers/comments/recent_by_page.go @@ -11,6 +11,12 @@ import ( "github.com/gofiber/fiber/v2" ) +type RecentCommentByPageResponse struct { + PageCount int64 `json:"page_count"` + HasMore bool `json:"has_more"` + Comments []CommentResponse `json:"comments"` +} + func RecentCommentByPage(c *fiber.Ctx) (err error) { uid, err := session.GetUserID(c) if err != nil { From 4f6f3cb46029991692c8dedaad882e374fe507f0 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 28 Apr 2024 12:05:23 +0800 Subject: [PATCH 47/68] feat(controllers/comments.RecentCommentByPage): return page count --- internal/controllers/comments/recent_by_page.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/controllers/comments/recent_by_page.go b/internal/controllers/comments/recent_by_page.go index f8eb3fa..f07d1a0 100644 --- a/internal/controllers/comments/recent_by_page.go +++ b/internal/controllers/comments/recent_by_page.go @@ -31,14 +31,12 @@ func RecentCommentByPage(c *fiber.Ctx) (err error) { db := database.GetDB() var comments []models.Comment - result := db.Preload("User").Preload("CourseGroup").Preload("CourseGroup.Course").Preload("CourseGroup.Teachers"). - Order("update_time DESC").Offset((id - 1) * 30).Limit(31).Find(&comments) + var count int64 + result := db.Preload("User").Preload("CourseGroup").Preload("CourseGroup.Course").Preload("CourseGroup.Teachers").Count(&count). + Order("update_time DESC").Offset((id - 1) * 30).Limit(30).Find(&comments) if err := result.Error; err != nil { return errors.Wrap(err, errors.DatabaseError) } - if result.RowsAffected == 31 { - comments = comments[:30] - } var likeResult []CommentLikeResult if uid != 0 { @@ -49,9 +47,10 @@ func RecentCommentByPage(c *fiber.Ctx) (err error) { var response []CommentResponse response = GenerateResponse(comments, uid, likeResult, true, utils.GetIP(c)) return c.Status(fiber.StatusOK).JSON(models.OKResponse{ - Data: fiber.Map{ - "has_more": result.RowsAffected == 31, - "comments": response, + Data: RecentCommentByPageResponse{ + PageCount: (count + 29) / 30, // ceil + HasMore: count > int64(id)*30, + Comments: response, }, Error: false, }) From f460bcd7c63c7ae2abb8f84028a51c14c0f85cee Mon Sep 17 00:00:00 2001 From: WA Date: Sat, 4 May 2024 12:48:22 +0800 Subject: [PATCH 48/68] Use github container registry --- .github/workflows/docker-image.yml | 40 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 020a160..956799f 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,18 +6,34 @@ on: jobs: build: runs-on: ubuntu-22.04 + permissions: + packages: write + contents: read env: - tag: ${{ secrets.CI_REGISTRY }}/geekpie/coursebench-backend:latest + REGISTRY: ghcr.io + USERNAME: ShanghaitechGeekPie + IMAGE_NAME : ${{ github.repository }} steps: - - uses: actions/checkout@v3 - - name: Login to Docker Hub - uses: docker/login-action@v2 + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Login to Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.USERNAME }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 with: - registry: ${{ secrets.CI_REGISTRY }} - username: ${{ secrets.CI_REGISTRY_USER }} - password: ${{ secrets.CI_REGISTRY_PASSWORD }} - - name: Build the Docker image - run: docker build . --file Dockerfile --tag $tag - - name: Push the Docker image1 - if: github.ref == 'refs/heads/master' - run: docker push $tag + context: . + push: ${{github.ref == 'refs/heads/master' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From ba307bd62a0737f04ba0ede9166f9938da8dd376 Mon Sep 17 00:00:00 2001 From: WA Date: Sat, 4 May 2024 13:18:24 +0800 Subject: [PATCH 49/68] Update docker-image.yml --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 956799f..74378ca 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -34,6 +34,6 @@ jobs: uses: docker/build-push-action@v2 with: context: . - push: ${{github.ref == 'refs/heads/master' }} + push: ${{github.ref == 'refs/heads/master' || 'refs/heads/release'}} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 636dd2c2f26610a547aa96190cf1991dcf1449bf Mon Sep 17 00:00:00 2001 From: WA Date: Sat, 4 May 2024 13:18:54 +0800 Subject: [PATCH 50/68] Update docker-image.yml --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 74378ca..1eb93fd 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -34,6 +34,6 @@ jobs: uses: docker/build-push-action@v2 with: context: . - push: ${{github.ref == 'refs/heads/master' || 'refs/heads/release'}} + push: ${{github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release'}} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 612fc227fc5c61a39d73de29b1cfa85ad0525a0c Mon Sep 17 00:00:00 2001 From: Yiyang Tan <140795018+Tanngent2005@users.noreply.github.com> Date: Sun, 5 May 2024 20:14:59 +0800 Subject: [PATCH 51/68] bugfix#19 --- internal/controllers/comments/user.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index 1d51517..d17d224 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -117,8 +117,7 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL currentUser, err := queries.GetUserByID(nil, uid) if err != nil { c.Reward = -2 - } - if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { + }else if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { c.Reward = -1 } if !anonymous || v.User.ID == uid { From d8fae858cc34fd46665db7eebe315b2183a2c4f3 Mon Sep 17 00:00:00 2001 From: WAAutoMaton Date: Sat, 11 May 2024 17:26:41 +0800 Subject: [PATCH 52/68] style(controller/comments/user.go): reformat file --- internal/controllers/comments/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index d17d224..e8f37b5 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -117,7 +117,7 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL currentUser, err := queries.GetUserByID(nil, uid) if err != nil { c.Reward = -2 - }else if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { + } else if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { c.Reward = -1 } if !anonymous || v.User.ID == uid { From b562551d99d67adc3b2ae023f2258a287f390c11 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 11 May 2024 23:06:17 +0800 Subject: [PATCH 53/68] feat(controllers/comments.GenerateResponse): disclose reward --- internal/controllers/comments/user.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index e8f37b5..1ac9872 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -113,13 +113,6 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL CoverReason: v.CoverReason, Reward: v.Reward, } - // 该评论未设置匿名,或者是自己的评论,则显示用户信息 - currentUser, err := queries.GetUserByID(nil, uid) - if err != nil { - c.Reward = -2 - } else if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin { - c.Reward = -1 - } if !anonymous || v.User.ID == uid { t, _ := queries.GetProfile(nil, v.UserID, uid) c.User = &t From df3ced1162a217dd07ae8f87f824f176332a1770 Mon Sep 17 00:00:00 2001 From: WAAutoMaton Date: Sun, 12 May 2024 16:35:54 +0800 Subject: [PATCH 54/68] Add license notices --- cmd/cmd_tools/clear_userdata.go | 16 ++++++++++++++++ cmd/cmd_tools/import_course.go | 16 ++++++++++++++++ cmd/cmd_tools/import_teacher.go | 16 ++++++++++++++++ cmd/cmd_tools/main.go | 16 ++++++++++++++++ cmd/cmd_tools/set_admin.go | 16 ++++++++++++++++ cmd/coursebench-backend/main.go | 16 ++++++++++++++++ internal/config/fiber.go | 16 ++++++++++++++++ internal/config/viper.go | 16 ++++++++++++++++ internal/controllers/comments.go | 16 ++++++++++++++++ internal/controllers/comments/course.go | 16 ++++++++++++++++ internal/controllers/comments/course_group.go | 16 ++++++++++++++++ internal/controllers/comments/cover.go | 16 ++++++++++++++++ internal/controllers/comments/delete.go | 16 ++++++++++++++++ internal/controllers/comments/fold.go | 16 ++++++++++++++++ internal/controllers/comments/like.go | 16 ++++++++++++++++ internal/controllers/comments/post.go | 16 ++++++++++++++++ internal/controllers/comments/recent.go | 16 ++++++++++++++++ internal/controllers/comments/update.go | 16 ++++++++++++++++ internal/controllers/comments/user.go | 16 ++++++++++++++++ internal/controllers/courses.go | 16 ++++++++++++++++ internal/controllers/courses/all.go | 16 ++++++++++++++++ internal/controllers/courses/info.go | 16 ++++++++++++++++ internal/controllers/teacher/all.go | 16 ++++++++++++++++ internal/controllers/teacher/info.go | 16 ++++++++++++++++ internal/controllers/teachers.go | 16 ++++++++++++++++ internal/controllers/test/captcha.go | 16 ++++++++++++++++ internal/controllers/test/captcha/captcha.go | 16 ++++++++++++++++ internal/controllers/test/course.go | 16 ++++++++++++++++ internal/controllers/test/course/add.go | 16 ++++++++++++++++ internal/controllers/test/course_group.go | 16 ++++++++++++++++ internal/controllers/test/course_group/add.go | 16 ++++++++++++++++ internal/controllers/test/myprofile.go | 16 ++++++++++++++++ internal/controllers/test/teacher.go | 16 ++++++++++++++++ internal/controllers/test/teacher/add.go | 16 ++++++++++++++++ internal/controllers/tests.go | 16 ++++++++++++++++ internal/controllers/users.go | 16 ++++++++++++++++ internal/controllers/users/get_captcha.go | 16 ++++++++++++++++ internal/controllers/users/login.go | 16 ++++++++++++++++ internal/controllers/users/logout.go | 16 ++++++++++++++++ internal/controllers/users/my_id.go | 16 ++++++++++++++++ internal/controllers/users/profile.go | 16 ++++++++++++++++ internal/controllers/users/register.go | 16 ++++++++++++++++ internal/controllers/users/register_active.go | 16 ++++++++++++++++ internal/controllers/users/reset_password.go | 16 ++++++++++++++++ .../controllers/users/reset_password_active.go | 16 ++++++++++++++++ internal/controllers/users/updatePassword.go | 16 ++++++++++++++++ internal/controllers/users/updateProfile.go | 16 ++++++++++++++++ internal/controllers/users/upload_avatar.go | 16 ++++++++++++++++ internal/fiber/config.go | 16 ++++++++++++++++ internal/fiber/errorHandler.go | 16 ++++++++++++++++ internal/fiber/new.go | 16 ++++++++++++++++ internal/fiber/route.go | 16 ++++++++++++++++ internal/middlewares/logger/log_middleware.go | 16 ++++++++++++++++ internal/middlewares/session/session.go | 16 ++++++++++++++++ internal/utils/utils.go | 16 ++++++++++++++++ pkg/database/minio.go | 16 ++++++++++++++++ pkg/database/postgres.go | 16 ++++++++++++++++ pkg/database/redis.go | 16 ++++++++++++++++ pkg/database/upgrade/upgrade.go | 16 ++++++++++++++++ pkg/errors/description.go | 16 ++++++++++++++++ pkg/errors/errno.go | 16 ++++++++++++++++ pkg/errors/error.go | 16 ++++++++++++++++ pkg/errors/errorLevel.go | 16 ++++++++++++++++ pkg/errors/gracefulPanic.go | 16 ++++++++++++++++ pkg/errors/options.go | 16 ++++++++++++++++ pkg/log/log.go | 16 ++++++++++++++++ pkg/mail/interface.go | 16 ++++++++++++++++ pkg/mail/smtp.go | 16 ++++++++++++++++ pkg/modelRegister/register.go | 16 ++++++++++++++++ pkg/models/comment.go | 16 ++++++++++++++++ pkg/models/course.go | 16 ++++++++++++++++ pkg/models/course_group.go | 16 ++++++++++++++++ pkg/models/course_response.go | 16 ++++++++++++++++ pkg/models/metadata.go | 16 ++++++++++++++++ pkg/models/response.go | 16 ++++++++++++++++ pkg/models/teacher.go | 16 ++++++++++++++++ pkg/models/user.go | 1 + pkg/queries/captcha.go | 16 ++++++++++++++++ pkg/queries/comment.go | 16 ++++++++++++++++ pkg/queries/course.go | 16 ++++++++++++++++ pkg/queries/db_upgrade.go | 16 ++++++++++++++++ pkg/queries/strings.go | 16 ++++++++++++++++ pkg/queries/teacher.go | 16 ++++++++++++++++ pkg/queries/user.go | 16 ++++++++++++++++ 84 files changed, 1329 insertions(+) diff --git a/cmd/cmd_tools/clear_userdata.go b/cmd/cmd_tools/clear_userdata.go index d79a9ac..70ce712 100644 --- a/cmd/cmd_tools/clear_userdata.go +++ b/cmd/cmd_tools/clear_userdata.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package main import ( diff --git a/cmd/cmd_tools/import_course.go b/cmd/cmd_tools/import_course.go index 44bfe08..52be236 100644 --- a/cmd/cmd_tools/import_course.go +++ b/cmd/cmd_tools/import_course.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package main import ( diff --git a/cmd/cmd_tools/import_teacher.go b/cmd/cmd_tools/import_teacher.go index 5de98a7..e2a8358 100644 --- a/cmd/cmd_tools/import_teacher.go +++ b/cmd/cmd_tools/import_teacher.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package main import ( diff --git a/cmd/cmd_tools/main.go b/cmd/cmd_tools/main.go index eecc884..6192ffd 100644 --- a/cmd/cmd_tools/main.go +++ b/cmd/cmd_tools/main.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package main import ( diff --git a/cmd/cmd_tools/set_admin.go b/cmd/cmd_tools/set_admin.go index 32da536..d86f224 100644 --- a/cmd/cmd_tools/set_admin.go +++ b/cmd/cmd_tools/set_admin.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package main import ( diff --git a/cmd/coursebench-backend/main.go b/cmd/coursebench-backend/main.go index b4a0018..0ed1aa8 100644 --- a/cmd/coursebench-backend/main.go +++ b/cmd/coursebench-backend/main.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package main import ( diff --git a/internal/config/fiber.go b/internal/config/fiber.go index b1125ee..46c8c08 100644 --- a/internal/config/fiber.go +++ b/internal/config/fiber.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package config import ( diff --git a/internal/config/viper.go b/internal/config/viper.go index 92baa5a..5bfda91 100644 --- a/internal/config/viper.go +++ b/internal/config/viper.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package config import ( diff --git a/internal/controllers/comments.go b/internal/controllers/comments.go index d8c8dd0..2fe3fce 100644 --- a/internal/controllers/comments.go +++ b/internal/controllers/comments.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package controllers import ( diff --git a/internal/controllers/comments/course.go b/internal/controllers/comments/course.go index 440464a..4bcd5d3 100644 --- a/internal/controllers/comments/course.go +++ b/internal/controllers/comments/course.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/course_group.go b/internal/controllers/comments/course_group.go index 1ecd459..765a5e9 100644 --- a/internal/controllers/comments/course_group.go +++ b/internal/controllers/comments/course_group.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/cover.go b/internal/controllers/comments/cover.go index 6a95e41..ed37d4a 100644 --- a/internal/controllers/comments/cover.go +++ b/internal/controllers/comments/cover.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/delete.go b/internal/controllers/comments/delete.go index 0905d8f..7babb9f 100644 --- a/internal/controllers/comments/delete.go +++ b/internal/controllers/comments/delete.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/fold.go b/internal/controllers/comments/fold.go index 9eb8ef9..6d1a8cf 100644 --- a/internal/controllers/comments/fold.go +++ b/internal/controllers/comments/fold.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/like.go b/internal/controllers/comments/like.go index 6e93960..bbc5ce8 100644 --- a/internal/controllers/comments/like.go +++ b/internal/controllers/comments/like.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/post.go b/internal/controllers/comments/post.go index f3868cb..506e8ab 100644 --- a/internal/controllers/comments/post.go +++ b/internal/controllers/comments/post.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/recent.go b/internal/controllers/comments/recent.go index fadb5c4..0d203ba 100644 --- a/internal/controllers/comments/recent.go +++ b/internal/controllers/comments/recent.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/update.go b/internal/controllers/comments/update.go index d902f08..5c05c58 100644 --- a/internal/controllers/comments/update.go +++ b/internal/controllers/comments/update.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/comments/user.go b/internal/controllers/comments/user.go index 2f80736..12727d0 100644 --- a/internal/controllers/comments/user.go +++ b/internal/controllers/comments/user.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package comments import ( diff --git a/internal/controllers/courses.go b/internal/controllers/courses.go index 6f4bfbd..4e0bce3 100644 --- a/internal/controllers/courses.go +++ b/internal/controllers/courses.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package controllers import ( diff --git a/internal/controllers/courses/all.go b/internal/controllers/courses/all.go index 909a9c5..6c44eb9 100644 --- a/internal/controllers/courses/all.go +++ b/internal/controllers/courses/all.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package courses import ( diff --git a/internal/controllers/courses/info.go b/internal/controllers/courses/info.go index dc95b4e..1218bcd 100644 --- a/internal/controllers/courses/info.go +++ b/internal/controllers/courses/info.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package courses import ( diff --git a/internal/controllers/teacher/all.go b/internal/controllers/teacher/all.go index 678e897..3a93b25 100644 --- a/internal/controllers/teacher/all.go +++ b/internal/controllers/teacher/all.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package teacher import ( diff --git a/internal/controllers/teacher/info.go b/internal/controllers/teacher/info.go index ecf7596..131bf35 100644 --- a/internal/controllers/teacher/info.go +++ b/internal/controllers/teacher/info.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package teacher import ( diff --git a/internal/controllers/teachers.go b/internal/controllers/teachers.go index f0b665b..919da21 100644 --- a/internal/controllers/teachers.go +++ b/internal/controllers/teachers.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package controllers import ( diff --git a/internal/controllers/test/captcha.go b/internal/controllers/test/captcha.go index 8fca948..584c927 100644 --- a/internal/controllers/test/captcha.go +++ b/internal/controllers/test/captcha.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package test import ( diff --git a/internal/controllers/test/captcha/captcha.go b/internal/controllers/test/captcha/captcha.go index 1472e41..d0684f5 100644 --- a/internal/controllers/test/captcha/captcha.go +++ b/internal/controllers/test/captcha/captcha.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package captcha import ( diff --git a/internal/controllers/test/course.go b/internal/controllers/test/course.go index e90211b..6f4f842 100644 --- a/internal/controllers/test/course.go +++ b/internal/controllers/test/course.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package test import ( diff --git a/internal/controllers/test/course/add.go b/internal/controllers/test/course/add.go index d215431..b057a12 100644 --- a/internal/controllers/test/course/add.go +++ b/internal/controllers/test/course/add.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package course import ( diff --git a/internal/controllers/test/course_group.go b/internal/controllers/test/course_group.go index f03679d..94205f5 100644 --- a/internal/controllers/test/course_group.go +++ b/internal/controllers/test/course_group.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package test import ( diff --git a/internal/controllers/test/course_group/add.go b/internal/controllers/test/course_group/add.go index 5f39c6a..7ffe599 100644 --- a/internal/controllers/test/course_group/add.go +++ b/internal/controllers/test/course_group/add.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package course_group import ( diff --git a/internal/controllers/test/myprofile.go b/internal/controllers/test/myprofile.go index 8d4697f..d6f8a6d 100644 --- a/internal/controllers/test/myprofile.go +++ b/internal/controllers/test/myprofile.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package test import ( diff --git a/internal/controllers/test/teacher.go b/internal/controllers/test/teacher.go index b415ebc..41b03ad 100644 --- a/internal/controllers/test/teacher.go +++ b/internal/controllers/test/teacher.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package test import ( diff --git a/internal/controllers/test/teacher/add.go b/internal/controllers/test/teacher/add.go index 10061ae..56f4dcd 100644 --- a/internal/controllers/test/teacher/add.go +++ b/internal/controllers/test/teacher/add.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package teacher import ( diff --git a/internal/controllers/tests.go b/internal/controllers/tests.go index 01ee457..b80c2c8 100644 --- a/internal/controllers/tests.go +++ b/internal/controllers/tests.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package controllers import ( diff --git a/internal/controllers/users.go b/internal/controllers/users.go index 23c4eda..0d37846 100644 --- a/internal/controllers/users.go +++ b/internal/controllers/users.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package controllers import ( diff --git a/internal/controllers/users/get_captcha.go b/internal/controllers/users/get_captcha.go index 602fe5b..87a4702 100644 --- a/internal/controllers/users/get_captcha.go +++ b/internal/controllers/users/get_captcha.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/login.go b/internal/controllers/users/login.go index 17ae1b7..cfb796a 100644 --- a/internal/controllers/users/login.go +++ b/internal/controllers/users/login.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/logout.go b/internal/controllers/users/logout.go index 10dbf81..1ecb115 100644 --- a/internal/controllers/users/logout.go +++ b/internal/controllers/users/logout.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/my_id.go b/internal/controllers/users/my_id.go index f73fa15..58f123a 100644 --- a/internal/controllers/users/my_id.go +++ b/internal/controllers/users/my_id.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/profile.go b/internal/controllers/users/profile.go index c767eda..31cfbd9 100644 --- a/internal/controllers/users/profile.go +++ b/internal/controllers/users/profile.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/register.go b/internal/controllers/users/register.go index 664c22e..639897a 100644 --- a/internal/controllers/users/register.go +++ b/internal/controllers/users/register.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/register_active.go b/internal/controllers/users/register_active.go index 13a2b5c..25c7d37 100644 --- a/internal/controllers/users/register_active.go +++ b/internal/controllers/users/register_active.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/reset_password.go b/internal/controllers/users/reset_password.go index cbd9ebf..43a9270 100644 --- a/internal/controllers/users/reset_password.go +++ b/internal/controllers/users/reset_password.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/reset_password_active.go b/internal/controllers/users/reset_password_active.go index 7751d1a..fcef23f 100644 --- a/internal/controllers/users/reset_password_active.go +++ b/internal/controllers/users/reset_password_active.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/updatePassword.go b/internal/controllers/users/updatePassword.go index 9cf8127..cd24b67 100644 --- a/internal/controllers/users/updatePassword.go +++ b/internal/controllers/users/updatePassword.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/updateProfile.go b/internal/controllers/users/updateProfile.go index 4159185..52159f1 100644 --- a/internal/controllers/users/updateProfile.go +++ b/internal/controllers/users/updateProfile.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/controllers/users/upload_avatar.go b/internal/controllers/users/upload_avatar.go index 9f81b3d..a454fb0 100644 --- a/internal/controllers/users/upload_avatar.go +++ b/internal/controllers/users/upload_avatar.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package users import ( diff --git a/internal/fiber/config.go b/internal/fiber/config.go index 9a84676..fb0f24e 100644 --- a/internal/fiber/config.go +++ b/internal/fiber/config.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package fiber import ( diff --git a/internal/fiber/errorHandler.go b/internal/fiber/errorHandler.go index b05eae0..c43198f 100644 --- a/internal/fiber/errorHandler.go +++ b/internal/fiber/errorHandler.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package fiber import ( diff --git a/internal/fiber/new.go b/internal/fiber/new.go index a928631..6e5ece7 100644 --- a/internal/fiber/new.go +++ b/internal/fiber/new.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package fiber import ( diff --git a/internal/fiber/route.go b/internal/fiber/route.go index 7b19b9a..309467a 100644 --- a/internal/fiber/route.go +++ b/internal/fiber/route.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package fiber import ( diff --git a/internal/middlewares/logger/log_middleware.go b/internal/middlewares/logger/log_middleware.go index cf3c60a..2fceeec 100644 --- a/internal/middlewares/logger/log_middleware.go +++ b/internal/middlewares/logger/log_middleware.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package logger import ( diff --git a/internal/middlewares/session/session.go b/internal/middlewares/session/session.go index 94aaa5c..c78e9a5 100644 --- a/internal/middlewares/session/session.go +++ b/internal/middlewares/session/session.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package session import ( diff --git a/internal/utils/utils.go b/internal/utils/utils.go index dd5afed..336fd6b 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package utils import ( diff --git a/pkg/database/minio.go b/pkg/database/minio.go index a4084ec..59ea90c 100644 --- a/pkg/database/minio.go +++ b/pkg/database/minio.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package database import ( diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index 7917762..317832a 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package database import ( diff --git a/pkg/database/redis.go b/pkg/database/redis.go index a6f4a71..5919fd9 100644 --- a/pkg/database/redis.go +++ b/pkg/database/redis.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package database import ( diff --git a/pkg/database/upgrade/upgrade.go b/pkg/database/upgrade/upgrade.go index fb8c2c2..3052041 100644 --- a/pkg/database/upgrade/upgrade.go +++ b/pkg/database/upgrade/upgrade.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package upgrade import ( diff --git a/pkg/errors/description.go b/pkg/errors/description.go index 4df8371..68cd4fc 100644 --- a/pkg/errors/description.go +++ b/pkg/errors/description.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package errors var ( diff --git a/pkg/errors/errno.go b/pkg/errors/errno.go index 2cbc6e2..056d905 100644 --- a/pkg/errors/errno.go +++ b/pkg/errors/errno.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package errors import "strconv" diff --git a/pkg/errors/error.go b/pkg/errors/error.go index 1e86570..1f6cae9 100644 --- a/pkg/errors/error.go +++ b/pkg/errors/error.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package errors import ( diff --git a/pkg/errors/errorLevel.go b/pkg/errors/errorLevel.go index 2d6cac9..26550e2 100644 --- a/pkg/errors/errorLevel.go +++ b/pkg/errors/errorLevel.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package errors type ErrorLevel int diff --git a/pkg/errors/gracefulPanic.go b/pkg/errors/gracefulPanic.go index 7040faf..d041a4c 100644 --- a/pkg/errors/gracefulPanic.go +++ b/pkg/errors/gracefulPanic.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package errors func Panic(v interface{}) { diff --git a/pkg/errors/options.go b/pkg/errors/options.go index c9e27ed..9426082 100644 --- a/pkg/errors/options.go +++ b/pkg/errors/options.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package errors type Option interface { diff --git a/pkg/log/log.go b/pkg/log/log.go index fe2f6d9..646cf24 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package log import ( diff --git a/pkg/mail/interface.go b/pkg/mail/interface.go index 386deb3..e89d10b 100644 --- a/pkg/mail/interface.go +++ b/pkg/mail/interface.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package mail import ( diff --git a/pkg/mail/smtp.go b/pkg/mail/smtp.go index eb3d003..35e16d3 100644 --- a/pkg/mail/smtp.go +++ b/pkg/mail/smtp.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package mail import ( diff --git a/pkg/modelRegister/register.go b/pkg/modelRegister/register.go index 3622c7e..923b6f5 100644 --- a/pkg/modelRegister/register.go +++ b/pkg/modelRegister/register.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package modelRegister var registeredTypes = make([]interface{}, 0) diff --git a/pkg/models/comment.go b/pkg/models/comment.go index fba0e2a..0c933e7 100644 --- a/pkg/models/comment.go +++ b/pkg/models/comment.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models import ( diff --git a/pkg/models/course.go b/pkg/models/course.go index c951201..fce7b7e 100644 --- a/pkg/models/course.go +++ b/pkg/models/course.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models import ( diff --git a/pkg/models/course_group.go b/pkg/models/course_group.go index d767dd2..7d0b7a7 100644 --- a/pkg/models/course_group.go +++ b/pkg/models/course_group.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models import ( diff --git a/pkg/models/course_response.go b/pkg/models/course_response.go index 11cd8c9..df20488 100644 --- a/pkg/models/course_response.go +++ b/pkg/models/course_response.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models type CourseAllResponse struct { diff --git a/pkg/models/metadata.go b/pkg/models/metadata.go index 377b5ac..8512f38 100644 --- a/pkg/models/metadata.go +++ b/pkg/models/metadata.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models import ( diff --git a/pkg/models/response.go b/pkg/models/response.go index e231220..137dea0 100644 --- a/pkg/models/response.go +++ b/pkg/models/response.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models import "time" diff --git a/pkg/models/teacher.go b/pkg/models/teacher.go index d1c410a..3a3bd29 100644 --- a/pkg/models/teacher.go +++ b/pkg/models/teacher.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package models import ( diff --git a/pkg/models/user.go b/pkg/models/user.go index 79a3b2c..ca564a6 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -27,6 +27,7 @@ type User struct { IsAnonymous bool IsAdmin bool `gorm:"default:false"` IsCommunityAdmin bool `gorm:"default:false"` + InvitedBy int } func init() { diff --git a/pkg/queries/captcha.go b/pkg/queries/captcha.go index 0d28950..eba8052 100644 --- a/pkg/queries/captcha.go +++ b/pkg/queries/captcha.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries import ( diff --git a/pkg/queries/comment.go b/pkg/queries/comment.go index 55c78d8..0b66070 100644 --- a/pkg/queries/comment.go +++ b/pkg/queries/comment.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries import ( diff --git a/pkg/queries/course.go b/pkg/queries/course.go index 73c3f6d..a88c3f1 100644 --- a/pkg/queries/course.go +++ b/pkg/queries/course.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries import ( diff --git a/pkg/queries/db_upgrade.go b/pkg/queries/db_upgrade.go index 58eadae..ee9fcde 100644 --- a/pkg/queries/db_upgrade.go +++ b/pkg/queries/db_upgrade.go @@ -1 +1,17 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries diff --git a/pkg/queries/strings.go b/pkg/queries/strings.go index 78dfa7d..508dd97 100644 --- a/pkg/queries/strings.go +++ b/pkg/queries/strings.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries // 返回一个字符串的渲染长度 diff --git a/pkg/queries/teacher.go b/pkg/queries/teacher.go index 76e3b1f..9e0cdab 100644 --- a/pkg/queries/teacher.go +++ b/pkg/queries/teacher.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries import ( diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 1a32e35..547143e 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -1,3 +1,19 @@ +// Copyright (C) 2021-2024 ShanghaiTech GeekPie +// This file is part of CourseBench Backend. +// +// CourseBench Backend is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// CourseBench Backend is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with CourseBench Backend. If not, see . + package queries import ( From c8df9e7ebf816cab960cbca4f7c7780bd1cef027 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 12 May 2024 23:13:39 +0800 Subject: [PATCH 55/68] feat(controllers/reward.SetComment)!: match api changes --- internal/controllers/reward.go | 2 +- internal/controllers/reward/setcomment.go | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/controllers/reward.go b/internal/controllers/reward.go index 60972ca..f27ec39 100644 --- a/internal/controllers/reward.go +++ b/internal/controllers/reward.go @@ -9,5 +9,5 @@ import ( func RewardRoutes(r fiber.Router) { route := r.Group("/reward") route.Get("/ranklist", reward.Ranklist) - route.Post("/set/:id", reward.SetComment) + route.Post("/set", reward.SetComment) } diff --git a/internal/controllers/reward/setcomment.go b/internal/controllers/reward/setcomment.go index 368cacf..1432127 100644 --- a/internal/controllers/reward/setcomment.go +++ b/internal/controllers/reward/setcomment.go @@ -6,13 +6,13 @@ import ( "coursebench-backend/pkg/errors" "coursebench-backend/pkg/models" "coursebench-backend/pkg/queries" - "strconv" "github.com/gofiber/fiber/v2" "gorm.io/gorm" ) type SetCommentRequest struct { + ID int `json:"id"` Reward int `json:"reward"` } @@ -23,12 +23,6 @@ func SetComment(c *fiber.Ctx) error { return errors.Wrap(err, errors.InvalidArgument) } - idRaw := c.Params("id", "GG") - id, err := strconv.Atoi(idRaw) - if err != nil { - return errors.New(errors.InvalidArgument) - } - uid, err := session.GetUserID(c) if err != nil { uid = 0 @@ -44,7 +38,7 @@ func SetComment(c *fiber.Ctx) error { } comment := &models.Comment{} - result := db.First(&comment, id) + result := db.First(&comment, request.ID) if result.Error != nil { return errors.Wrap(result.Error, errors.DatabaseError) } From ddd32ffa7418230660a87c239361ec466ccedf1b Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 19 May 2024 14:09:41 +0800 Subject: [PATCH 56/68] fix(controllers/reward.SetComment): save user reward --- internal/controllers/reward/setcomment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controllers/reward/setcomment.go b/internal/controllers/reward/setcomment.go index 1432127..729f2aa 100644 --- a/internal/controllers/reward/setcomment.go +++ b/internal/controllers/reward/setcomment.go @@ -51,7 +51,7 @@ func SetComment(c *fiber.Ctx) error { if err := tx.Save(comment).Error; err != nil { return err } - if err := tx.Save(user).Error; err != nil { + if err := tx.Save(&comment.User).Error; err != nil { return err } return nil From 6fe4c78dbad66cf51411f93e645910faa6f1c935 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 19 May 2024 14:06:34 +0800 Subject: [PATCH 57/68] fix(quries.Ranklist): use correct field name --- pkg/queries/reward.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/reward.go b/pkg/queries/reward.go index 655c091..c660bfc 100644 --- a/pkg/queries/reward.go +++ b/pkg/queries/reward.go @@ -16,7 +16,7 @@ func Ranklist(db *gorm.DB) ([]models.RanklistResponse, error) { var ranklist []models.RanklistResponse result := db.Model(&models.User{}). Select("nick_name", "reward", "is_anonymous"). - Order("rewards DESC"). + Order("reward DESC"). Limit(30). Scan(&ranklist) From 91abb180889db54020d27ea735dfb93676579a5f Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 19 May 2024 20:38:22 +0800 Subject: [PATCH 58/68] fix(controllers/reward.SetComment): preload User before setting reward --- internal/controllers/reward/setcomment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controllers/reward/setcomment.go b/internal/controllers/reward/setcomment.go index 729f2aa..0616e6d 100644 --- a/internal/controllers/reward/setcomment.go +++ b/internal/controllers/reward/setcomment.go @@ -38,7 +38,7 @@ func SetComment(c *fiber.Ctx) error { } comment := &models.Comment{} - result := db.First(&comment, request.ID) + result := db.Preload("User").First(&comment, request.ID) if result.Error != nil { return errors.Wrap(result.Error, errors.DatabaseError) } From a04a3f701a601eb340b761f59141744f1d09f831 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Sun, 19 May 2024 21:11:46 +0800 Subject: [PATCH 59/68] fix(queries.GetProfile): display rewards for admins --- pkg/queries/user.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index a4bdc3e..f941450 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -347,29 +347,43 @@ func GetUserByID(db *gorm.DB, id uint) (*models.User, error) { return user, nil } -// id: 被查询用户的id -// uid: 查询用户的id -// ip: 查询用户的ip -func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error) { +func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.ProfileResponse, error) { if db == nil { db = database.GetDB() } - user, err := GetUserByID(db, id) + + user, err := GetUserByID(db, queriedUserID) if err != nil { return models.ProfileResponse{}, err } + + // As written in the previous commit, administrators do not + // have access to the invitation code of users other than themselves. + var displayInvitationCode bool = queryingUserID == queriedUserID + var displayReward bool = queryingUserID == queriedUserID + + if queryingUserID != 0 && queryingUserID != queriedUserID { + queryingUser, err := GetUserByID(db, queryingUserID) + if err != nil { + return models.ProfileResponse{}, err + } + if queryingUser.IsAdmin || queryingUser.IsCommunityAdmin { + displayReward = true + } + } + avatar := "" if user.Avatar != "" { avatar = fmt.Sprintf("https://%s/%s/avatar/%s", database.GetEndpoint(), database.MinioConf.Bucket, user.Avatar) } - if user.IsAnonymous && id != uid { - return models.ProfileResponse{ID: id, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil + if user.IsAnonymous && queryingUserID != queriedUserID { + return models.ProfileResponse{ID: user.ID, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil } else { - r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin} - if id == uid { + r := models.ProfileResponse{ID: user.ID, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin} + if displayInvitationCode { r.InvitationCode = user.InvitationCode } - if id == uid || user.IsAdmin || user.IsCommunityAdmin { + if displayReward { r.Reward = user.Reward } else { r.Reward = -1 From a17223efcc315e15507d5c9baccf4194b5395382 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Mon, 20 May 2024 11:06:00 +0800 Subject: [PATCH 60/68] style(queries.GetProfile): fix style --- pkg/queries/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index f941450..deac4fe 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -359,7 +359,7 @@ func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.Pr // As written in the previous commit, administrators do not // have access to the invitation code of users other than themselves. - var displayInvitationCode bool = queryingUserID == queriedUserID + displayInvitationCode := queryingUserID == queriedUserID var displayReward bool = queryingUserID == queriedUserID if queryingUserID != 0 && queryingUserID != queriedUserID { From f9e4c250a4944e6115aa06e98ee9d93ac8d76005 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Mon, 20 May 2024 11:06:12 +0800 Subject: [PATCH 61/68] style(queries.GetProfile): fix style --- pkg/queries/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index deac4fe..d44b14c 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -360,7 +360,7 @@ func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.Pr // As written in the previous commit, administrators do not // have access to the invitation code of users other than themselves. displayInvitationCode := queryingUserID == queriedUserID - var displayReward bool = queryingUserID == queriedUserID + displayReward := queryingUserID == queriedUserID if queryingUserID != 0 && queryingUserID != queriedUserID { queryingUser, err := GetUserByID(db, queryingUserID) From 89c002350c937a0da9d1c764d889f9c89508c72a Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Mon, 20 May 2024 11:09:49 +0800 Subject: [PATCH 62/68] docs(queries.GetProfile): rm ref to old commits --- pkg/queries/user.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index d44b14c..2358b19 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -357,8 +357,6 @@ func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.Pr return models.ProfileResponse{}, err } - // As written in the previous commit, administrators do not - // have access to the invitation code of users other than themselves. displayInvitationCode := queryingUserID == queriedUserID displayReward := queryingUserID == queriedUserID From ab3e9052ff8a30e5fa15264862d4eae5a41ab3fc Mon Sep 17 00:00:00 2001 From: Hengyu Ai <47201556+AstatineAi@users.noreply.github.com> Date: Mon, 20 May 2024 19:49:40 +0800 Subject: [PATCH 63/68] docs(queries.GetProfile): add comment on query condition Co-authored-by: Sizhe Zhao --- pkg/queries/user.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 2358b19..74c1672 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -360,6 +360,7 @@ func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.Pr displayInvitationCode := queryingUserID == queriedUserID displayReward := queryingUserID == queriedUserID + // don't query if not logged in if queryingUserID != 0 && queryingUserID != queriedUserID { queryingUser, err := GetUserByID(db, queryingUserID) if err != nil { From babc0cf9473eecfec51841ffd43b7c9475288e91 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Wed, 22 May 2024 10:47:18 +0000 Subject: [PATCH 64/68] fix(queries.Ranklist): fetch data with Find --- pkg/queries/reward.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queries/reward.go b/pkg/queries/reward.go index c660bfc..0a3b10f 100644 --- a/pkg/queries/reward.go +++ b/pkg/queries/reward.go @@ -18,7 +18,7 @@ func Ranklist(db *gorm.DB) ([]models.RanklistResponse, error) { Select("nick_name", "reward", "is_anonymous"). Order("reward DESC"). Limit(30). - Scan(&ranklist) + Find(&ranklist) for i := range ranklist { if ranklist[i].IsAnonymous { From 207a8e6ab44b10924dfcedbc6a2a5cebe9b35a14 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Wed, 22 May 2024 14:28:30 +0000 Subject: [PATCH 65/68] fix(pkg/models.User): set default reward --- pkg/models/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/models/user.go b/pkg/models/user.go index 9087084..3451560 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -46,7 +46,7 @@ type User struct { IsCommunityAdmin bool `gorm:"default:false"` InvitationCode string InvitedByUserID uint - Reward int + Reward int `gorm:"default:0"` HasPostedComments bool `gorm:"default:false"` } From 10839f08fc4d1b429fdeb029568f3e0e98872d47 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Wed, 22 May 2024 15:05:12 +0000 Subject: [PATCH 66/68] feat(database/upgrade.UpgradeDBFrom3To4): set default for user reward --- pkg/database/upgrade/upgrade.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/database/upgrade/upgrade.go b/pkg/database/upgrade/upgrade.go index 3052041..9fd2ca6 100644 --- a/pkg/database/upgrade/upgrade.go +++ b/pkg/database/upgrade/upgrade.go @@ -22,6 +22,7 @@ import ( "coursebench-backend/pkg/log" "coursebench-backend/pkg/models" "coursebench-backend/pkg/queries" + "gorm.io/gorm" ) @@ -48,7 +49,11 @@ func UpgradeDB() { case 2: log.Println("Upgrading database version from 2 to 3...") UpgradeDBFrom2To3() + fallthrough case 3: + log.Println("Upgrading database version from 3 to 4...") + UpgradeDBFrom3To4() + case 4: default: log.Panicf("The version of database is: %d, which is newer than the backend.", metadata.DBVersion) } @@ -106,3 +111,17 @@ func UpgradeDBFrom2To3() { log.Panicln(err) } } + +func UpgradeDBFrom3To4() { + db := database.GetDB() + err := db.Transaction(func(tx *gorm.DB) error { + err := tx.Model(&models.User{}).Where("reward is null").Update("reward", 0).Error + if err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + return nil + }) + if err != nil { + log.Panicln(err) + } +} From ed23695f92cce953a7f4085540ad5a420cd71a83 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Thu, 23 May 2024 15:50:42 +0800 Subject: [PATCH 67/68] fix(queries.GetProfile): set reward in profile response to anonymous user to -1 --- pkg/queries/user.go | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 74c1672..6528523 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -375,20 +375,33 @@ func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.Pr if user.Avatar != "" { avatar = fmt.Sprintf("https://%s/%s/avatar/%s", database.GetEndpoint(), database.MinioConf.Bucket, user.Avatar) } - if user.IsAnonymous && queryingUserID != queriedUserID { - return models.ProfileResponse{ID: user.ID, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil + r := models.ProfileResponse{ + ID: user.ID, + NickName: user.NickName, + Avatar: avatar, + IsAnonymous: user.IsAnonymous, + IsAdmin: user.IsAdmin, + IsCommunityAdmin: user.IsCommunityAdmin, + } + + if !user.IsAnonymous || queryingUserID == queriedUserID { + r.Email = user.Email + r.Year = user.Year + r.Grade = user.Grade + r.RealName = user.RealName + } + + if displayInvitationCode { + r.InvitationCode = user.InvitationCode + } + + if displayReward { + r.Reward = user.Reward } else { - r := models.ProfileResponse{ID: user.ID, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin} - if displayInvitationCode { - r.InvitationCode = user.InvitationCode - } - if displayReward { - r.Reward = user.Reward - } else { - r.Reward = -1 - } - return r, nil + r.Reward = -1 } + + return r, nil } func CheckYear(year int) bool { From 7b708582fe273b9f6b4d5ddcd6bd718443391b56 Mon Sep 17 00:00:00 2001 From: Hengyu Ai Date: Wed, 29 May 2024 23:03:00 +0800 Subject: [PATCH 68/68] fix(queries.Register): reward inviter after checking email availability --- pkg/queries/user.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/queries/user.go b/pkg/queries/user.go index 6528523..f52f714 100644 --- a/pkg/queries/user.go +++ b/pkg/queries/user.go @@ -117,22 +117,6 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { return errors.New(errors.InvalidArgument) } - // check if the invitation code is valid - if invitation_code != "" { - inviter, err := GetUserByInvitationCode(db, invitation_code) - if err != nil { - if errors.Is(err, errors.UserNotExists) { - return errors.New(errors.InvitationCodeInvalid) - } - return err - } - - u.InvitedByUserID = inviter.ID - // TODO: only once for the inviter? - inviter.Reward += 100 - db.Save(inviter) - } - // 检查邮箱是否已存在 user := &models.User{} result := db.Where("email = ?", u.Email).Take(user) @@ -160,6 +144,23 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { } u.InvitationCode = code + // check if the invitation code is valid + if invitation_code != "" { + inviter, err := GetUserByInvitationCode(db, invitation_code) + if err != nil { + if errors.Is(err, errors.UserNotExists) { + return errors.New(errors.InvitationCodeInvalid) + } + return err + } + + u.InvitedByUserID = inviter.ID + inviter.Reward += 100 + if err = db.Select("reward").Save(inviter).Error; err != nil { + return errors.Wrap(err, errors.DatabaseError) + } + } + if err = db.Create(u).Error; err != nil { return errors.Wrap(err, errors.DatabaseError) }