Conversation
|
|
||
| Capsule saved = capsuleService.createCapsule(dto, cid); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(saved); | ||
| } |
There was a problem hiding this comment.
@PostMapping
public ResponseEntity createCapsule(@ModelAttribute InputDto dto);
InputDto {
MultipartFile meiaFile;
String data;
}
@ModelAttribute annotion을 사용해 String과 MultipartFile 동시에 받을 수 있음
There was a problem hiding this comment.
@ModelAttribute 라는 어노테이션 사용하여 컨트롤러 코드 구조 변경해봤습니다 감사합니당.
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<CapsuleDto.Select> createCapsule(@ModelAttribute CapsuleDto.Create requestDto) {
CapsuleDto.Select created = capsuleService.createCapsule(requestDto);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
}
구조 변경하면서 Dto도 기존에는 기능별로 나뉘어져 있었는데 구조 합쳐서 다시 만들었습니다
public class CapsuleDto {
// 캡슐 생성
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
public static class Create {
private String capsuleType;
private String title;
private String content;
private Date openTime;
// 이미지 & 동영상
private MultipartFile mediaFile;
}
// 캡슐 조회
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
public static class Select {
private Long casuleId;
private String capsuleType;
private String title;
private String content;
private Date openTime;
}
// 캡슐 수정
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
public static class Update {
private String capsuleType;
private String title;
private String content;
private Date openTime;
}
}
이런식으로 변경했는데, 어노테이션이 겹치는 부분이 너무 많은데 괜찮은거 맞을까용;;;
리뷰 감사합니다. 배워갑니당 >0<
| @Getter | ||
| @Setter | ||
| public class CapsuleCreateRequestDto { | ||
|
|
There was a problem hiding this comment.
Dto class의 경우
spring boot에 의해 json parsing되는 일이 많음으로
@NoArgStructure을 꼭 붙여준다 (없을시 기본 생성되지만 명시하는게 좋음)
There was a problem hiding this comment.
해당 부분 반영하여 코드 수정하겠습니다. 감사합니다 :)
|
|
||
| public class CapsuleSelectResponseDto { | ||
|
|
||
| @Getter |
There was a problem hiding this comment.
앗; 알겠습니다. 바로 반영하겠습니다. 감사합니당
|
|
||
| // IPFS CID 필드 ( 이미지 / 동영상 ) | ||
| private String mediaCid; | ||
|
|
There was a problem hiding this comment.
// 캡슐 아이디
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long capsuleId;
// 캡슐 종류
@Column(nullable = false)
private String capsuleType;
// 제목
@Column(nullable = false)
private String title;
// 내용
@Column
private String content;
// 캡슐 오픈일
@Column
private Date openTime;
// IPFS CID 필드 ( 이미지 / 동영상 )
@Column
private String mediaCid;
엔티티 구조도 @column 사용하여 변경했습니당. 감사합니다 :):)
|
|
||
| return capsuleRepository.save(capsule); | ||
| } | ||
|
|
There was a problem hiding this comment.
createCapule 함수의 위치가 올바르지 않음
- 확장중 다른 service에서 CapuleService에 의존성을 가진다면 createCapules함수에도 의존성을 가지게 됨
- dto -> entity 함수는 대부분 dto에 의존성을 가짐으로
dto로 옮기는게 좋음
@Getter
@Setter
@NoArgStructor
class Dto {
int id; String col;
public Entity toEntity() { return Entity.builder(). .. .build(); } // dto -> entity 함수
public static Dto of(Entity entity) { return new Dto(); } // entity -> dto 함수
}
There was a problem hiding this comment.
이 부분은 아직 완벽하게 이해를 못해서 좀 더 알아보고 수정하여 다시 코멘트 올리겠습니다!
| return ResponseEntity.ok(cid); | ||
| } catch (Exception e) { | ||
| return ResponseEntity.internalServerError().body("IPFS 파일 업로드 실패: " + e.getMessage()); | ||
| } |
There was a problem hiding this comment.
catch (Exception e) { ... }는 다른 모든 exception또한 처리해버림 (만약 다른 부분에서 exception이 발생해도 무조건 "파일 업로드 실패" 라는 404를 반환하게됨)
때문에
IpfsService :: 27줄에서 throw 한 exception을 CustomIpfsException으로 class를 생성해서 던지고
catch(CustomIpfsException e) { ... } 으로 처리하는게 맞음
There was a problem hiding this comment.
해당 전역 에러 처리도 다시 한 번 공부해서 수정하겠습니다.
😺 Issue
✅ 작업 리스트
⚙️ 작업 내용
캡슐 CRUD 구현
스웨거 연동
IPFS 연동
전역 에러
📷 테스트 / 구현 내용
🤔 문제점 / 궁금한 점 (필요 시)
📁 참고 자료