diff --git a/pkg/database/migrations/006_post_reports.sql b/pkg/database/migrations/006_post_reports.sql new file mode 100644 index 0000000..94a24d7 --- /dev/null +++ b/pkg/database/migrations/006_post_reports.sql @@ -0,0 +1,30 @@ +-- +migrate Up +CREATE TYPE ReportType AS ENUM ( + 'duplicate', + 'missing_data', + 'rating_abuse', + 'illegal_content' + ); + +CREATE TYPE ReportState AS ENUM ( + 'pending_unclaimed', + 'pending', + 'approved', + 'partial', + 'rejected' + ); + +CREATE TABLE "PostReport" +( + id CHAR(25) NOT NULL PRIMARY KEY, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + deleted_at TIMESTAMP WITH TIME ZONE NULL, + post_id CHAR(25) NOT NULL REFERENCES "Post" (id), + report_by TEXT NOT NULL REFERENCES "User" (id), + report_description TEXT NOT NULL, + audit_by TEXT NULL REFERENCES "User" (id), + audit_description TEXT NOT NULL, + report_type ReportType NOT NULL, + report_state ReportState NOT NULL +); \ No newline at end of file diff --git a/pkg/database/post_report.go b/pkg/database/post_report.go new file mode 100644 index 0000000..33992ca --- /dev/null +++ b/pkg/database/post_report.go @@ -0,0 +1,173 @@ +package database + +import ( + "context" + "errors" + + "git.anthrove.art/Anthrove/otter-space-sdk/v4/internal/utils" + otterError "git.anthrove.art/Anthrove/otter-space-sdk/v4/pkg/error" + "git.anthrove.art/Anthrove/otter-space-sdk/v4/pkg/models" + log "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel/attribute" + "gorm.io/gorm" +) + +func CreatePostReport(ctx context.Context, postReport models.PostReport) (models.PostReport, error) { + ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreatePostReport") + defer span.End() + + localLogger = localLogger.WithFields(log.Fields{ + "post_report_id": postReport.ID, + }) + + span.SetAttributes( + attribute.String("post_report_id", string(postReport.ID)), + ) + + utils.HandleEvent(span, localLogger, "Starting postReport creation") + + if client == nil { + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) + } + + result := client.WithContext(ctx).Create(&postReport) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrDuplicatedKey) { + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DuplicateKey}) + } + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, result.Error) + } + + utils.HandleEvent(span, localLogger, "Post createdReport successfully") + return postReport, nil +} + +func GetPostReportByID(ctx context.Context, id models.PostReportID) (models.PostReport, error) { + ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetPostReportByID") + defer span.End() + + localLogger = localLogger.WithFields(log.Fields{ + "post_report_id": id, + }) + + span.SetAttributes( + attribute.String("post_report_id", string(id)), + ) + + utils.HandleEvent(span, localLogger, "Starting get postReport by ID") + + var postReport models.PostReport + + if client == nil { + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) + } + + if len(id) == 0 { + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostReportIDIsEmpty}) + } + + if len(id) != 25 { + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostReportIDIsWrongLength}) + } + + result := client.WithContext(ctx).First(&postReport, "id = ?", id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) + } + return models.PostReport{}, utils.HandleError(ctx, span, localLogger, result.Error) + } + + utils.HandleEvent(span, localLogger, "PostReport retrieved successfully") + return postReport, nil +} + +// UpdatePostReport updates the PostReport information in the database. +// Only a few parameter can be updated: +// - AuditBy +// - AuditDescription +// - ReportType +// - ReportState +func UpdatePostReport(ctx context.Context, postReport models.PostReport) error { + ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdatePostReport") + defer span.End() + + localLogger = localLogger.WithFields(log.Fields{ + "post_report_id": postReport.ID, + }) + + span.SetAttributes( + attribute.String("post_report_id", string(postReport.ID)), + ) + + utils.HandleEvent(span, localLogger, "Starting postReport update") + + if client == nil { + return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) + } + + if len(postReport.ID) == 0 { + return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostIDIsEmpty}) + } + + updatePost := models.PostReport{ + BaseModel: models.BaseModel[models.PostReportID]{ + ID: postReport.ID, + }, + AuditBy: postReport.AuditBy, + AuditDescription: postReport.AuditDescription, + ReportType: postReport.ReportType, + ReportState: postReport.ReportState, + } + + result := client.WithContext(ctx).Model(&updatePost).Updates(updatePost) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) + } + return utils.HandleError(ctx, span, localLogger, result.Error) + } + + utils.HandleEvent(span, localLogger, "PostReport updated successfully") + return nil +} + +func DeletePostReport(ctx context.Context, id models.PostReportID) error { + ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePostReport") + defer span.End() + + localLogger = localLogger.WithFields(log.Fields{ + "post_report_id": id, + }) + + span.SetAttributes( + attribute.String("post_report_id", string(id)), + ) + + utils.HandleEvent(span, localLogger, "Starting delete postReport") + + var postReport models.PostReport + + if client == nil { + return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) + } + + if len(id) == 0 { + return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostReportIDIsEmpty}) + } + + if len(id) != 25 { + return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostReportIDIsWrongLength}) + } + + result := client.WithContext(ctx).Delete(&postReport, "id = ?", id) + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) + } + return utils.HandleError(ctx, span, localLogger, result.Error) + } + + utils.HandleEvent(span, localLogger, "PostReport deleted successfully") + return nil +} diff --git a/pkg/database/post_report_test.go b/pkg/database/post_report_test.go new file mode 100644 index 0000000..de0a5df --- /dev/null +++ b/pkg/database/post_report_test.go @@ -0,0 +1,507 @@ +package database + +import ( + "context" + "fmt" + "reflect" + "testing" + "time" + + "git.anthrove.art/Anthrove/otter-space-sdk/v4/pkg/models" + "git.anthrove.art/Anthrove/otter-space-sdk/v4/test" + "go.opentelemetry.io/contrib/bridges/otellogrus" + "go.opentelemetry.io/otel" + "gorm.io/gorm" +) + +func TestCreatePostReport(t *testing.T) { + // Setup trow away container + ctx := context.Background() + container, gormDB, err := test.StartPostgresContainer(ctx) + if err != nil { + logger.Fatalf("Could not start PostgreSQL container: %v", err) + } + + client = gormDB + + // Setup open telemetry + tracer = otel.Tracer(tracingName) + + hook := otellogrus.NewHook(tracingName) + logger.AddHook(hook) + + defer container.Terminate(ctx) + + // -- -- Setup Tests + + // -- Create Post to test with + validPost := models.Post{ + BaseModel: models.BaseModel[models.PostID]{ + ID: models.PostID(fmt.Sprintf("%025s", "Post1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + Rating: models.SFW, + } + + validPost, err = CreatePost(ctx, validPost) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // Setup Tests + validUser01 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User1"))}} + validUser01, err = CreateUser(ctx, validUser01) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + validUser02 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User2"))}} + validUser02, err = CreateUser(ctx, validUser02) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- Create PostReport to test with + validPostReport := models.PostReport{ + BaseModel: models.BaseModel[models.PostReportID]{ + ID: models.PostReportID(fmt.Sprintf("%025s", "PostReport1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + PostID: validPost.ID, + ReportBy: validUser01.ID, + ReportDescription: "aaa", + AuditBy: &validUser02.ID, + AuditDescription: "ahaa", + ReportType: models.Duplicate, + ReportState: models.Rejected, + } + // -- + + // -- -- Tests + type args struct { + ctx context.Context + source models.PostReport + } + tests := []struct { + name string + args args + want models.PostReport + wantErr bool + }{ + { + name: "Test 01: Valid PostReport", + args: args{ + ctx: ctx, + source: validPostReport, + }, + want: validPostReport, + wantErr: false, + }, + { + name: "Test 02: Duplicate PostReport", + args: args{ + ctx: ctx, + source: validPostReport, + }, + want: models.PostReport{}, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := CreatePostReport(tt.args.ctx, tt.args.source) + if (err != nil) != tt.wantErr { + t.Errorf("CreatePostReport() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatePostReport() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdatePostReport(t *testing.T) { + // Setup trow away container + ctx := context.Background() + container, gormDB, err := test.StartPostgresContainer(ctx) + if err != nil { + logger.Fatalf("Could not start PostgreSQL container: %v", err) + } + + client = gormDB + + // Setup open telemetry + tracer = otel.Tracer(tracingName) + + hook := otellogrus.NewHook(tracingName) + logger.AddHook(hook) + + defer container.Terminate(ctx) + + // -- Create Post to test with + validPost := models.Post{ + BaseModel: models.BaseModel[models.PostID]{ + ID: models.PostID(fmt.Sprintf("%025s", "Post1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + Rating: models.SFW, + } + + validPost, err = CreatePost(ctx, validPost) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // Setup Tests + validUser01 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User1"))}} + validUser01, err = CreateUser(ctx, validUser01) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + validUser02 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User2"))}} + validUser02, err = CreateUser(ctx, validUser02) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- Create PostReport to test with + validPostReport := models.PostReport{ + BaseModel: models.BaseModel[models.PostReportID]{ + ID: models.PostReportID(fmt.Sprintf("%025s", "PostReport1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + PostID: validPost.ID, + ReportBy: validUser01.ID, + ReportDescription: "aaa", + AuditBy: nil, + AuditDescription: "", + ReportType: models.Duplicate, + ReportState: models.Rejected, + } + // -- + + validPostReport, err = CreatePostReport(ctx, validPostReport) + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- + + // -- Create Updates models for UserPostReport + validUpdatePostReport := validPostReport + validUpdatePostReport.AuditBy = &validUser02.ID + validUpdatePostReport.AuditDescription = "aaaaa" + validUpdatePostReport.ReportState = models.Approved + + invalidUpdatePostReport := models.PostReport{} + // -- + + // -- -- Tests + type args struct { + ctx context.Context + source models.PostReport + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "Test 01: Valid Update for PostReport", + args: args{ + ctx: ctx, + source: validUpdatePostReport, + }, + wantErr: false, + }, + { + name: "Test 02: Invalid Update for PostReport", + args: args{ + ctx: ctx, + source: invalidUpdatePostReport, + }, + wantErr: true, + }, + { + name: "Test 03: Empty ID for Update for PostReport", + args: args{ + ctx: ctx, + source: models.PostReport{BaseModel: models.BaseModel[models.PostReportID]{ID: ""}}, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdatePostReport(tt.args.ctx, tt.args.source); (err != nil) != tt.wantErr { + t.Errorf("UpdatePostReport() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestGetPostReportByID(t *testing.T) { + // Setup trow away container + ctx := context.Background() + container, gormDB, err := test.StartPostgresContainer(ctx) + if err != nil { + logger.Fatalf("Could not start PostgreSQL container: %v", err) + } + + client = gormDB + + // Setup open telemetry + tracer = otel.Tracer(tracingName) + + hook := otellogrus.NewHook(tracingName) + logger.AddHook(hook) + + defer container.Terminate(ctx) + + // -- -- Setup Tests + // -- Create Post to test with + validPost := models.Post{ + BaseModel: models.BaseModel[models.PostID]{ + ID: models.PostID(fmt.Sprintf("%025s", "Post1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + Rating: models.SFW, + } + + validPost, err = CreatePost(ctx, validPost) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // Setup Tests + validUser01 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User1"))}} + validUser01, err = CreateUser(ctx, validUser01) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + validUser02 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User2"))}} + validUser02, err = CreateUser(ctx, validUser02) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- Create PostReport to test with + validPostReport := models.PostReport{ + BaseModel: models.BaseModel[models.PostReportID]{ + ID: models.PostReportID(fmt.Sprintf("%025s", "PostReport1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + PostID: validPost.ID, + ReportBy: validUser01.ID, + ReportDescription: "aaa", + AuditBy: nil, + AuditDescription: "", + ReportType: models.Duplicate, + ReportState: models.Rejected, + } + // -- + + validPostReport, err = CreatePostReport(ctx, validPostReport) + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- + // -- + + // -- -- Tests + type args struct { + ctx context.Context + id models.PostReportID + } + tests := []struct { + name string + args args + want models.PostReport + wantErr bool + }{ + { + name: "Test 01: Valid PostReport ID", + args: args{ + ctx: ctx, + id: validPostReport.ID, + }, + want: validPostReport, + wantErr: false, + }, + { + name: "Test 03: Empty PostReportID", + args: args{ + ctx: ctx, + id: "", + }, + wantErr: true, + }, + { + name: "Test 04: Short PostReportID", + args: args{ + ctx: ctx, + id: "111", + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetPostReportByID(tt.args.ctx, tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("GetPostReportByID() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !checkPostReportID(got, tt.want) { + t.Errorf("GetPostReportByID() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDeletePostReport(t *testing.T) { + // Setup trow away container + ctx := context.Background() + container, gormDB, err := test.StartPostgresContainer(ctx) + if err != nil { + logger.Fatalf("Could not start PostgreSQL container: %v", err) + } + + client = gormDB + + // Setup open telemetry + tracer = otel.Tracer(tracingName) + + hook := otellogrus.NewHook(tracingName) + logger.AddHook(hook) + + defer container.Terminate(ctx) + + // -- -- Setup Tests + // -- Create Post to test with + validPost := models.Post{ + BaseModel: models.BaseModel[models.PostID]{ + ID: models.PostID(fmt.Sprintf("%025s", "Post1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + Rating: models.SFW, + } + + validPost, err = CreatePost(ctx, validPost) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // Setup Tests + validUser01 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User1"))}} + validUser01, err = CreateUser(ctx, validUser01) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + validUser02 := models.User{BaseModel: models.BaseModel[models.UserID]{ID: models.UserID(fmt.Sprintf("%025s", "User2"))}} + validUser02, err = CreateUser(ctx, validUser02) + + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- Create PostReport to test with + validPostReport := models.PostReport{ + BaseModel: models.BaseModel[models.PostReportID]{ + ID: models.PostReportID(fmt.Sprintf("%025s", "PostReport1")), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + PostID: validPost.ID, + ReportBy: validUser01.ID, + ReportDescription: "aaa", + AuditBy: nil, + AuditDescription: "", + ReportType: models.Duplicate, + ReportState: models.Rejected, + } + // -- + + validPostReport, err = CreatePostReport(ctx, validPostReport) + if err != nil { + t.Fatalf("CreatePostReport err: %v", err) + } + // -- + // -- + + // -- -- Tests + type args struct { + ctx context.Context + id models.PostReportID + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "Test 01: Delete Valid PostReport", + args: args{ + ctx: ctx, + id: validPostReport.ID, + }, + wantErr: false, + }, + { + name: "Test 02: Delete not existed PostReport", + args: args{ + ctx: ctx, + id: validPostReport.ID, + }, + wantErr: false, + }, + { + name: "Test 03: Empty PostReportID", + args: args{ + ctx: ctx, + id: "", + }, + wantErr: true, + }, + { + name: "Test 04: Short PostReportID", + args: args{ + ctx: ctx, + id: "111", + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := DeletePostReport(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { + t.Errorf("DeletePostReport() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func checkPostReportID(got models.PostReport, want models.PostReport) bool { + if got.ID != want.ID { + return false + } + + return true +} diff --git a/pkg/error/validation.go b/pkg/error/validation.go index ab53258..5693903 100644 --- a/pkg/error/validation.go +++ b/pkg/error/validation.go @@ -26,7 +26,7 @@ const ( UserFavoriteIsWrongLength = "userFavoriteID has the wrong length" PostListIsEmpty = "userFavoriteList cannot be empty" - PostIDIsEmpty = "userFavoriteID cannot be empty" + PostIDIsEmpty = "PostID cannot be empty" PostIDIsWrongLength = "PostID has the wrong length" BatchSizeIsEmpty = "batchSize cannot be empty" @@ -38,6 +38,9 @@ const ( ScrapeTaskIDIsEmpty = "ScrapeTaskID cannot be empty" ScrapeTaskIDIsWrongLength = "ScrapeTaskID has the wrong length, needs to be 25 characters long" + + PostReportIDIsEmpty = "PostReportID cannot be empty" + PostReportIDIsWrongLength = "PostReportID has the wrong length" ) type EntityValidationFailed struct { diff --git a/pkg/models/const.go b/pkg/models/const.go index fb7a04f..abf13d9 100644 --- a/pkg/models/const.go +++ b/pkg/models/const.go @@ -25,6 +25,10 @@ type ( UserFavoriteID string ScrapeTaskID string + + PostReportID string + ReportType string + ReportState string ) const ( @@ -50,6 +54,21 @@ const ( Copyright TagType = "copyright" ) +const ( + Duplicate ReportType = "duplicate" + MissingData ReportType = "missing_data" + RatingAbuse ReportType = "rating_abuse" + IllegalContent ReportType = "illegal_content" +) + +const ( + PendingUnclaimed ReportState = "pending_unclaimed" + Pending ReportState = "pending" + Approved ReportState = "approved" + Partial ReportState = "partial" + Rejected ReportState = "rejected" +) + func (r *Rating) Convert(e621Rating string) { switch e621Rating { case "e": diff --git a/pkg/models/orm.go b/pkg/models/orm.go index 4ce9b06..bd02ec5 100644 --- a/pkg/models/orm.go +++ b/pkg/models/orm.go @@ -8,7 +8,7 @@ import ( ) type ID interface { - UserID | SourceID | PostID | UserSourceID | UserFavoriteID | PoolID + UserID | SourceID | PostID | UserSourceID | UserFavoriteID | PoolID | PostReportID } type BaseModel[T ID] struct { diff --git a/pkg/models/postReport.go b/pkg/models/postReport.go new file mode 100644 index 0000000..fe7ea4f --- /dev/null +++ b/pkg/models/postReport.go @@ -0,0 +1,16 @@ +package models + +type PostReport struct { + BaseModel[PostReportID] + PostID PostID `json:"post_id"` + ReportBy UserID `json:"report_by"` + ReportDescription string `json:"report_description"` + AuditBy *UserID `json:"audit_by"` + AuditDescription string `json:"audit_description"` + ReportType ReportType `json:"report_type" gorm:"type:enum('duplicate','missing_data','rating_abuse','illegal_content')"` + ReportState ReportState `json:"report_state" gorm:"type:enum('pending_unclaimed', 'pending', 'approved', 'partial', 'rejected')"` +} + +func (PostReport) TableName() string { + return "PostReport" +} diff --git a/pkg/models/postReport_test.go b/pkg/models/postReport_test.go new file mode 100644 index 0000000..e7d7e03 --- /dev/null +++ b/pkg/models/postReport_test.go @@ -0,0 +1,11 @@ +package models + +import "testing" + +func TestPostReport_TableName(t *testing.T) { + postReport := PostReport{} + expectedTableName := "PostReport" + if tableName := postReport.TableName(); tableName != expectedTableName { + t.Fatalf("expected %s, but got %s", expectedTableName, tableName) + } +}