Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince213 committed Jun 29, 2024
2 parents 24bcf69 + e1bfe33 commit 2c3effa
Show file tree
Hide file tree
Showing 90 changed files with 1,768 additions and 36 deletions.
16 changes: 16 additions & 0 deletions cmd/cmd_tools/clear_userdata.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
16 changes: 16 additions & 0 deletions cmd/cmd_tools/import_course.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
16 changes: 16 additions & 0 deletions cmd/cmd_tools/import_teacher.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
16 changes: 16 additions & 0 deletions cmd/cmd_tools/main.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
16 changes: 16 additions & 0 deletions cmd/cmd_tools/set_admin.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
16 changes: 16 additions & 0 deletions cmd/coursebench-backend/main.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
16 changes: 16 additions & 0 deletions internal/config/fiber.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package config

import (
Expand Down
16 changes: 16 additions & 0 deletions internal/config/viper.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package config

import (
Expand Down
18 changes: 18 additions & 0 deletions internal/controllers/comments.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
// 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 <http://www.gnu.org/licenses/>.

package controllers

import (
"coursebench-backend/internal/controllers/comments"

"github.com/gofiber/fiber/v2"
)

Expand All @@ -14,6 +31,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)
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/comments/course.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand Down
19 changes: 18 additions & 1 deletion internal/controllers/comments/course_group.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand All @@ -6,8 +22,9 @@ import (
"coursebench-backend/pkg/database"
"coursebench-backend/pkg/errors"
"coursebench-backend/pkg/models"
"github.com/gofiber/fiber/v2"
"strconv"

"github.com/gofiber/fiber/v2"
)

func CourseGroupComment(c *fiber.Ctx) (err error) {
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/comments/cover.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/comments/delete.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/comments/fold.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/comments/like.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand Down
43 changes: 42 additions & 1 deletion internal/controllers/comments/post.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

package comments

import (
Expand All @@ -6,9 +22,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 {
Expand Down Expand Up @@ -117,6 +134,30 @@ 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
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)
}
inviter.Reward += 100
tx.Save(inviter)

return nil
})
if err != nil {
Expand Down
Loading

0 comments on commit 2c3effa

Please sign in to comment.