Changing Authors
This commit is contained in:
@@ -105,6 +105,14 @@ public class StoryController {
|
||||
public ResponseEntity<StoryDto> updateStory(@PathVariable UUID id,
|
||||
@Valid @RequestBody UpdateStoryRequest request) {
|
||||
logger.info("Updating story: {} (ID: {})", request.getTitle(), id);
|
||||
|
||||
// Handle author creation/lookup at controller level before calling service
|
||||
if (request.getAuthorName() != null && !request.getAuthorName().trim().isEmpty() && request.getAuthorId() == null) {
|
||||
Author author = findOrCreateAuthor(request.getAuthorName().trim());
|
||||
request.setAuthorId(author.getId());
|
||||
request.setAuthorName(null); // Clear author name since we now have the ID
|
||||
}
|
||||
|
||||
Story updatedStory = storyService.updateWithTagNames(id, request);
|
||||
logger.info("Successfully updated story: {}", updatedStory.getTitle());
|
||||
return ResponseEntity.ok(convertToDto(updatedStory));
|
||||
@@ -389,9 +397,13 @@ public class StoryController {
|
||||
if (updateReq.getVolume() != null) {
|
||||
story.setVolume(updateReq.getVolume());
|
||||
}
|
||||
// Handle author - either by ID or by name
|
||||
if (updateReq.getAuthorId() != null) {
|
||||
Author author = authorService.findById(updateReq.getAuthorId());
|
||||
story.setAuthor(author);
|
||||
} else if (updateReq.getAuthorName() != null && !updateReq.getAuthorName().trim().isEmpty()) {
|
||||
Author author = findOrCreateAuthor(updateReq.getAuthorName().trim());
|
||||
story.setAuthor(author);
|
||||
}
|
||||
// Handle series - either by ID or by name
|
||||
if (updateReq.getSeriesId() != null) {
|
||||
@@ -697,6 +709,7 @@ public class StoryController {
|
||||
private String sourceUrl;
|
||||
private Integer volume;
|
||||
private UUID authorId;
|
||||
private String authorName;
|
||||
private UUID seriesId;
|
||||
private String seriesName;
|
||||
private List<String> tagNames;
|
||||
@@ -716,6 +729,8 @@ public class StoryController {
|
||||
public void setVolume(Integer volume) { this.volume = volume; }
|
||||
public UUID getAuthorId() { return authorId; }
|
||||
public void setAuthorId(UUID authorId) { this.authorId = authorId; }
|
||||
public String getAuthorName() { return authorName; }
|
||||
public void setAuthorName(String authorName) { this.authorName = authorName; }
|
||||
public UUID getSeriesId() { return seriesId; }
|
||||
public void setSeriesId(UUID seriesId) { this.seriesId = seriesId; }
|
||||
public String getSeriesName() { return seriesName; }
|
||||
|
||||
@@ -610,6 +610,7 @@ public class StoryService {
|
||||
if (updateReq.getVolume() != null) {
|
||||
story.setVolume(updateReq.getVolume());
|
||||
}
|
||||
// Handle author - either by ID or by name
|
||||
if (updateReq.getAuthorId() != null) {
|
||||
Author author = authorService.findById(updateReq.getAuthorId());
|
||||
story.setAuthor(author);
|
||||
@@ -620,7 +621,7 @@ public class StoryService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateStoryTagsByNames(Story story, java.util.List<String> tagNames) {
|
||||
// Clear existing tags first
|
||||
Set<Tag> existingTags = new HashSet<>(story.getTags());
|
||||
|
||||
Reference in New Issue
Block a user