refactor(dto): use Record instead of Lombok data
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.ddf.vodsystem.controllers;
|
||||
|
||||
import com.ddf.vodsystem.dto.ClipDTO;
|
||||
import com.ddf.vodsystem.dto.ClipResponse;
|
||||
import com.ddf.vodsystem.dto.APIResponse;
|
||||
import com.ddf.vodsystem.dto.ClipUpdateRequest;
|
||||
import com.ddf.vodsystem.entities.Clip;
|
||||
@@ -22,9 +22,9 @@ public class ClipController {
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public ResponseEntity<APIResponse<List<ClipDTO>>> getClips() {
|
||||
public ResponseEntity<APIResponse<List<ClipResponse>>> getClips() {
|
||||
List<Clip> clips = clipService.getClipsByUser();
|
||||
List<ClipDTO> clipDTOs = clips.stream()
|
||||
List<ClipResponse> clipDTOs = clips.stream()
|
||||
.map(this::convertToDTO)
|
||||
.toList();
|
||||
|
||||
@@ -37,13 +37,13 @@ public class ClipController {
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<APIResponse<ClipDTO>> getClipById(@PathVariable Long id) {
|
||||
public ResponseEntity<APIResponse<ClipResponse>> getClipById(@PathVariable Long id) {
|
||||
Optional<Clip> clip = clipService.getClipById(id);
|
||||
if (clip.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
ClipDTO clipDTO = convertToDTO(clip.get());
|
||||
ClipResponse clipDTO = convertToDTO(clip.get());
|
||||
|
||||
return ResponseEntity.ok(
|
||||
new APIResponse<>(SUCCESS,
|
||||
@@ -54,10 +54,10 @@ public class ClipController {
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public ResponseEntity<APIResponse<ClipDTO>> updateClip(@PathVariable Long id,
|
||||
public ResponseEntity<APIResponse<ClipResponse>> updateClip(@PathVariable Long id,
|
||||
@RequestBody ClipUpdateRequest updateFields) {
|
||||
Clip clip = clipService.updateClip(id, updateFields);
|
||||
ClipDTO clipDTO = convertToDTO(clip);
|
||||
ClipResponse clipDTO = convertToDTO(clip);
|
||||
|
||||
return ResponseEntity.ok(
|
||||
new APIResponse<>(SUCCESS, "Clip updated successfully", clipDTO)
|
||||
@@ -79,14 +79,14 @@ public class ClipController {
|
||||
);
|
||||
}
|
||||
|
||||
private ClipDTO convertToDTO(Clip clip) {
|
||||
ClipDTO dto = new ClipDTO();
|
||||
dto.setId(clip.getId());
|
||||
dto.setUserId(clip.getUser().getId());
|
||||
dto.setTitle(clip.getTitle());
|
||||
dto.setDescription(clip.getDescription());
|
||||
dto.setDuration(clip.getDuration());
|
||||
dto.setCreatedAt(clip.getCreatedAt());
|
||||
return dto;
|
||||
private ClipResponse convertToDTO(Clip clip) {
|
||||
return new ClipResponse(
|
||||
clip.getId(),
|
||||
clip.getUser().getId(),
|
||||
clip.getTitle(),
|
||||
clip.getDescription(),
|
||||
clip.getDuration(),
|
||||
clip.getCreatedAt()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.ddf.vodsystem.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class ClipDTO {
|
||||
private Long id;
|
||||
private Long userId;
|
||||
private String title;
|
||||
private String description;
|
||||
private Float duration;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
12
src/main/java/com/ddf/vodsystem/dto/ClipResponse.java
Normal file
12
src/main/java/com/ddf/vodsystem/dto/ClipResponse.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.ddf.vodsystem.dto;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public record ClipResponse(
|
||||
Long id,
|
||||
Long userId,
|
||||
String title,
|
||||
String description,
|
||||
Float duration,
|
||||
LocalDateTime createdAt
|
||||
) {}
|
||||
Reference in New Issue
Block a user