11package ssu .eatssu .domain .inquiry .service ;
22
33import lombok .RequiredArgsConstructor ;
4+ import org .springframework .context .ApplicationEventPublisher ;
45import org .springframework .stereotype .Service ;
56import org .springframework .transaction .annotation .Transactional ;
67import ssu .eatssu .domain .auth .security .CustomUserDetails ;
1011import ssu .eatssu .domain .user .entity .User ;
1112import ssu .eatssu .domain .user .repository .UserRepository ;
1213import ssu .eatssu .global .handler .response .BaseException ;
14+ import ssu .eatssu .global .log .event .LogEvent ;
1315
1416import static ssu .eatssu .global .handler .response .BaseResponseStatus .NOT_FOUND_USER ;
1517
@@ -20,14 +22,23 @@ public class InquiryService {
2022
2123 private final UserRepository userRepository ;
2224 private final InquiryRepository inquiryRepository ;
25+ private final ApplicationEventPublisher eventPublisher ;
2326
2427 public Inquiry createUserInquiry (CustomUserDetails userDetails , CreateInquiryRequest request ) {
2528 User user = userRepository .findById (userDetails .getId ())
26- .orElseThrow (() -> new BaseException (NOT_FOUND_USER ));
29+ .orElseThrow (() -> new BaseException (NOT_FOUND_USER ));
2730
2831 Inquiry inquiry = new Inquiry (request .getContent (), user , request .getEmail ());
32+ Inquiry saved = inquiryRepository .save (inquiry );
2933
30- return inquiryRepository .save (inquiry );
34+ eventPublisher .publishEvent (LogEvent .of (String .format (
35+ "Inquiry created: id=%d, userId=%d, status=%s" ,
36+ saved .getId (),
37+ user .getId (),
38+ saved .getStatus ()
39+ )));
40+
41+ return saved ;
3142 }
3243
3344}
0 commit comments