refactor(dto): use Record instead of Lombok data
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.ddf.vodsystem.controllers;
|
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.APIResponse;
|
||||||
import com.ddf.vodsystem.dto.ClipUpdateRequest;
|
import com.ddf.vodsystem.dto.ClipUpdateRequest;
|
||||||
import com.ddf.vodsystem.entities.Clip;
|
import com.ddf.vodsystem.entities.Clip;
|
||||||
@@ -22,9 +22,9 @@ public class ClipController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public ResponseEntity<APIResponse<List<ClipDTO>>> getClips() {
|
public ResponseEntity<APIResponse<List<ClipResponse>>> getClips() {
|
||||||
List<Clip> clips = clipService.getClipsByUser();
|
List<Clip> clips = clipService.getClipsByUser();
|
||||||
List<ClipDTO> clipDTOs = clips.stream()
|
List<ClipResponse> clipDTOs = clips.stream()
|
||||||
.map(this::convertToDTO)
|
.map(this::convertToDTO)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
@@ -37,13 +37,13 @@ public class ClipController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ResponseEntity<APIResponse<ClipDTO>> getClipById(@PathVariable Long id) {
|
public ResponseEntity<APIResponse<ClipResponse>> getClipById(@PathVariable Long id) {
|
||||||
Optional<Clip> clip = clipService.getClipById(id);
|
Optional<Clip> clip = clipService.getClipById(id);
|
||||||
if (clip.isEmpty()) {
|
if (clip.isEmpty()) {
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClipDTO clipDTO = convertToDTO(clip.get());
|
ClipResponse clipDTO = convertToDTO(clip.get());
|
||||||
|
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
new APIResponse<>(SUCCESS,
|
new APIResponse<>(SUCCESS,
|
||||||
@@ -54,10 +54,10 @@ public class ClipController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/{id}")
|
@PatchMapping("/{id}")
|
||||||
public ResponseEntity<APIResponse<ClipDTO>> updateClip(@PathVariable Long id,
|
public ResponseEntity<APIResponse<ClipResponse>> updateClip(@PathVariable Long id,
|
||||||
@RequestBody ClipUpdateRequest updateFields) {
|
@RequestBody ClipUpdateRequest updateFields) {
|
||||||
Clip clip = clipService.updateClip(id, updateFields);
|
Clip clip = clipService.updateClip(id, updateFields);
|
||||||
ClipDTO clipDTO = convertToDTO(clip);
|
ClipResponse clipDTO = convertToDTO(clip);
|
||||||
|
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
new APIResponse<>(SUCCESS, "Clip updated successfully", clipDTO)
|
new APIResponse<>(SUCCESS, "Clip updated successfully", clipDTO)
|
||||||
@@ -79,14 +79,14 @@ public class ClipController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClipDTO convertToDTO(Clip clip) {
|
private ClipResponse convertToDTO(Clip clip) {
|
||||||
ClipDTO dto = new ClipDTO();
|
return new ClipResponse(
|
||||||
dto.setId(clip.getId());
|
clip.getId(),
|
||||||
dto.setUserId(clip.getUser().getId());
|
clip.getUser().getId(),
|
||||||
dto.setTitle(clip.getTitle());
|
clip.getTitle(),
|
||||||
dto.setDescription(clip.getDescription());
|
clip.getDescription(),
|
||||||
dto.setDuration(clip.getDuration());
|
clip.getDuration(),
|
||||||
dto.setCreatedAt(clip.getCreatedAt());
|
clip.getCreatedAt()
|
||||||
return dto;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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