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,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,
}
}