Compare commits

..

No commits in common. "81c7a51256fe23ff84e70e9ca7bf283dc0761c75" and "bd305f0edf6f083326cf0d586eb2ed5b8a6513aa" have entirely different histories.

19 changed files with 21 additions and 250 deletions

View File

@ -22,7 +22,6 @@ type Subscribe struct {
type SubscribePlan struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
Code string `gorm:"not null" json:"code"`
Name string `gorm:"not null" json:"name"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

View File

@ -7,8 +7,8 @@ import (
"gorm.io/gorm"
)
func (sr *StaffRepository) GetStaffByEmail(email string) (*authdomain.Staff, error) {
var staff authdomain.Staff
func (sr *StaffRepository) GetStaffByEmail(email string) (*authdomain.LoginRepoResponse, error) {
var staff authdomain.LoginRepoResponse
if email == "" {
return nil, errors.New("email is empty")

View File

@ -10,7 +10,7 @@ type StaffRepository struct {
}
type StaffIntf interface {
GetStaffByEmail(string) (*authdomain.Staff, error)
GetStaffByEmail(string) (*authdomain.LoginRepoResponse, error)
Create(*authdomain.Staff) (*authdomain.Staff, error)
}

View File

@ -5,14 +5,13 @@ import (
"github.com/google/uuid"
)
func (s *SubsPlan) Create(spec subscribeplandomain.SubscribePlanReq) error {
data := &subscribeplandomain.SubscribePlan{
func (s *SubsPlan) Create(code string) error {
spec := &subscribeplandomain.SubscribePlan{
ID: uuid.New(),
Code: spec.Code,
Name: spec.Name,
Code: code,
}
if err := s.DB.Create(&data).Error; err != nil {
if err := s.DB.Create(&spec).Error; err != nil {
return err
}

View File

@ -1,15 +0,0 @@
package subscribeplanrepository
import (
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
)
func (s *SubsPlan) GetAll() ([]subscribeplandomain.SubscribePlan, error) {
var subscribePlans []subscribeplandomain.SubscribePlan
if err := s.DB.Find(&subscribePlans).Error; err != nil {
return nil, err
}
return subscribePlans, nil
}

View File

@ -1,17 +1,13 @@
package subscribeplanrepository
import (
"github.com/ardeman/project-legalgo-go/database"
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
)
import "github.com/ardeman/project-legalgo-go/database"
type SubsPlan struct {
DB *database.DB
}
type SubsPlanIntf interface {
Create(subscribeplandomain.SubscribePlanReq) error
GetAll() ([]subscribeplandomain.SubscribePlan, error)
Create(string) error
}
func New(

View File

@ -3,12 +3,12 @@ package userrepository
import (
"errors"
authdomain "github.com/ardeman/project-legalgo-go/internal/domain/auth"
usermodel "github.com/ardeman/project-legalgo-go/database/user"
"gorm.io/gorm"
)
func (ur *UserRepository) GetUserByEmail(email string) (*authdomain.User, error) {
var user authdomain.User
func (ur *UserRepository) GetUserByEmail(email string) (*usermodel.User, error) {
var user usermodel.User
if email == "" {
return nil, errors.New("email is empty")

View File

@ -2,6 +2,7 @@ package userrepository
import (
"github.com/ardeman/project-legalgo-go/database"
usermodel "github.com/ardeman/project-legalgo-go/database/user"
authdomain "github.com/ardeman/project-legalgo-go/internal/domain/auth"
)
@ -10,7 +11,7 @@ type UserRepository struct {
}
type UserIntf interface {
GetUserByEmail(string) (*authdomain.User, error)
GetUserByEmail(string) (*usermodel.User, error)
CreateUser(*authdomain.User) (*authdomain.User, error)
}

View File

@ -45,7 +45,7 @@ func CreateSubscribePlan(
return
}
if err := subsSvc.CreatePlan(spec); err != nil {
if err := subsSvc.CreatePlan(spec.Code); err != nil {
response.ResponseWithErrorCode(
ctx,
w,

View File

@ -1,32 +0,0 @@
package subscribeplanhttp
import (
"net/http"
subscribeplansvc "github.com/ardeman/project-legalgo-go/internal/services/subscribe_plan"
"github.com/ardeman/project-legalgo-go/internal/utilities/response"
"github.com/go-chi/chi/v5"
)
func GetAllPlan(
router chi.Router,
subsPlanSvc subscribeplansvc.SubsPlanIntf,
) {
router.Get("/subscribe-plan/get-all", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
subsPlan, err := subsPlanSvc.GetAllPlan()
if err != nil {
response.ResponseWithErrorCode(
ctx,
w,
err,
response.ErrBadRequest.Code,
response.ErrBadRequest.HttpCode,
response.ErrBadRequest.Message,
)
return
}
response.RespondJsonSuccess(ctx, w, subsPlan)
})
}

View File

@ -5,6 +5,5 @@ import "go.uber.org/fx"
var Module = fx.Module("subscribe-plan",
fx.Invoke(
CreateSubscribePlan,
GetAllPlan,
),
)

View File

@ -4,11 +4,9 @@ import "github.com/google/uuid"
type SubscribePlanReq struct {
Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"`
}
type SubscribePlan struct {
ID uuid.UUID `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}

View File

@ -7,8 +7,8 @@ import (
"github.com/ardeman/project-legalgo-go/internal/utilities/utils"
)
func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
user, err := a.userRepo.GetUserByEmail(spec.Email)
func (sv *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
user, err := sv.userRepo.GetUserByEmail(spec.Email)
if err != nil {
return "", errors.New(err.Error())
}

View File

@ -9,10 +9,6 @@ import (
)
func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error) {
_, err := a.staffRepo.GetStaffByEmail(spec.Email)
if err == nil {
return "", errors.New("this email address is already in use")
}
hashedPwd, err := HashPassword(spec.Password)
if err != nil {
return "", err

View File

@ -9,12 +9,6 @@ import (
)
func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error) {
_, err := a.userRepo.GetUserByEmail(spec.Email)
if err == nil {
return "", errors.New("this email address is already in use")
}
subsId, err := a.subsRepo.Create(spec.SubscribePlanID)
if err != nil {
return "", nil

View File

@ -1,7 +1,5 @@
package subscribeplansvc
import subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
func (sb *SubsPlanSvc) CreatePlan(spec subscribeplandomain.SubscribePlanReq) error {
return sb.subsAccs.Create(spec)
func (sb *SubsPlanSvc) CreatePlan(code string) error {
return sb.subsAccs.Create(code)
}

View File

@ -1,14 +0,0 @@
package subscribeplansvc
import (
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
)
func (s *SubsPlanSvc) GetAllPlan() ([]subscribeplandomain.SubscribePlan, error) {
subsPlan, err := s.subsAccs.GetAll()
if err != nil {
return nil, err
}
return subsPlan, nil
}

View File

@ -1,17 +1,13 @@
package subscribeplansvc
import (
subscribeplanrepository "github.com/ardeman/project-legalgo-go/internal/accessor/subscribeplan"
subscribeplandomain "github.com/ardeman/project-legalgo-go/internal/domain/subscribe_plan"
)
import subscribeplanrepository "github.com/ardeman/project-legalgo-go/internal/accessor/subscribeplan"
type SubsPlanSvc struct {
subsAccs subscribeplanrepository.SubsPlanIntf
}
type SubsPlanIntf interface {
CreatePlan(subscribeplandomain.SubscribePlanReq) error
GetAllPlan() ([]subscribeplandomain.SubscribePlan, error)
CreatePlan(string) error
}
func New(

View File

@ -1,144 +0,0 @@
openapi: 3.0.0
info:
title: Staff and User API
version: 1.0.0
description: API for handling staff and user login, registration, and subscription plan creation.
paths:
/staff/login:
post:
summary: Login for staff
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
format: email
password:
type: string
required:
- email
- password
responses:
"200":
description: Successful login
"400":
description: Bad request
/staff/register:
post:
summary: Register a new staff member
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
format: email
password:
type: string
required:
- email
- password
responses:
"201":
description: Staff member created
"400":
description: Bad request
"409":
description: Conflict (email already registered)
/user/login:
post:
summary: Login for user
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
format: email
password:
type: string
required:
- email
- password
responses:
"200":
description: Successful login
"400":
description: Bad request
/user/register:
post:
summary: Register a new user
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
format: email
password:
type: string
subscribe_plan_id:
type: string
phone:
type: string
format: phone
required:
- email
- password
- subscribe_plan_id
- phone
responses:
"201":
description: User created
"400":
description: Bad request
"409":
description: Conflict (email already registered)
/subscribe-plan/create:
post:
summary: Create a new subscription plan
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
code:
type: string
required:
- code
responses:
"201":
description: Subscription plan created
"400":
description: Bad request
"409":
description: Conflict (plan code already exists)
/subscribe-plan/get-all:
get:
summary: Get all subscription plan
responses:
"201":
description: Subscription plan created
"400":
description: Bad request