-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/ivanxc/hse/dashboardrest/mapper/FormCreateMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ivanxc.hse.dashboardrest.mapper; | ||
|
||
import com.ivanxc.hse.dashboardrest.dto.FormCreateDto; | ||
import com.ivanxc.hse.dashboardrest.entity.Form; | ||
import java.time.LocalDateTime; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FormCreateMapper implements Mapper<FormCreateDto, Form> { | ||
|
||
@Override | ||
public Form map(FormCreateDto from) { | ||
Form form = new Form(); | ||
copy(from, form); | ||
return form; | ||
} | ||
|
||
@Override | ||
public Form map(FormCreateDto from, Form to) { | ||
copy(from, to); | ||
return to; | ||
} | ||
|
||
public void copy(FormCreateDto from, Form to) { | ||
to.setTitle(from.getTitle()); | ||
to.setType(from.getType()); | ||
to.setUpdated(LocalDateTime.now()); | ||
to.setCreated(LocalDateTime.now()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/ivanxc/hse/dashboardrest/mapper/FormEditMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.ivanxc.hse.dashboardrest.mapper; | ||
|
||
import com.ivanxc.hse.dashboardrest.dto.FormEditDto; | ||
import com.ivanxc.hse.dashboardrest.entity.Form; | ||
import java.time.LocalDateTime; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FormEditMapper implements Mapper<FormEditDto, Form> { | ||
|
||
@Override | ||
public Form map(FormEditDto from) { | ||
Form form = new Form(); | ||
copy(from, form); | ||
return form; | ||
} | ||
|
||
public FormEditDto map(Form form) { | ||
return new FormEditDto( | ||
form.getTitle() | ||
); | ||
} | ||
|
||
@Override | ||
public Form map(FormEditDto from, Form to) { | ||
copy(from, to); | ||
return to; | ||
} | ||
|
||
public void copy(FormEditDto from, Form to) { | ||
to.setTitle(from.getTitle()); | ||
to.setUpdated(LocalDateTime.now()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/ivanxc/hse/dashboardrest/mapper/FormReadMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ivanxc.hse.dashboardrest.mapper; | ||
|
||
import com.ivanxc.hse.dashboardrest.dto.FormReadDto; | ||
import com.ivanxc.hse.dashboardrest.entity.Form; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FormReadMapper implements Mapper<Form, FormReadDto> { | ||
|
||
@Override | ||
public FormReadDto map(Form from) { | ||
return new FormReadDto( | ||
from.getId(), | ||
from.getTitle(), | ||
from.getType(), | ||
from.getCreated(), | ||
from.getUpdated() | ||
); | ||
} | ||
|
||
public FormReadDto map(Form from, long id) { | ||
return new FormReadDto( | ||
id, | ||
from.getTitle(), | ||
from.getType(), | ||
from.getCreated(), | ||
from.getUpdated() | ||
); | ||
} | ||
|
||
} |