Align backend company registration and notification routes with frontend
This commit is contained in:
parent
aa544426a5
commit
4544a1d5b2
3 changed files with 161 additions and 142 deletions
|
|
@ -3,21 +3,25 @@ package dto
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type CreateCompanyRequest struct {
|
type CreateCompanyRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
CompanyName string `json:"companyName"` // Alternative field name
|
CompanyName string `json:"companyName"` // Alternative field name
|
||||||
Document string `json:"document"`
|
Document string `json:"document"`
|
||||||
Contact string `json:"contact"`
|
Contact string `json:"contact"`
|
||||||
AdminEmail string `json:"admin_email"`
|
AdminEmail string `json:"admin_email"`
|
||||||
Email string `json:"email"` // Alternative field name
|
Email string `json:"email"` // Alternative field name
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
Website *string `json:"website,omitempty"`
|
Website *string `json:"website,omitempty"`
|
||||||
Address *string `json:"address,omitempty"`
|
Address *string `json:"address,omitempty"`
|
||||||
EmployeeCount *string `json:"employeeCount,omitempty"`
|
City *string `json:"city,omitempty"`
|
||||||
FoundedYear *int `json:"foundedYear,omitempty"`
|
State *string `json:"state,omitempty"`
|
||||||
Description *string `json:"description,omitempty"`
|
ZipCode *string `json:"zip_code,omitempty"`
|
||||||
YearsInMarket *string `json:"years_in_market,omitempty"`
|
EmployeeCount *string `json:"employeeCount,omitempty"`
|
||||||
BirthDate *string `json:"birth_date,omitempty"`
|
FoundedYear *int `json:"foundedYear,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
YearsInMarket *string `json:"years_in_market,omitempty"`
|
||||||
|
BirthDate *string `json:"birth_date,omitempty"`
|
||||||
|
AdminBirthDate *string `json:"admin_birth_date,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompanyResponse struct {
|
type CompanyResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ func NewCreateCompanyUseCase(cRepo ports.CompanyRepository, uRepo ports.UserRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uc *CreateCompanyUseCase) Execute(ctx context.Context, input dto.CreateCompanyRequest) (*dto.CompanyResponse, error) {
|
func (uc *CreateCompanyUseCase) Execute(ctx context.Context, input dto.CreateCompanyRequest) (*dto.CompanyResponse, error) {
|
||||||
|
if input.Name == "" && input.CompanyName != "" {
|
||||||
|
input.Name = input.CompanyName
|
||||||
|
}
|
||||||
|
|
||||||
// 0. Sanitize inputs
|
// 0. Sanitize inputs
|
||||||
sanitizer := utils.DefaultSanitizer()
|
sanitizer := utils.DefaultSanitizer()
|
||||||
input.Name = sanitizer.SanitizeName(input.Name)
|
input.Name = sanitizer.SanitizeName(input.Name)
|
||||||
|
|
@ -96,10 +100,19 @@ func (uc *CreateCompanyUseCase) Execute(ctx context.Context, input dto.CreateCom
|
||||||
|
|
||||||
adminUser := entity.NewUser("", savedCompany.ID, "Admin", input.AdminEmail)
|
adminUser := entity.NewUser("", savedCompany.ID, "Admin", input.AdminEmail)
|
||||||
adminUser.PasswordHash = hashedPassword
|
adminUser.PasswordHash = hashedPassword
|
||||||
|
adminUser.Address = input.Address
|
||||||
|
adminUser.City = input.City
|
||||||
|
adminUser.State = input.State
|
||||||
|
adminUser.ZipCode = input.ZipCode
|
||||||
|
|
||||||
if input.BirthDate != nil {
|
birthDate := input.BirthDate
|
||||||
|
if birthDate == nil {
|
||||||
|
birthDate = input.AdminBirthDate
|
||||||
|
}
|
||||||
|
|
||||||
|
if birthDate != nil {
|
||||||
layout := "2006-01-02"
|
layout := "2006-01-02"
|
||||||
if parsed, err := time.Parse(layout, *input.BirthDate); err == nil {
|
if parsed, err := time.Parse(layout, *birthDate); err == nil {
|
||||||
adminUser.BirthDate = &parsed
|
adminUser.BirthDate = &parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,8 @@ func NewRouter() http.Handler {
|
||||||
notificationHandler := handlers.NewNotificationHandler(notificationService)
|
notificationHandler := handlers.NewNotificationHandler(notificationService)
|
||||||
mux.Handle("PUT /api/v1/notifications/read-all", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAllAsRead)))
|
mux.Handle("PUT /api/v1/notifications/read-all", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAllAsRead)))
|
||||||
mux.Handle("PUT /api/v1/notifications/{id}/read", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAsRead)))
|
mux.Handle("PUT /api/v1/notifications/{id}/read", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAsRead)))
|
||||||
|
mux.Handle("PATCH /api/v1/notifications/read-all", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAllAsRead)))
|
||||||
|
mux.Handle("PATCH /api/v1/notifications/{id}/read", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.MarkAsRead)))
|
||||||
mux.Handle("POST /api/v1/notifications/fcm-token", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.RegisterFCMToken)))
|
mux.Handle("POST /api/v1/notifications/fcm-token", authMiddleware.HeaderAuthGuard(http.HandlerFunc(notificationHandler.RegisterFCMToken)))
|
||||||
|
|
||||||
// Swagger Route - available at /docs
|
// Swagger Route - available at /docs
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue