Skip to content

Commit 1a3fcd7

Browse files
committed
refactor : add attachment column
1 parent ccc4d4c commit 1a3fcd7

File tree

10 files changed

+53
-21
lines changed

10 files changed

+53
-21
lines changed

src/main/java/org/bssm/attachit/domain/attachment/domain/Attachment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Attachment {
2828
private Long zIndex;
2929

3030
@Column
31+
@Enumerated(EnumType.STRING)
3132
private PostType postType;
3233

3334
@Column

src/main/java/org/bssm/attachit/domain/attachment/presentation/AttachmentController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
public class AttachmentController {
1515

1616
private final PostAttachmentService postAttachmentService;
17-
1817
@PostMapping
1918
public ResponseEntity<String> createPost(@RequestPart("data") PostAttachmentRequest request, @RequestPart("file") MultipartFile file, HttpServletRequest httpServletRequest) {
2019
return postAttachmentService.execute(request, file, httpServletRequest);

src/main/java/org/bssm/attachit/domain/attachment/presentation/dto/request/PostAttachmentRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
public class PostAttachmentRequest {
88
private String content;
99
private Long colorCode;
10-
private Long zIndex;
1110
private PostType postType;
12-
private String xPosition;
13-
private String yPosition;
11+
private Long z;
12+
private String x;
13+
private String y;
1414
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.bssm.attachit.domain.attachment.presentation.dto.response;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
import org.bssm.attachit.domain.attachment.domain.type.PostType;
6+
7+
@Getter
8+
@Builder
9+
public class AttachmentResponse {
10+
private String content;
11+
private String url;
12+
private Long colorCode;
13+
private Long zIndex;
14+
private PostType postType;
15+
private String xPosition;
16+
private String yPosition;
17+
private String name;
18+
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.bssm.attachit.domain.attachment.service;
22

33
import lombok.RequiredArgsConstructor;
4-
import org.bssm.attachit.domain.attachment.domain.Attachment;
4+
import org.bssm.attachit.domain.attachment.presentation.dto.response.AttachmentResponse;
55
import org.bssm.attachit.domain.attachment.repository.AttachmentRepository;
6+
import org.bssm.attachit.global.properties.FileProperties;
67
import org.springframework.stereotype.Service;
78

89
import java.util.List;
@@ -12,8 +13,20 @@
1213
public class GetAttachmentListService {
1314

1415
private final AttachmentRepository attachmentRepository;
16+
private final FileProperties fileProperties;
1517

16-
public List<Attachment> execute() {
17-
return attachmentRepository.findAll();
18+
public List<AttachmentResponse> execute() {
19+
return attachmentRepository.findAll().stream().map(
20+
attachment -> AttachmentResponse.builder()
21+
.content(attachment.getContent())
22+
.url(fileProperties.getUrl() + "/file?attachmentId=" + attachment.getId())
23+
.name(attachment.getUser().getName())
24+
.colorCode(attachment.getColorCode())
25+
.postType(attachment.getPostType())
26+
.xPosition(attachment.getXPosition())
27+
.yPosition(attachment.getYPosition())
28+
.zIndex(attachment.getZIndex())
29+
.build()
30+
).toList();
1831
}
1932
}

src/main/java/org/bssm/attachit/domain/attachment/service/PostAttachmentService.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import jakarta.servlet.http.HttpServletRequest;
44
import lombok.RequiredArgsConstructor;
55
import org.bssm.attachit.domain.attachment.domain.Attachment;
6-
import org.bssm.attachit.domain.attachment.exception.FileNotFoundException;
76
import org.bssm.attachit.domain.attachment.presentation.dto.request.PostAttachmentRequest;
87
import org.bssm.attachit.domain.attachment.repository.AttachmentRepository;
98
import org.bssm.attachit.domain.user.domain.User;
@@ -24,26 +23,26 @@ public class PostAttachmentService {
2423
private final FileSaveUtil fileSaveUtil;
2524

2625
public ResponseEntity<String> execute(PostAttachmentRequest request, MultipartFile file, HttpServletRequest httpServletRequest) {
27-
if (file.isEmpty()) {
28-
throw FileNotFoundException.EXCEPTION;
29-
}
30-
3126
User user = userRepository.findByEmail(jwtUtil.extractEmail(httpServletRequest)).orElseThrow(
3227
() -> UserNotFoundException.EXCEPTION
3328
);
3429

35-
String path = fileSaveUtil.save(file);
30+
String path = null;
31+
32+
if (!file.isEmpty()) {
33+
path = fileSaveUtil.save(file);
34+
}
3635

3736
attachmentRepository.save(
3837
Attachment.builder()
3938
.path(path)
4039
.content(request.getContent())
4140
.user(user)
4241
.colorCode(request.getColorCode())
43-
.zIndex(request.getZIndex())
42+
.zIndex(request.getZ())
4443
.postType(request.getPostType())
45-
.xPosition(request.getXPosition())
46-
.yPosition(request.getYPosition())
44+
.xPosition(request.getX())
45+
.yPosition(request.getY())
4746
.build()
4847
);
4948

src/main/java/org/bssm/attachit/global/properties/FileProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
@ConfigurationProperties(prefix = "root")
1212
public class FileProperties {
1313
private Path path;
14+
private String url;
1415
}

src/main/java/org/bssm/attachit/global/security/socket/WebSocketHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import lombok.RequiredArgsConstructor;
6-
import org.bssm.attachit.domain.attachment.domain.Attachment;
76
import org.bssm.attachit.domain.attachment.exception.SocketIOException;
7+
import org.bssm.attachit.domain.attachment.presentation.dto.response.AttachmentResponse;
88
import org.bssm.attachit.domain.attachment.service.GetAttachmentListService;
99
import org.springframework.scheduling.annotation.Scheduled;
1010
import org.springframework.stereotype.Component;
@@ -37,7 +37,7 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus status)
3737

3838
@Scheduled(fixedRate = 1000, initialDelay = 5000)
3939
public void sendAttachmentListToAllClients() throws JsonProcessingException {
40-
List<Attachment> attachmentList = getAttachmentListService.execute();
40+
List<AttachmentResponse> attachmentList = getAttachmentListService.execute();
4141
String jsonAttachments = objectMapper.writeValueAsString(attachmentList);
4242
TextMessage message = new TextMessage(jsonAttachments);
4343
CLIENTS.forEach((key, value) -> {

src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jwt:
2323

2424
root:
2525
path: ${ROOT_PATH}
26+
url: ${SERVER_URL}
2627

2728
server:
2829
servlet:

src/test/java/org/bssm/attachit/AttachitApplicationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
@SpringBootTest
77
class AttachitApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
9+
// @Test
10+
// void contextLoads() {
11+
// }
1212

1313
}

0 commit comments

Comments
 (0)