-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 장소 등록 시 장소 통계와 함께 등록되는 기능 추가 #479
Changes from 9 commits
cda09de
2d0d015
94c533d
186ae32
b6d16aa
015f83d
5e8a0ab
865fcc9
472aec6
7df2b48
bbc44e2
1f16d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.now.naaga.place.application; | ||
|
||
import com.now.naaga.place.application.dto.CreatePlaceStatisticsCommand; | ||
import com.now.naaga.place.domain.PlaceCreateEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
public class CreatePlaceStatisticsWithPlaceCreateEventHandler { | ||
|
||
private final PlaceStatisticsService placeStatisticsService; | ||
|
||
public CreatePlaceStatisticsWithPlaceCreateEventHandler(final PlaceStatisticsService placeStatisticsService) { | ||
this.placeStatisticsService = placeStatisticsService; | ||
} | ||
|
||
@Transactional | ||
@EventListener | ||
public void handle(final PlaceCreateEvent placeCreateEvent) { | ||
final Long placeId = placeCreateEvent.placeId(); | ||
final CreatePlaceStatisticsCommand command = new CreatePlaceStatisticsCommand(placeId); | ||
placeStatisticsService.createPlaceStatistics(command); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.now.naaga.place.application; | ||
|
||
import static com.now.naaga.place.domain.PlaceStatistics.LIKE_COUNT_DEFAULT_VALUE; | ||
|
||
import com.now.naaga.place.application.dto.CreatePlaceStatisticsCommand; | ||
import com.now.naaga.place.application.dto.FindPlaceByIdCommand; | ||
import com.now.naaga.place.application.dto.SubtractLikeCommand; | ||
import com.now.naaga.place.domain.Place; | ||
import com.now.naaga.place.domain.PlaceStatistics; | ||
import com.now.naaga.place.exception.PlaceStatisticsException; | ||
import com.now.naaga.place.exception.PlaceStatisticsExceptionType; | ||
import com.now.naaga.place.repository.PlaceStatisticsRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional | ||
@Service | ||
public class PlaceStatisticsService { | ||
|
||
private final PlaceStatisticsRepository placeStatisticsRepository; | ||
|
||
private final PlaceService placeService; | ||
|
||
public PlaceStatisticsService(final PlaceStatisticsRepository placeStatisticsRepository, | ||
final PlaceService placeService) { | ||
this.placeStatisticsRepository = placeStatisticsRepository; | ||
this.placeService = placeService; | ||
} | ||
|
||
public PlaceStatistics createPlaceStatistics(final CreatePlaceStatisticsCommand createPlaceStatisticsCommand) { | ||
final Long placeId = createPlaceStatisticsCommand.placeId(); | ||
final Place place = placeService.findPlaceById(new FindPlaceByIdCommand(placeId)); | ||
|
||
final PlaceStatistics placeStatistics = new PlaceStatistics(place, LIKE_COUNT_DEFAULT_VALUE); | ||
return placeStatisticsRepository.save(placeStatistics); | ||
} | ||
|
||
public void subtractLike(final SubtractLikeCommand subtractLikeCommand) { | ||
final Long placeId = subtractLikeCommand.placeId(); | ||
|
||
final PlaceStatistics placeStatistics = placeStatisticsRepository.findByPlaceId(placeId) | ||
.orElseThrow(() -> new PlaceStatisticsException(PlaceStatisticsExceptionType.NOT_FOUND)); | ||
|
||
placeStatistics.subtractLike(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.now.naaga.place.application.dto; | ||
|
||
public record CreatePlaceStatisticsCommand(Long placeId) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.now.naaga.place.application.dto; | ||
|
||
public record SubtractLikeCommand(Long placeId) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.now.naaga.place.domain; | ||
|
||
public record PlaceCreateEvent(Long temporaryPlaceId, | ||
Long placeId) { | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.now.naaga.temporaryplace.application; | ||
|
||
import com.now.naaga.place.domain.PlaceCreateEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
public class DeleteTemporaryPlaceWithPlaceCreateEventHandler { | ||
|
||
private final TemporaryPlaceService temporaryPlaceService; | ||
|
||
public DeleteTemporaryPlaceWithPlaceCreateEventHandler(final TemporaryPlaceService temporaryPlaceService) { | ||
this.temporaryPlaceService = temporaryPlaceService; | ||
} | ||
|
||
@Transactional | ||
@EventListener | ||
public void handle(final PlaceCreateEvent placeCreateEvent) { | ||
final Long temporaryPlaceId = placeCreateEvent.temporaryPlaceId(); | ||
temporaryPlaceService.deleteById(temporaryPlaceId); | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에 AWS S3에 저장된 사진 파일의 위치를 이동시키는 부분도 필요하겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S3 가 어떻게 진행되고 있는지 몰라서 어떤 코멘트인지 잘 모르겠습니다 🥲 수정이 필요하다는 의미이신가요? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정리 겸 for 채채
Long placeId) // 장소 통계를 만들기 위함
객체를 생성하고, 해당 객체로 이벤트를 발생시킨다
= PlaceCreateEvent()객체가 publish되었을 때, @eventlistener가 붙고 PlaceCreateEvent 매개변수를 갖는 메서드가 실행 되는 듯 함.
장소통계 서비스를 이용한 장소 통계가 생성된다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한가지 정정하겠습니다!
동시에 실행되지 않습니다. 비동기 이벤트가 아닌, 동기 이벤트이기 때문에 순서대로 실행됩니다 - !