Skip to content
This repository was archived by the owner on Sep 29, 2024. It is now read-only.

Commit 6021442

Browse files
authored
Merge pull request #800 from SE-TINF22B6/cors-fix
Change file data variable type
2 parents 68ec226 + c79112e commit 6021442

16 files changed

+31
-32
lines changed

src/main/java/de/tinf22b6/dhbwhub/mapper/PictureMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ public static Picture mapToModel(PictureProposal proposal) {
1111
);
1212
}
1313

14-
public static Picture mapToModelUser(byte[] imageData) {
14+
public static Picture mapToModelUser(String imageData) {
1515
return new Picture(
1616
"user.png",
1717
imageData
1818
);
1919
}
2020

21-
public static Picture mapToModelPost(byte[] imageData) {
21+
public static Picture mapToModelPost(String imageData) {
2222
return new Picture(
2323
"post.png",
2424
imageData
2525
);
2626
}
27-
}
27+
}

src/main/java/de/tinf22b6/dhbwhub/model/Picture.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public class Picture {
2020

2121
private final String name;
2222

23-
private final byte[] imageData;
23+
private final String imageData;
2424

2525
}

src/main/java/de/tinf22b6/dhbwhub/proposal/PictureProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
public class PictureProposal {
1313
private String name;
1414

15-
private byte[] imageData;
15+
private String imageData;
1616
}

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/CommentThreadViewProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class CommentThreadViewProposal {
2222

2323
private Long accountId;
2424

25-
private byte[] authorImage;
25+
private String authorImage;
2626

2727
private Date timestamp;
2828

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/CreateEventPostProposal.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import lombok.NoArgsConstructor;
66
import lombok.Setter;
77

8-
import javax.xml.stream.Location;
98
import java.util.Date;
109

1110
@Getter
@@ -27,7 +26,7 @@ public class CreateEventPostProposal {
2726

2827
private String[] tags;
2928

30-
private byte[] postImage;
29+
private String postImage;
3130

3231
private Long accountId;
3332
}

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/CreatePostProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class CreatePostProposal {
2121

2222
private Date timestamp;
2323

24-
private byte[] postImage;
24+
private String postImage;
2525

2626
private Long accountId;
2727

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/EventCommentThreadViewProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class EventCommentThreadViewProposal {
2222

2323
private Long accountId;
2424

25-
private byte[] authorImage;
25+
private String authorImage;
2626

2727
private Date timestamp;
2828

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/FriendlistProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public class FriendlistProposal {
1818

1919
private String username;
2020

21-
private byte[] image;
21+
private String image;
2222

2323
}

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/HomepagePostPreviewProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class HomepagePostPreviewProposal {
2727

2828
private Date timestamp;
2929

30-
private byte[] postImage;
30+
private String postImage;
3131

3232
private Long accountId;
3333

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/PostThreadViewProposal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class PostThreadViewProposal {
2727

2828
private Date timestamp;
2929

30-
private byte[] postImage;
30+
private String postImage;
3131

3232
private Long accountId;
3333

3434
private String username;
3535

36-
private byte[] userImage;
36+
private String userImage;
3737

3838
private List<CommentThreadViewProposal> comments;
3939
}

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UpdateEventPostProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ public class UpdateEventPostProposal {
2525

2626
private String[] tags;
2727

28-
private byte[] postImage;
28+
private String postImage;
2929
}

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UpdatePictureProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
public class UpdatePictureProposal {
1313
private Long userId;
1414

15-
private byte[] imageData;
15+
private String imageData;
1616
}

src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UpdatePostProposal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public class UpdatePostProposal {
1818

1919
private String[] tags;
2020

21-
private byte[] postImage;
21+
private String postImage;
2222

2323
}

src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public HomepagePostPreviewProposal create(CreatePostProposal proposal) {
6868
if(user == null){
6969
throw new NoSuchEntryException("User with the AccountId " + proposal.getAccountId() + " does not exist!");
7070
}
71-
Picture picture = proposal.getPostImage().length != 0 ?
71+
Picture picture = !proposal.getPostImage().isEmpty() ?
7272
pictureRepository.save(PictureMapper.mapToModelPost(proposal.getPostImage())): null;
7373

7474
Post post = repository.save(PostMapper.mapToModel(proposal,user,picture));
@@ -148,14 +148,14 @@ public PostThreadViewProposal update(Long id, UpdatePostProposal proposal) {
148148
Post initialPost = get(id);
149149
Picture picture;
150150

151-
byte[] proposalImageData = proposal.getPostImage() != null? proposal.getPostImage() : new byte[0];
152-
byte[] initialImageData = initialPost.getPicture() != null? initialPost.getPicture().getImageData() : new byte[0];
151+
String proposalImageData = proposal.getPostImage() != null ? proposal.getPostImage() : "";
152+
String initialImageData = initialPost.getPicture() != null ? initialPost.getPicture().getImageData() : "";
153153
// Check if Picture has changed
154-
if (proposalImageData.length == 0 && initialImageData.length != 0) {
154+
if (proposalImageData.isEmpty() && !initialImageData.isEmpty()) {
155155
pictureRepository.delete(initialPost.getPicture().getId());
156156
picture = null;
157157
}
158-
else if (!Arrays.equals(initialImageData, proposalImageData)) {
158+
else if (!initialImageData.equals(proposalImageData)) {
159159
pictureRepository.delete(initialPost.getPicture().getId());
160160
picture = pictureRepository.save(PictureMapper.mapToModelPost(proposalImageData));
161161
} else {

src/main/java/de/tinf22b6/dhbwhub/service/UserServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void updatePassword(UpdatePasswordProposal proposal) {
130130
@Override
131131
public void updatePicture(UpdatePictureProposal proposal) {
132132
User user = get(proposal.getUserId());
133-
if (proposal.getImageData().length == 0){
133+
if (proposal.getImageData().isEmpty()){
134134
throw new IllegalArgumentException("Image data is empty");
135135
}
136136
Picture picture = pictureRepository.save(PictureMapper.mapToModelUser(proposal.getImageData()));

src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
public abstract class AbstractApplicationTest {
1717
protected Picture createDefaultPicture() {
18-
return new Picture("profile.png", new byte[]{ 12, 34, 45, 67, 78, 91 });
18+
return new Picture("profile.png", "ahudmpiwmhapicuhawiughui");
1919
}
2020

2121
protected Picture createDefaultPicture2() {
22-
return new Picture("img-user", new byte[]{ 12, 34, 44, 67, 78 });
22+
return new Picture("img-user", "ahudmpiwmhapicuhawiughui");
2323
}
2424

2525
protected Account createDefaultAccount() {
@@ -111,7 +111,7 @@ protected SavedPost createDefaultSavedPost2() {
111111
}
112112

113113
protected PictureProposal createDefaultPictureProposal() {
114-
return new PictureProposal("profile.png", new byte[]{ 12, 34, 45, 67, 78, 91 });
114+
return new PictureProposal("profile.png", "ahudmpiwmhapicuhawiughui");
115115
}
116116

117117
protected AccountProposal createDefaultAccountProposal() {
@@ -147,19 +147,19 @@ protected SavedPostProposal createDefaultSavedPostProposal() {
147147
}
148148

149149
protected HomepagePostPreviewProposal createDefaultHomepagePostPreviewProposal() {
150-
return new HomepagePostPreviewProposal(1L,"Titel 1","Beschreibung 1", Arrays.stream(new String[]{"Tag 1", "Tag 2"}).toList(), 12, 4, new Date(1478979207L), new byte[]{ 12, 34, 45, 67, 78, 91 }, 1L, "Bruno");
150+
return new HomepagePostPreviewProposal(1L,"Titel 1","Beschreibung 1", Arrays.stream(new String[]{"Tag 1", "Tag 2"}).toList(), 12, 4, new Date(1478979207L), "ahudmpiwmhapicuhawiughui", 1L, "Bruno");
151151
}
152152

153153
protected PostThreadViewProposal createDefaultPostThreadViewProposal() {
154-
return new PostThreadViewProposal(1L,"Titel 1","Beschreibung 1", Arrays.stream(new String[]{"Tag 1", "Tag 2"}).toList(), 12, 4, new Date(1478979207L), new byte[]{ 12, 34, 45, 67, 78, 91 }, 1L, "Bruno", new byte[]{ 12, 34, 45, 67, 78, 91 }, List.of(createDefaultCommentThreadViewProposal()));
154+
return new PostThreadViewProposal(1L,"Titel 1","Beschreibung 1", Arrays.stream(new String[]{"Tag 1", "Tag 2"}).toList(), 12, 4, new Date(1478979207L), "ahudmpiwmhapicuhawiughui", 1L, "Bruno", "ahudmpiwmhapicuhawiughui", List.of(createDefaultCommentThreadViewProposal()));
155155
}
156156

157157
protected CommentThreadViewProposal createDefaultCommentThreadViewProposal() {
158-
return new CommentThreadViewProposal(1L, 0L,"Beschreibung 1", "Bruno", 1L, new byte[]{ 12, 34, 45, 67, 78, 91 }, new Date(1478979207L), 23);
158+
return new CommentThreadViewProposal(1L, 0L,"Beschreibung 1", "Bruno", 1L, "ahudmpiwmhapicuhawiughui", new Date(1478979207L), 23);
159159
}
160160

161161
protected FriendlistProposal createDefaultFriendlistProposal() {
162-
return new FriendlistProposal(1L,2L,"Bruno", new byte[]{ 12, 34, 45, 67, 78, 91 });
162+
return new FriendlistProposal(1L,2L,"Bruno", "ahudmpiwmhapicuhawiughui");
163163
}
164164

165165
protected CreateCommentProposal createDefaultCreateCommentProposal() {
@@ -171,7 +171,7 @@ protected UpdateCommentProposal createDefaultUpdateCommentProposal() {
171171
}
172172

173173
protected CreatePostProposal createDefaultCreatePostProposal() {
174-
return new CreatePostProposal("Titel 1", "Beschreibung 1", new String[]{"Tag 1", "Tag 2"}, new Date(1478979207L), new byte[]{ 12, 34, 45, 67, 78, 91 }, 1L);
174+
return new CreatePostProposal("Titel 1", "Beschreibung 1", new String[]{"Tag 1", "Tag 2"}, new Date(1478979207L), "ahudmpiwmhapicuhawiughui", 1L);
175175
}
176176

177177
protected UpdatePostProposal createDefaultUpdatePostProposal() {
@@ -366,6 +366,6 @@ protected UpdatePasswordProposal createUpdatePasswordProposal() {
366366
}
367367

368368
protected UpdatePictureProposal createUpdatePictureProposal() {
369-
return new UpdatePictureProposal(1L, new byte[]{12, 12, 12, 12});
369+
return new UpdatePictureProposal(1L, "ahudmpiwmhapicuhawiughui");
370370
}
371371
}

0 commit comments

Comments
 (0)