Skip to content

Commit

Permalink
Add warn log
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkhanh-axonivy committed Jul 9, 2024
1 parent 84b9bf1 commit 36aba62
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import com.axonivy.market.controller.FeedbackController;
import com.axonivy.market.entity.Feedback;
import com.axonivy.market.entity.User;
import com.axonivy.market.exceptions.model.NotFoundException;
import com.axonivy.market.model.FeedbackModel;
import com.axonivy.market.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.stereotype.Component;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Log4j2
@Component
public class FeedbackModelAssembler extends RepresentationModelAssemblerSupport<Feedback, FeedbackModel> {

Expand All @@ -31,7 +34,14 @@ public FeedbackModel toModel(Feedback feedback) {
}

private FeedbackModel createResource(FeedbackModel model, Feedback feedback) {
User user = userService.findUser(feedback.getUserId());
User user;
try {
user = userService.findUser(feedback.getUserId());
}
catch (NotFoundException e) {
log.warn(e.getMessage());
user = new User();
}
model.setId(feedback.getId());
model.setUsername(StringUtils.isBlank(user.getName()) ? user.getUsername() : user.getName());
model.setUserAvatarUrl(user.getAvatarUrl());
Expand Down

0 comments on commit 36aba62

Please sign in to comment.