-
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.
#5 Implemented relation of exercise and images
- Loading branch information
1 parent
104fafa
commit 5750166
Showing
10 changed files
with
164 additions
and
129 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,20 +1,44 @@ | ||
package info.wallyson.dto; | ||
|
||
import info.wallyson.entity.Exercise; | ||
import javax.validation.constraints.NotBlank; | ||
import info.wallyson.entity.ExerciseImage; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@Builder | ||
public class ExerciseDTO { | ||
private String id; | ||
@NotBlank private String name; | ||
private String description; | ||
private String imageUrl; | ||
private String createdBy; | ||
private List<String> images; | ||
@NotBlank private String createdBy; | ||
|
||
public Exercise toEntity() { | ||
return new Exercise(null, this.name, this.description, this.imageUrl, this.createdBy); | ||
var imagesSet = | ||
this.images != null | ||
? this.images.stream() | ||
.map(img -> new ExerciseImage(null, img)) | ||
.collect(Collectors.toSet()) | ||
: null; | ||
|
||
return new Exercise(null, this.name, this.description, imagesSet, this.createdBy); | ||
} | ||
|
||
public static ExerciseDTO fromEntity(Exercise ex) { | ||
var images = ex.getImages().stream().map(ExerciseImage::getId_url).collect(Collectors.toList()); | ||
var id = ex.getId() != null ? ex.getId().toString() : ""; | ||
|
||
return ExerciseDTO.builder() | ||
.id(id) | ||
.name(ex.getName()) | ||
.description(ex.getDescription()) | ||
.images(images) | ||
.createdBy(ex.getCreatedBy()) | ||
.build(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
package info.wallyson.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ExerciseImageDTO { | ||
private String name; | ||
private String url; | ||
private String name; | ||
private String url; | ||
} |
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
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,19 @@ | ||
package info.wallyson.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "exercise_images") | ||
@AllArgsConstructor | ||
@Getter | ||
public class ExerciseImage { | ||
@Id @GeneratedValue private Long id; | ||
|
||
private String id_url; | ||
} |
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
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
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
Oops, something went wrong.