Skip to content

Commit

Permalink
Merge branch 'main' into feat/teacher
Browse files Browse the repository at this point in the history
# Conflicts:
#	cmd/migrate/migrate.go
#	handler/auth.go
#	repository/course.go
#	repository/teacher.go
  • Loading branch information
dujiajun committed Aug 15, 2024
2 parents a31ff56 + 5ff2586 commit e1a2da1
Show file tree
Hide file tree
Showing 30 changed files with 669 additions and 32 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout 3m --verbose
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gocyclo
- gofmt
- goimports
fast: true
10 changes: 4 additions & 6 deletions cmd/import_from_jwc/import_from_jwc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
pinyin2 "github.com/mozillazg/go-pinyin"
"gorm.io/gorm"
"gorm.io/gorm/clause"

"jcourse_go/dal"
"jcourse_go/model/po"
)
Expand Down Expand Up @@ -39,7 +40,9 @@ func initDB() {

func readRawCSV(filename string) [][]string {
fs, err := os.Open(filename)
defer fs.Close()
defer func(fs *os.File) {
_ = fs.Close()
}(fs)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -229,7 +232,6 @@ func queryAllTeacher() {
teacherKeyMap[makeTeacherKey(teacher.Code)] = teacher
teacherIDMap[teacher.ID] = teacher
}
return
}

func parseCourseFromLine(line []string) po.CoursePO {
Expand Down Expand Up @@ -263,7 +265,6 @@ func queryAllCourse() {
courseKeyMap[makeCourseKey(course.Code, course.MainTeacherName)] = course
courseIDMap[course.ID] = course
}
return
}

func parseOfferedCourseFromLine(line []string) po.OfferedCoursePO {
Expand Down Expand Up @@ -297,7 +298,6 @@ func queryAllOfferedCourse() {
offeredCourseIDMap[offeredCourse.ID] = offeredCourse
offeredCourseKeyMap[makeOfferedCourseKey(offeredCourse.CourseID, offeredCourse.Semester)] = offeredCourse
}
return
}

func parseOfferedCourseTeacherGroup(line []string) []po.OfferedCourseTeacherPO {
Expand Down Expand Up @@ -329,7 +329,6 @@ func queryAllOfferedCourseTeacherGroup() {
for _, offeredCourseTeacher := range offeredCourseTeachers {
offeredCourseTeacherKeyMap[makeOfferedCourseTeacherKey(offeredCourseTeacher.OfferedCourseID, offeredCourseTeacher.TeacherID)] = offeredCourseTeacher
}
return
}

func parseCourseCategories(line []string) []po.CourseCategoryPO {
Expand Down Expand Up @@ -364,7 +363,6 @@ func queryAllCourseCategory() {
}
courseCategoryMap[makeCourseCategoryKey(int64(course.ID), courseCategory.Category)] = courseCategory
}
return
}

func generatePinyin(name string) string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/migrate/migrate.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/joho/godotenv"

"jcourse_go/dal"
"jcourse_go/model/po"

"github.com/joho/godotenv"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion dal/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"log"
"os"

"jcourse_go/util"

"github.com/DATA-DOG/go-sqlmock"
_ "github.com/lib/pq"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"jcourse_go/util"
)

var dbClient *gorm.DB
Expand Down
35 changes: 35 additions & 0 deletions handler/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package handler

import (
"jcourse_go/model/domain"
"jcourse_go/model/dto"
"jcourse_go/service"
"net/http"

"github.com/gin-gonic/gin"
)

func AdminGetUserList(c *gin.Context) {
var request dto.UserListRequest
if err := c.ShouldBindQuery(&request); err != nil {
c.JSON(http.StatusBadRequest, dto.BaseResponse{Message: "参数错误"})
return
}

filter := domain.UserFilter{
Page: request.Page,
PageSize: request.PageSize,
}
users, err := service.AdminGetUserList(c, filter)
if err != nil {
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误。"})
}
total, _ := service.GetUserCount(c, filter)
response := dto.UserListResponseForAdmin{
Page: request.Page,
PageSize: request.PageSize,
Total: total,
Data: users,
}
c.JSON(http.StatusOK, response)
}
6 changes: 3 additions & 3 deletions handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"errors"
"net/http"

"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"

"jcourse_go/constant"
"jcourse_go/model/domain"
"jcourse_go/model/dto"
"jcourse_go/service"

"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"
)

func LoginHandler(c *gin.Context) {
Expand Down
5 changes: 5 additions & 0 deletions handler/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/gin-gonic/gin"

"jcourse_go/constant"
"jcourse_go/model/converter"
"jcourse_go/model/domain"
Expand Down Expand Up @@ -85,6 +86,10 @@ func GetCourseListHandler(c *gin.Context) {
return
}
total, err := service.GetCourseCount(c, filter)
if err != nil {
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误。"})
return
}

resp := dto.CourseListResponse{
Total: total,
Expand Down
10 changes: 8 additions & 2 deletions handler/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"jcourse_go/middleware"
"jcourse_go/model/converter"
"jcourse_go/model/domain"
Expand Down Expand Up @@ -48,6 +49,10 @@ func GetReviewListHandler(c *gin.Context) {
return
}
total, err := service.GetReviewCount(c, filter)
if err != nil {
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误。"})
return
}

response := dto.ReviewListResponse{
Page: request.Page,
Expand Down Expand Up @@ -96,7 +101,7 @@ func UpdateReviewHandler(c *gin.Context) {
return
}

c.JSON(http.StatusOK, dto.UpdateReviewResponse{ReviewID: request.ReviewID})
c.JSON(http.StatusOK, dto.UpdateReviewResponse{ReviewID: request.ReviewID}) // nolint: gosimple
}

func DeleteReviewHandler(c *gin.Context) {
Expand All @@ -110,7 +115,8 @@ func DeleteReviewHandler(c *gin.Context) {
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误。"})
return
}
c.JSON(http.StatusOK, dto.DeleteReviewResponse{ReviewID: request.ReviewID})

c.JSON(http.StatusOK, dto.DeleteReviewResponse{ReviewID: request.ReviewID}) // nolint: gosimple
}

func GetReviewListForCourseHandler(c *gin.Context) {}
Loading

0 comments on commit e1a2da1

Please sign in to comment.