Skip to content

Commit

Permalink
fix: unhandle nil (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious authored Dec 29, 2023
1 parent 1f8b66b commit fd9fb51
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/auth/auth.util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func ConvertRegisterRequestDTOToUser(dto *dto.RegisterRequestDTO, email string)

func DesiredRoundDTOToModel(dto *dto.DesiredRound, userId int) model.DesiredRound {
var desiredRound model.DesiredRound
if dto == nil {
return desiredRound
}
desiredRound.Order = dto.Order
desiredRound.Round = model.Round(dto.Round)
desiredRound.UserId = uint(userId)
Expand Down Expand Up @@ -88,6 +91,9 @@ func UserModelToUserDTO(mUser *model.User) dto.User {

func InterestedFacultyToFacultyInfo(m *model.InterestedFaculty) dto.FacultyInfo {
var facultyInfo dto.FacultyInfo
if m == nil {
return facultyInfo
}
facultyInfo.Department.Code = m.DepartmentCode
facultyInfo.Department.Name.En = m.Department.Name.En
facultyInfo.Department.Name.Th = m.Department.Name.Th
Expand All @@ -102,13 +108,19 @@ func InterestedFacultyToFacultyInfo(m *model.InterestedFaculty) dto.FacultyInfo

func DesiredRoundModelToDTO(m *model.DesiredRound) dto.DesiredRound {
var desiredRound dto.DesiredRound
if m == nil {
return desiredRound
}
desiredRound.Order = m.Order
desiredRound.Round = string(m.Round)
return desiredRound
}

func ScheduleModelToDTO(m *model.Schedule) dto.Schedule {
var registeredEvent dto.Schedule
if m == nil {
return registeredEvent
}
registeredEvent.Id = m.Id
registeredEvent.CurrentAttendee = m.CurrentAttendee
registeredEvent.StartsAt = m.StartsAt
Expand Down
3 changes: 3 additions & 0 deletions internal/dto/bilingual_field.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type BilingualField struct {

func BilingualModelToDTO(m *model.Bilingual) BilingualField {
var bf BilingualField
if m == nil {
return bf
}
bf.En = m.En
bf.Th = m.Th
return bf
Expand Down
6 changes: 6 additions & 0 deletions internal/event/event.utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (

func EventModelToDTO(m *model.Event) dto.Event {
var event dto.Event
if m == nil {
return event
}
event.Id = m.Id
event.Name = dto.BilingualModelToDTO(&m.Name)
event.Faculty.Code = m.FacultyCode
Expand All @@ -26,6 +29,9 @@ func EventModelToDTO(m *model.Event) dto.Event {

func ScheduleModelToDTO(m *model.Schedule) dto.Schedule {
var schedule dto.Schedule
if m == nil {
return schedule
}
schedule.Id = m.Id
schedule.EndsAt = m.EndsAt
schedule.StartsAt = m.StartsAt
Expand Down

0 comments on commit fd9fb51

Please sign in to comment.