feat: models added for the notfication
This commit is contained in:
parent
63b443171d
commit
dd1d05929a
51
README.md
51
README.md
|
|
@ -1 +1,50 @@
|
|||
# FortuneBet-Backend
|
||||
# FortuneBet-Backend
|
||||
# Directory Structure
|
||||
|
||||
├── cmd
|
||||
│ ├── main.go
|
||||
├── db
|
||||
│ ├── migrations
|
||||
│ │ ├── 000001_fortune.down.sql
|
||||
│ │ ├── 000001_fortune.up.sql
|
||||
│ └── query
|
||||
│ ├── user.sql
|
||||
├── gen
|
||||
│ └── db
|
||||
│ ├── db.go
|
||||
│ ├── models.go
|
||||
│ ├── user.sql.go
|
||||
└── internal
|
||||
├── config
|
||||
│ ├── config.go
|
||||
├── domain
|
||||
│ ├── auth.go
|
||||
│ ├── notification.go
|
||||
│ ├── user.go
|
||||
├── logger
|
||||
│ ├── logger.go
|
||||
├── repository
|
||||
│ ├── store.go
|
||||
│ ├── user.go
|
||||
├── services
|
||||
│ ├── notfication
|
||||
│ │ ├── port.go
|
||||
│ │ ├── service.go
|
||||
│ └── user
|
||||
│ ├── port.go
|
||||
│ ├── service.go
|
||||
└── web_server
|
||||
└── validator
|
||||
├── validatord.go
|
||||
├── app.go
|
||||
├── app_routes.go
|
||||
├── .air.toml
|
||||
├── .gitignore
|
||||
├── README.md
|
||||
├── compose.db.yaml
|
||||
├── go.mod
|
||||
├── go.sum
|
||||
├── makefile
|
||||
├── sqlc.yaml
|
||||
|
||||
# End Directory Structure
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
CREATE TABLE users (
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
first_name VARCHAR(255) NOT NULL,
|
||||
last_name VARCHAR(255) NOT NULL,
|
||||
|
|
@ -7,6 +7,6 @@ CREATE TABLE users (
|
|||
password TEXT NOT NULL,
|
||||
role VARCHAR(50) NOT NULL,
|
||||
verified BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP ,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
created_at TIMESTAMP,
|
||||
updated_at TIMESTAMP
|
||||
);
|
||||
|
|
|
|||
1
db/migrations/000002_notification.down.sql
Normal file
1
db/migrations/000002_notification.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE notifications;
|
||||
37
db/migrations/000002_notification.up.sql
Normal file
37
db/migrations/000002_notification.up.sql
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
CREATE TABLE IF NOT EXISTS notifications (
|
||||
id VARCHAR(255) PRIMARY KEY,
|
||||
recipient_id VARCHAR(255) NOT NULL,
|
||||
type TEXT NOT NULL CHECK (
|
||||
type IN (
|
||||
'cash_out_success',
|
||||
'deposit_success',
|
||||
'bet_placed',
|
||||
'daily_report',
|
||||
'high_loss_on_bet',
|
||||
'bet_overload',
|
||||
'signup_welcome',
|
||||
'otp_sent'
|
||||
)
|
||||
),
|
||||
level TEXT NOT NULL CHECK (level IN ('info', 'error', 'warning', 'success')),
|
||||
error_severity TEXT CHECK (
|
||||
error_severity IN ('low', 'medium', 'high', 'critical', 'fatal')
|
||||
),
|
||||
reciever TEXT NOT NULL CHECK (reciever IN ('admin', 'customer')),
|
||||
is_read BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
delivery_status TEXT NOT NULL CHECK (delivery_status IN ('pending', 'sent', 'failed')),
|
||||
delivery_channel TEXT CHECK (
|
||||
delivery_channel IN ('email', 'sms', 'push', 'in-app')
|
||||
),
|
||||
payload JSONB NOT NULL,
|
||||
priority INTEGER,
|
||||
version INTEGER NOT NULL DEFAULT 0,
|
||||
timestamp TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
metadata JSONB
|
||||
);
|
||||
|
||||
CREATE INDEX idx_notifications_recipient_id ON notifications (recipient_id);
|
||||
|
||||
CREATE INDEX idx_notifications_timestamp ON notifications (timestamp);
|
||||
|
||||
CREATE INDEX idx_notifications_type ON notifications (type);
|
||||
87
internal/domain/notification.go
Normal file
87
internal/domain/notification.go
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NotificationType string
|
||||
type NotificationRecieverSide string
|
||||
type NotificationDeliveryScheme string
|
||||
type NotificationLevel string
|
||||
type NotificationErrorSeverity string
|
||||
type NotificationDeliveryStatus string
|
||||
type DeliveryChannel string
|
||||
|
||||
const (
|
||||
NotificationTypeCashOutSuccess NotificationType = "cash_out_success"
|
||||
NotificationTypeDepositSuccess NotificationType = "deposit_success"
|
||||
NotificationTypeBetPlaced NotificationType = "bet_placed"
|
||||
NotificationTypeDailyReport NotificationType = "daily_report"
|
||||
NotificationTypeHighLossOnBet NotificationType = "high_loss_on_bet"
|
||||
NotificationTypeBetOverload NotificationType = "bet_overload"
|
||||
NotificationTypeSignUpWelcome NotificationType = "signup_welcome"
|
||||
NotificationTypeOTPSent NotificationType = "otp_sent"
|
||||
|
||||
NotificationRecieverSideAdmin NotificationRecieverSide = "admin"
|
||||
NotificationRecieverSideCustomer NotificationRecieverSide = "customer"
|
||||
|
||||
NotificationDeliverySchemeBulk NotificationDeliveryScheme = "bulk"
|
||||
NotificationDeliverySchemeSingle NotificationDeliveryScheme = "single"
|
||||
|
||||
NotificationLevelInfo NotificationLevel = "info"
|
||||
NotificationLevelError NotificationLevel = "error"
|
||||
NotificationLevelWarning NotificationLevel = "warning"
|
||||
NotificationLevelSuccess NotificationLevel = "success"
|
||||
|
||||
NotificationErrorSeverityLow NotificationErrorSeverity = "low"
|
||||
NotificationErrorSeverityMedium NotificationErrorSeverity = "medium"
|
||||
NotificationErrorSeverityHigh NotificationErrorSeverity = "high"
|
||||
NotificationErrorSeverityCritical NotificationErrorSeverity = "critical"
|
||||
NotificationErrorSeverityFatal NotificationErrorSeverity = "fatal"
|
||||
|
||||
DeliveryStatusPending NotificationDeliveryStatus = "pending"
|
||||
DeliveryStatusSent NotificationDeliveryStatus = "sent"
|
||||
DeliveryStatusFailed NotificationDeliveryStatus = "failed"
|
||||
|
||||
DeliveryChannelEmail DeliveryChannel = "email"
|
||||
DeliveryChannelSMS DeliveryChannel = "sms"
|
||||
DeliveryChannelPush DeliveryChannel = "push"
|
||||
DeliveryChannelInApp DeliveryChannel = "in-app"
|
||||
)
|
||||
|
||||
type NotificationPayload struct {
|
||||
Headline string
|
||||
Message string
|
||||
Tags []string
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
ID string `json:"id"`
|
||||
RecipientID string `json:"recipient_id"`
|
||||
Type NotificationType `json:"type"`
|
||||
Level NotificationLevel `json:"level"`
|
||||
ErrorSeverity *NotificationErrorSeverity `json:"error_severity"`
|
||||
Reciever NotificationRecieverSide `json:"reciever"`
|
||||
IsRead bool `json:"is_read"`
|
||||
DeliveryStatus NotificationDeliveryStatus `json:"delivery_status,omitempty"`
|
||||
DeliveryChannel DeliveryChannel `json:"delivery_channel,omitempty"`
|
||||
Payload NotificationPayload `json:"payload"`
|
||||
Priority int `json:"priority,omitempty"`
|
||||
Version int `json:"-"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Metadata json.RawMessage `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
func (n *Notification) ToJSON() ([]byte, error) {
|
||||
return json.Marshal(n)
|
||||
}
|
||||
|
||||
func FromJSON(data []byte) (*Notification, error) {
|
||||
var n Notification
|
||||
err := json.Unmarshal(data, &n)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &n, nil
|
||||
}
|
||||
4
internal/services/notfication/port.go
Normal file
4
internal/services/notfication/port.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package notficationservice
|
||||
|
||||
type NotificationStore interface {
|
||||
}
|
||||
11
internal/services/notfication/service.go
Normal file
11
internal/services/notfication/service.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package notficationservice
|
||||
|
||||
type Service struct {
|
||||
store NotificationStore
|
||||
}
|
||||
|
||||
func New(store NotificationStore) *Service {
|
||||
return &Service{
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
26
makefile
26
makefile
|
|
@ -1,32 +1,32 @@
|
|||
include .env
|
||||
.PHONY: test
|
||||
test:
|
||||
go test ./app
|
||||
@go test ./app
|
||||
.PHONY: coverage
|
||||
coverage:
|
||||
mkdir -p coverage
|
||||
go test -coverprofile=coverage.out ./internal/... ;
|
||||
go tool cover -func=coverage.out -o coverage/coverage.txt
|
||||
@mkdir -p coverage
|
||||
@go test -coverprofile=coverage.out ./internal/...
|
||||
@go tool cover -func=coverage.out -o coverage/coverage.txt
|
||||
.PHONY: build
|
||||
build:
|
||||
go build -ldflags="-s" -o ./bin/web ./
|
||||
@go build -ldflags="-s" -o ./bin/web ./
|
||||
.PHONY: run
|
||||
run:
|
||||
echo "Running Go application"; \
|
||||
go run ./cmd/main.go
|
||||
@echo "Running Go application"
|
||||
@go run ./cmd/main.go
|
||||
.PHONY: air
|
||||
air:
|
||||
echo "Running air"; \
|
||||
air -c .air.toml
|
||||
@echo "Running air"
|
||||
@air -c .air.toml
|
||||
.PHONY: migrations/up
|
||||
migrations/new:
|
||||
@echo 'Creating migration files for DB_URL'
|
||||
migrate create -seq -ext=.sql -dir=./db/migrations $(name)
|
||||
@migrate create -seq -ext=.sql -dir=./db/migrations $(name)
|
||||
.PHONY: migrations/up
|
||||
migrations/up:
|
||||
migrations/up:
|
||||
@echo 'Running up migrations...'
|
||||
migrate -path ./db/migrations -database $(DB_URL) up
|
||||
@migrate -path ./db/migrations -database $(DB_URL) up
|
||||
|
||||
.PHONY: swagger
|
||||
swagger:
|
||||
swag init -g cmd/main.go
|
||||
@swag init -g cmd/main.go
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user