implemented data sources with prisma in go

This commit is contained in:
2025-01-02 13:19:55 +00:00
parent cfb0bdf9cf
commit 615e749a12
55 changed files with 1399 additions and 788 deletions
@@ -0,0 +1,28 @@
package dto
// ProjectDTO represents the data structure for transferring project data.
type ProjectDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
ClientID *string `json:"clientId"`
UserID string `json:"userId"`
CreatedAt string `json:"createdAt"` // Use ISO8601 format
UpdatedAt string `json:"updatedAt"` // Use ISO8601 format
}
// ProjectCreateDTO is used for creating a new project.
type ProjectCreateDTO struct {
Name string `json:"name"`
Description *string `json:"description"`
ClientID *string `json:"clientId"`
UserID string `json:"userId"`
}
// ProjectUpdateDTO is used for updating an existing project.
type ProjectUpdateDTO struct {
Name *string `json:"name"`
Description *string `json:"description"`
ClientID *string `json:"clientId"`
UserID *string `json:"userId"`
}
@@ -0,0 +1,25 @@
package dto
// ProjectTaskDTO represents the data structure for transferring project task data.
type ProjectTaskDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
ProjectID string `json:"projectId"`
CreatedAt string `json:"createdAt"` // Use ISO8601 format
UpdatedAt string `json:"updatedAt"` // Use ISO8601 format
}
// ProjectTaskCreateDTO is used for creating a new project task.
type ProjectTaskCreateDTO struct {
Name string `json:"name"`
Description *string `json:"description"`
ProjectID string `json:"projectId"`
}
// ProjectTaskUpdateDTO is used for updating an existing project task.
type ProjectTaskUpdateDTO struct {
Name *string `json:"name"`
Description *string `json:"description"`
ProjectID *string `json:"projectId"`
}
@@ -0,0 +1,31 @@
package dto
// TimeEntryDTO represents the data structure for transferring time entry data.
type TimeEntryDTO struct {
ID string `json:"id"`
StartTime string `json:"startTime"` // Use ISO8601 format
EndTime *string `json:"endTime"` // Use ISO8601 format
Description *string `json:"description"`
UserID string `json:"userId"`
ProjectID string `json:"projectId"`
CreatedAt string `json:"createdAt"` // Use ISO8601 format
UpdatedAt string `json:"updatedAt"` // Use ISO8601 format
}
// TimeEntryCreateDTO is used for creating a new time entry.
type TimeEntryCreateDTO struct {
StartTime string `json:"startTime"` // Use ISO8601 format
EndTime *string `json:"endTime"` // Use ISO8601 format
Description *string `json:"description"`
UserID string `json:"userId"`
ProjectID string `json:"projectId"`
}
// TimeEntryUpdateDTO is used for updating an existing time entry.
type TimeEntryUpdateDTO struct {
StartTime *string `json:"startTime"` // Use ISO8601 format
EndTime *string `json:"endTime"` // Use ISO8601 format
Description *string `json:"description"`
UserID *string `json:"userId"`
ProjectID *string `json:"projectId"`
}
@@ -0,0 +1,25 @@
package dto
// UserDTO represents the data structure for transferring user data.
type UserDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Password *string `json:"password,omitempty"` // Optional for cases where password shouldn't be exposed
CreatedAt string `json:"createdAt"` // Use ISO8601 format
UpdatedAt string `json:"updatedAt"` // Use ISO8601 format
}
// UserCreateDTO is used for creating a new user.
type UserCreateDTO struct {
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
}
// UserUpdateDTO is used for updating an existing user.
type UserUpdateDTO struct {
Name *string `json:"name"`
Email *string `json:"email"`
Password *string `json:"password"`
}
@@ -0,0 +1,14 @@
package mappers
import (
"time"
)
// Parses ISO8601 timestamps
func parseISOTime(value string) time.Time {
parsed, err := time.Parse(time.RFC3339, value)
if err != nil {
panic("Invalid ISO8601 format") // Or handle error gracefully
}
return parsed
}
@@ -0,0 +1,41 @@
package mappers
import (
"actatempus_backend/internal/application/services/dto"
"actatempus_backend/internal/domain/entities"
"time"
)
// MapProjectToDTO converts a Project domain object to a ProjectDTO.
func MapProjectToDTO(project entities.Project) dto.ProjectDTO {
return dto.ProjectDTO{
ID: project.ID,
Name: project.Name,
Description: project.Description,
ClientID: project.ClientID,
UserID: project.UserID,
CreatedAt: project.CreatedAt.Format(time.RFC3339),
UpdatedAt: project.UpdatedAt.Format(time.RFC3339),
}
}
// MapCreateDTOToProject converts a ProjectCreateDTO to a Project domain object.
func MapCreateDTOToProject(dto dto.ProjectCreateDTO) entities.ProjectCreate {
return entities.ProjectCreate{
Name: dto.Name,
Description: dto.Description,
ClientID: dto.ClientID,
UserID: dto.UserID,
}
}
// MapUpdateDTOToProject converts a ProjectUpdateDTO to a partial Project domain object.
func MapUpdateDTOToProject(dto dto.ProjectUpdateDTO, ID string) entities.ProjectUpdate {
return entities.ProjectUpdate{
ID: ID,
Name: dto.Name,
Description: dto.Description,
ClientID: dto.ClientID,
UserID: dto.UserID,
}
}
@@ -0,0 +1,38 @@
package mappers
import (
"actatempus_backend/internal/application/services/dto"
"actatempus_backend/internal/domain/entities"
"time"
)
// MapProjectTaskToDTO converts a ProjectTask domain object to a ProjectTaskDTO.
func MapProjectTaskToDTO(task entities.ProjectTask) dto.ProjectTaskDTO {
return dto.ProjectTaskDTO{
ID: task.ID,
Name: task.Name,
Description: task.Description,
ProjectID: task.ProjectID,
CreatedAt: task.CreatedAt.Format(time.RFC3339),
UpdatedAt: task.UpdatedAt.Format(time.RFC3339),
}
}
// MapCreateDTOToProjectTask converts a ProjectTaskCreateDTO to a ProjectTask domain object.
func MapCreateDTOToProjectTask(dto dto.ProjectTaskCreateDTO) entities.ProjectTaskCreate {
return entities.ProjectTaskCreate{
Name: dto.Name,
Description: dto.Description,
ProjectID: dto.ProjectID,
}
}
// MapUpdateDTOToProjectTask converts a ProjectTaskUpdateDTO to a partial ProjectTask domain object.
func MapUpdateDTOToProjectTask(dto dto.ProjectTaskUpdateDTO, ID string) entities.ProjectTaskUpdate {
return entities.ProjectTaskUpdate{
ID: ID,
Name: dto.Name,
Description: dto.Description,
ProjectID: dto.ProjectID,
}
}
@@ -0,0 +1,46 @@
package mappers
import (
"actatempus_backend/internal/application/services/dto"
"actatempus_backend/internal/domain/entities"
"actatempus_backend/internal/utils"
"time"
)
// MapTimeEntryToDTO converts a TimeEntry domain object to a TimeEntryDTO.
func MapTimeEntryToDTO(entry entities.TimeEntry) dto.TimeEntryDTO {
return dto.TimeEntryDTO{
ID: entry.ID,
StartTime: entry.StartTime.Format(time.RFC3339),
EndTime: utils.Let(entry.EndTime, func (t time.Time) string { return t.Format(time.RFC3339);}),
Description: entry.Description,
UserID: entry.UserID,
ProjectID: entry.ProjectID,
CreatedAt: entry.CreatedAt.Format(time.RFC3339),
UpdatedAt: entry.UpdatedAt.Format(time.RFC3339),
}
}
// MapCreateDTOToTimeEntry converts a TimeEntryCreateDTO to a TimeEntry domain object.
func MapCreateDTOToTimeEntry(dto dto.TimeEntryCreateDTO) entities.TimeEntryCreate {
return entities.TimeEntryCreate{
StartTime: parseISOTime(dto.StartTime),
EndTime: utils.Let(dto.EndTime,parseISOTime),
Description: dto.Description,
UserID: dto.UserID,
ProjectID: dto.ProjectID,
}
}
// MapUpdateDTOToTimeEntry converts a TimeEntryUpdateDTO to a partial TimeEntry domain object.
func MapUpdateDTOToTimeEntry(dto dto.TimeEntryUpdateDTO, ID string) entities.TimeEntryUpdate {
return entities.TimeEntryUpdate{
ID: ID,
StartTime: utils.Let(dto.StartTime,parseISOTime),
EndTime: utils.Let(dto.EndTime,parseISOTime),
Description: dto.Description,
UserID: dto.UserID,
ProjectID: dto.ProjectID,
}
}
@@ -0,0 +1,37 @@
package mappers
import (
"actatempus_backend/internal/application/services/dto"
"actatempus_backend/internal/domain/entities"
"time"
)
// MapUserToDTO converts a User domain object to a UserDTO.
func MapUserToDTO(user entities.User) dto.UserDTO {
return dto.UserDTO{
ID: user.ID,
Name: user.Name,
Email: user.Email,
CreatedAt: user.CreatedAt.Format(time.RFC3339),
UpdatedAt: user.UpdatedAt.Format(time.RFC3339),
}
}
// MapCreateDTOToUser converts a UserCreateDTO to a User domain object.
func MapCreateDTOToUser(dto dto.UserCreateDTO) entities.UserCreate {
return entities.UserCreate{
Name: dto.Name,
Email: dto.Email,
Password: dto.Password,
}
}
// MapUpdateDTOToUser converts a UserUpdateDTO to a partial User domain object.
func MapUpdateDTOToUser(dto dto.UserUpdateDTO, ID string) entities.UserUpdate {
return entities.UserUpdate{
ID: ID,
Name: dto.Name,
Email: dto.Email,
Password: dto.Password,
}
}