Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Users #14

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9e96c19
Add user role
geerew Sep 9, 2024
ddef322
Tidy comments
geerew Sep 9, 2024
2e78ce6
Init of params table, model and dao
geerew Sep 9, 2024
caec054
Init of users table, model and dao
geerew Sep 9, 2024
208e75c
Rework dao generic count
geerew Sep 9, 2024
c7f797a
Rework dao generic get
geerew Sep 9, 2024
ebc7066
Rework dao generic list
geerew Sep 9, 2024
06ed1c0
Rework dao generic delete
geerew Sep 9, 2024
c651c8c
Rework dao generic process orderby
geerew Sep 9, 2024
43544d4
Rework BaseDao to hold the table name
geerew Sep 9, 2024
2b9ac5e
Rework BaseDao to hold the table name
geerew Sep 9, 2024
3ce6633
Rework BaseDao to hold the table name
geerew Sep 9, 2024
7232e02
Tidy countSelect and baseSelect
geerew Sep 10, 2024
f1f8511
Tidy dao columns
geerew Sep 10, 2024
d4fdcc2
Support rendering columns in a better way
geerew Sep 10, 2024
81c62fd
Tidy some params
geerew Sep 10, 2024
1d74121
Rework building select columns and available orderby columns
geerew Sep 11, 2024
4bad913
Tidy
geerew Sep 11, 2024
b46e430
More tiding
geerew Sep 11, 2024
6b94211
Add schema support
geerew Sep 27, 2024
7008f13
Add schema support
geerew Sep 27, 2024
8fa8854
datetime equals for simple testing
geerew Sep 27, 2024
5a82cb7
Support alias and join
geerew Sep 30, 2024
641e92b
Rename schema to db_schema and support tablemapper
geerew Oct 2, 2024
81c52b6
fix package name
geerew Oct 2, 2024
fd00f48
Centralise errors
geerew Oct 3, 2024
cd80251
Support immutable tag for updates
geerew Oct 3, 2024
31bf743
rework utils/schema
geerew Oct 18, 2024
f7c9221
A complete rework of the schema and handle relations
geerew Oct 23, 2024
13349d6
Additional errors
geerew Oct 23, 2024
0bed4cf
Rework scan_status type
geerew Oct 23, 2024
ae36228
Update go.mod
geerew Oct 23, 2024
97c619e
Tidy
geerew Oct 31, 2024
0c623cf
Rework scan status type
geerew Nov 18, 2024
5ac78cd
More errors
geerew Nov 18, 2024
e349c33
Fix asset type
geerew Nov 18, 2024
f61ff9b
More errors
geerew Nov 19, 2024
a0fe574
Rework DB
geerew Nov 19, 2024
a7d749b
Rework models to use new utils.schema
geerew Nov 19, 2024
0c368f4
Rework models to use new utils.schema
geerew Nov 19, 2024
240a742
Init of DAO
geerew Nov 19, 2024
bff3ddc
update 00002 schema
geerew Nov 19, 2024
affafc5
Allow transception
geerew Nov 22, 2024
deec678
Add NewDAO to create a new dao
geerew Nov 22, 2024
e69b41d
Rework scanner
geerew Nov 22, 2024
73932ef
Update utils
geerew Nov 22, 2024
52a84e9
add isprocessing
geerew Nov 22, 2024
fe6bc59
Rename log scanner
geerew Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- [ENHANCEMENT] Change how frequently the course availability check is run
- [ENHANCEMENT] Support for FFMPEG path
- [ENHANCEMENT] On mobile use a drawer for tags
- [ENHANCEMENT] Write a general scanning monitor util
- [ENHANCEMENT] Write a general course scanner
- Add 1 or more scans, do a bulk query for all in the list
- take a writable and update the status

Expand All @@ -33,7 +33,7 @@
- [ENHANCEMENT] Support adding categories from on the home page
- [ENHANCEMENT] Fix the difference in location of the loading icon and the error
- [ENHANCEMENT] Change from carousel to no carousel
-
- [ENHANCEMENT] Add completed and updated icons on course cards

### Courses

Expand Down Expand Up @@ -113,7 +113,6 @@

### Tags

- [ENHANCEMENT] Currently uppercase and lowercase tags are different and so uppercase are ordered first. Make them case insensitive
- [ENHANCEMENT] Analyze and optimize the DB

### Assets and Attachments
Expand Down
25 changes: 12 additions & 13 deletions api/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/geerew/off-course/daos"
"github.com/geerew/off-course/database"
Expand All @@ -34,20 +33,20 @@ type assets struct {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

type assetResponse struct {
ID string `json:"id"`
CourseID string `json:"courseId"`
Title string `json:"title"`
Prefix int `json:"prefix"`
Chapter string `json:"chapter"`
Path string `json:"path"`
Type types.Asset `json:"assetType"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID string `json:"id"`
CourseID string `json:"courseId"`
Title string `json:"title"`
Prefix int `json:"prefix"`
Chapter string `json:"chapter"`
Path string `json:"path"`
Type types.Asset `json:"assetType"`
CreatedAt types.DateTime `json:"createdAt"`
UpdatedAt types.DateTime `json:"updatedAt"`

// Progress
VideoPos int `json:"videoPos"`
Completed bool `json:"completed"`
CompletedAt time.Time `json:"completedAt"`
VideoPos int `json:"videoPos"`
Completed bool `json:"completed"`
CompletedAt types.DateTime `json:"completedAt"`

// Attachments
Attachments []*attachmentResponse `json:"attachments,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func TestAssets_ServeAsset(t *testing.T) {
coursesDao := daos.NewCourseDao(router.config.DbManager.DataDb)
assetsDao := daos.NewAssetDao(router.config.DbManager.DataDb)

require.Nil(t, coursesDao.Create(testData[0].Course))
require.Nil(t, coursesDao.Create(testData[0].Course, nil))
require.Nil(t, assetsDao.Create(testData[0].Assets[0], nil))

// Create asset
Expand Down
16 changes: 8 additions & 8 deletions api/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"database/sql"
"log/slog"
"strings"
"time"

"github.com/geerew/off-course/daos"
"github.com/geerew/off-course/database"
"github.com/geerew/off-course/models"
"github.com/geerew/off-course/utils/appFs"
"github.com/geerew/off-course/utils/pagination"
"github.com/geerew/off-course/utils/types"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/spf13/afero"
Expand All @@ -27,13 +27,13 @@ type attachments struct {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

type attachmentResponse struct {
ID string `json:"id"`
AssetId string `json:"assetId"`
CourseID string `json:"courseId"`
Title string `json:"title"`
Path string `json:"path"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID string `json:"id"`
AssetId string `json:"assetId"`
CourseID string `json:"courseId"`
Title string `json:"title"`
Path string `json:"path"`
CreatedAt types.DateTime `json:"createdAt"`
UpdatedAt types.DateTime `json:"updatedAt"`
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
44 changes: 22 additions & 22 deletions api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/url"
"os"
"strings"
"time"

"github.com/Masterminds/squirrel"
"github.com/geerew/off-course/daos"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/geerew/off-course/utils/appFs"
"github.com/geerew/off-course/utils/jobs"
"github.com/geerew/off-course/utils/pagination"
"github.com/geerew/off-course/utils/types"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/spf13/afero"
Expand All @@ -41,23 +41,23 @@ type courses struct {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

type courseResponse struct {
ID string `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
HasCard bool `json:"hasCard"`
Available bool `json:"available"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID string `json:"id"`
Title string `json:"title"`
Path string `json:"path"`
HasCard bool `json:"hasCard"`
Available bool `json:"available"`
CreatedAt types.DateTime `json:"createdAt"`
UpdatedAt types.DateTime `json:"updatedAt"`

// Scan status
ScanStatus string `json:"scanStatus"`

// Progress
Started bool `json:"started"`
StartedAt time.Time `json:"startedAt"`
Percent int `json:"percent"`
CompletedAt time.Time `json:"completedAt"`
ProgressUpdatedAt time.Time `json:"progressUpdatedAt"`
Started bool `json:"started"`
StartedAt types.DateTime `json:"startedAt"`
Percent int `json:"percent"`
CompletedAt types.DateTime `json:"completedAt"`
ProgressUpdatedAt types.DateTime `json:"progressUpdatedAt"`
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -116,7 +116,7 @@ func (api *courses) getCourses(c *fiber.Ctx) error {
return errorResponse(c, fiber.StatusBadRequest, "Invalid tags parameter", err)
}

courseIds, err := api.courseTagDao.ListCourseIdsByTags(filtered, nil)
courseIds, err := api.courseTagDao.ListCourseIdsByTags(filtered, nil, nil)
if err != nil {
return errorResponse(c, fiber.StatusInternalServerError, "Error looking up courses by tags", err)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (api *courses) getCourses(c *fiber.Ctx) error {
func (api *courses) getCourse(c *fiber.Ctx) error {
id := c.Params("id")

course, err := api.courseDao.Get(id, nil, nil)
course, err := api.courseDao.Get(id, nil)

if err != nil {
if err == sql.ErrNoRows {
Expand Down Expand Up @@ -209,7 +209,7 @@ func (api *courses) createCourse(c *fiber.Ctx) error {
// Set the course to available
course.Available = true

if err := api.courseDao.Create(course); err != nil {
if err := api.courseDao.Create(course, nil); err != nil {
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
return errorResponse(c, fiber.StatusBadRequest, "A course with this path already exists", err)
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (api *courses) deleteCourse(c *fiber.Ctx) error {
func (api *courses) getCard(c *fiber.Ctx) error {
id := c.Params("id")

course, err := api.courseDao.Get(id, nil, nil)
course, err := api.courseDao.Get(id, nil)

if err != nil {
if err == sql.ErrNoRows {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (api *courses) getAssets(c *fiber.Ctx) error {
expand := c.QueryBool("expand", false)

// Get the course
_, err := api.courseDao.Get(id, nil, nil)
_, err := api.courseDao.Get(id, nil)
if err != nil {
if err == sql.ErrNoRows {
return errorResponse(c, fiber.StatusNotFound, "Course not found", nil)
Expand Down Expand Up @@ -316,7 +316,7 @@ func (api *courses) getAsset(c *fiber.Ctx) error {
assetId := c.Params("asset")
expand := c.QueryBool("expand", false)

_, err := api.courseDao.Get(id, nil, nil)
_, err := api.courseDao.Get(id, nil)
if err != nil {
if err == sql.ErrNoRows {
return errorResponse(c, fiber.StatusNotFound, "Course not found", nil)
Expand Down Expand Up @@ -356,7 +356,7 @@ func (api *courses) getAssetAttachments(c *fiber.Ctx) error {
orderBy := c.Query("orderBy", "title asc")

// Get the course
_, err := api.courseDao.Get(id, nil, nil)
_, err := api.courseDao.Get(id, nil)
if err != nil {
if err == sql.ErrNoRows {
return errorResponse(c, fiber.StatusNotFound, "Course not found", nil)
Expand Down Expand Up @@ -406,7 +406,7 @@ func (api *courses) getAssetAttachment(c *fiber.Ctx) error {
attachmentId := c.Params("attachment")

// Get the course
_, err := api.courseDao.Get(id, nil, nil)
_, err := api.courseDao.Get(id, nil)
if err != nil {
if err == sql.ErrNoRows {
return errorResponse(c, fiber.StatusNotFound, "Course not found", nil)
Expand Down Expand Up @@ -452,7 +452,7 @@ func (api *courses) getTags(c *fiber.Ctx) error {
id := c.Params("id")

// Get the course
_, err := api.courseDao.Get(id, nil, nil)
_, err := api.courseDao.Get(id, nil)
if err != nil {
if err == sql.ErrNoRows {
return errorResponse(c, fiber.StatusNotFound, "Course not found", nil)
Expand Down
2 changes: 1 addition & 1 deletion api/courses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func TestCourses_DeleteCourse(t *testing.T) {
require.NoError(t, err)
require.Equal(t, http.StatusNoContent, status)

_, err = courseDao.Get(testData[2].ID, nil, nil)
_, err = courseDao.Get(testData[2].ID, nil)
require.ErrorIs(t, err, sql.ErrNoRows)

// ----------------------------
Expand Down
11 changes: 5 additions & 6 deletions api/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"log/slog"
"time"

"github.com/Masterminds/squirrel"
"github.com/geerew/off-course/daos"
Expand All @@ -23,11 +22,11 @@ type logs struct {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

type logResponse struct {
ID string `json:"id"`
Level int `json:"level"`
Message string `json:"message"`
Data types.JsonMap `json:"data"`
CreatedAt time.Time `json:"createdAt"`
ID string `json:"id"`
Level int `json:"level"`
Message string `json:"message"`
Data types.JsonMap `json:"data"`
CreatedAt types.DateTime `json:"createdAt"`
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 2 additions & 3 deletions api/scans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"database/sql"
"log/slog"
"time"

"github.com/geerew/off-course/daos"
"github.com/geerew/off-course/models"
Expand All @@ -28,8 +27,8 @@ type scanResponse struct {
ID string `json:"id"`
CourseID string `json:"courseId"`
Status types.ScanStatus `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
CreatedAt types.DateTime `json:"createdAt"`
UpdatedAt types.DateTime `json:"updatedAt"`
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
14 changes: 7 additions & 7 deletions api/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"net/url"
"sort"
"strings"
"time"

"github.com/Masterminds/squirrel"
"github.com/geerew/off-course/daos"
"github.com/geerew/off-course/database"
"github.com/geerew/off-course/models"
"github.com/geerew/off-course/utils/pagination"
"github.com/geerew/off-course/utils/types"
"github.com/gofiber/fiber/v2"
)

Expand All @@ -27,12 +27,12 @@ type tags struct {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

type tagResponse struct {
ID string `json:"id"`
Tag string `json:"tag"`
CourseCount int `json:"courseCount"`
Courses []*courseTag `json:"courses,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID string `json:"id"`
Tag string `json:"tag"`
CourseCount int `json:"courseCount"`
Courses []*courseTag `json:"courses,omitempty"`
CreatedAt types.DateTime `json:"createdAt"`
UpdatedAt types.DateTime `json:"updatedAt"`
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 4 additions & 4 deletions cron/course_availability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestCourseAvailability_Run(t *testing.T) {
require.Nil(t, err)

// Check the course is marked as unavailable
course, err := daos.NewCourseDao(dbManager.DataDb).Get(testData[0].Course.ID, nil, nil)
course, err := daos.NewCourseDao(dbManager.DataDb).Get(testData[0].Course.ID, nil)
require.Nil(t, err)
require.False(t, course.Available)

Expand All @@ -53,7 +53,7 @@ func TestCourseAvailability_Run(t *testing.T) {
require.Nil(t, err)

// Check the course is marked as available
course, err = daos.NewCourseDao(dbManager.DataDb).Get(testData[0].Course.ID, nil, nil)
course, err = daos.NewCourseDao(dbManager.DataDb).Get(testData[0].Course.ID, nil)
require.Nil(t, err)
require.True(t, course.Available)
})
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestCourseAvailability_Run(t *testing.T) {

// Check the courses are marked as unavailable
for _, data := range testData {
course, err := daos.NewCourseDao(dbManager.DataDb).Get(data.Course.ID, nil, nil)
course, err := daos.NewCourseDao(dbManager.DataDb).Get(data.Course.ID, nil)
require.Nil(t, err)
require.False(t, course.Available)
}
Expand All @@ -104,7 +104,7 @@ func TestCourseAvailability_Run(t *testing.T) {

// Check the courses are marked as available
for _, data := range testData {
course, err := daos.NewCourseDao(dbManager.DataDb).Get(data.Course.ID, nil, nil)
course, err := daos.NewCourseDao(dbManager.DataDb).Get(data.Course.ID, nil)
require.Nil(t, err)
require.True(t, course.Available)
}
Expand Down
Loading