Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
x-logging: &default-logging
driver: "json-file"
options:
max-size: "10m"
max-file: "3"

services:
nginx:
image: nginx:stable-alpine
Expand All @@ -15,6 +21,7 @@ services:
image: ${APP_IMAGE}
container_name: routee-app-blue
restart: unless-stopped
logging: *default-logging
expose:
- "8080"
environment:
Expand Down Expand Up @@ -51,6 +58,7 @@ services:
image: ${APP_IMAGE}
container_name: routee-app-green
restart: unless-stopped
logging: *default-logging
expose:
- "8080"
environment:
Expand Down Expand Up @@ -116,6 +124,7 @@ services:
image: grafana/tempo:latest
container_name: routee-tempo
restart: unless-stopped
logging: *default-logging
user: "0"
command: [ "-config.file=/etc/tempo.yaml" ]
volumes:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sopt.routee.activity.api.event;

public record ActivityDeletedEvent(
Long memberId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import org.sopt.routee.activity.internal.entity.activity.Activity;
import org.sopt.routee.activity.internal.entity.activity.ActivityStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import jakarta.persistence.LockModeType;

public interface ActivityRepository extends JpaRepository<Activity, Long> {
boolean existsByMemberIdAndActivityStatusIn(Long memberId, Collection<ActivityStatus> activityStatuses);

Expand All @@ -26,6 +29,9 @@ List<Long> findIdsByMemberIdAndActivityStatusIn(

Optional<Activity> findByIdAndMemberId(Long id, Long memberId);

@Lock(LockModeType.PESSIMISTIC_WRITE)
Optional<Activity> findForUpdateByIdAndMemberId(Long id, Long memberId);

List<Activity> findByMemberIdAndActivityStatusAndStartedAtBetweenOrderByStartedAtDesc(
Long memberId,
ActivityStatus activityStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.stream.Collectors;

import org.sopt.routee.activity.api.event.ActivityCompletedEvent;
import org.sopt.routee.activity.api.event.ActivityDeletedEvent;
import org.sopt.routee.activity.internal.entity.activity.Activity;
import org.sopt.routee.activity.internal.entity.activity.ActivityStatus;
import org.sopt.routee.activity.internal.entity.timeline.Timeline;
Expand Down Expand Up @@ -197,7 +198,7 @@ public UpdateActivityTitleResult updateTitle(UpdateActivityTitleCommand command)

@Transactional
public void complete(CompleteActivityCommand command) {
Activity activity = activityRepository.findByIdAndMemberId(command.activityId(), command.memberId())
Activity activity = activityRepository.findForUpdateByIdAndMemberId(command.activityId(), command.memberId())
.orElseThrow(ActivityNotFoundException::new);

if (activity.getActivityStatus().isCompleted()) {
Expand Down Expand Up @@ -375,7 +376,7 @@ public void deleteActivitiesByMemberId(long memberId) {

public void delete(Long activityId, Long memberId) {
Activity deletedActivity = transactionTemplate.execute(status -> {
Activity activity = activityRepository.findByIdAndMemberId(activityId, memberId)
Activity activity = activityRepository.findForUpdateByIdAndMemberId(activityId, memberId)
.orElseThrow(ActivityNotFoundException::new);

routeRepository.deleteByActivityIdIn(List.of(activityId));
Expand All @@ -384,6 +385,7 @@ public void delete(Long activityId, Long memberId) {

if (activity.getActivityStatus().isCompleted()) {
refreshDailySummaryAfterDelete(activity);
applicationEventPublisher.publishEvent(new ActivityDeletedEvent(memberId));
}

return activity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.routee.member.internal.listener;

import org.sopt.routee.activity.api.event.ActivityCompletedEvent;
import org.sopt.routee.activity.api.event.ActivityDeletedEvent;
import org.sopt.routee.member.internal.service.MemberService;
import org.springframework.modulith.events.ApplicationModuleListener;
import org.springframework.stereotype.Component;
Expand All @@ -17,4 +18,9 @@ class MemberActivityEventListener {
void handleActivityCompleted(ActivityCompletedEvent event) {
memberService.incrementTotalActivityCount(event.memberId());
}

@ApplicationModuleListener
void handleActivityDeleted(ActivityDeletedEvent event) {
memberService.decrementTotalActivityCount(event.memberId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
@Query("UPDATE Member m SET m.totalActivityCount = m.totalActivityCount + 1 WHERE m.id = :memberId")
void incrementTotalActivityCount(@Param("memberId") Long memberId);

@Modifying
@Query("UPDATE Member m SET m.totalActivityCount = m.totalActivityCount - 1 WHERE m.id = :memberId AND m.totalActivityCount > 0")
void decrementTotalActivityCount(@Param("memberId") Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ public void incrementTotalActivityCount(long memberId) {
memberRepository.incrementTotalActivityCount(memberId);
}

@Transactional
public void decrementTotalActivityCount(long memberId) {
memberRepository.decrementTotalActivityCount(memberId);
}

@Transactional(readOnly = true)
public ActivitySummaryResult getActivitySummary(long memberId, int year, int month) {
if (!memberRepository.existsById(memberId)) {
Expand Down
17 changes: 17 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ echo "Step 4: Removing old container ($OLD)..."
docker compose -f docker-compose.yml stop $OLD || true
docker compose -f docker-compose.yml rm -f $OLD || true

echo "Step 5: Cleaning up old application images..."

PREVIOUS_IMAGE=""
if [ -f .last-deployed-tag ]; then
PREVIOUS_IMAGE=$(cat .last-deployed-tag)
fi

APP_REPOSITORY="${APP_IMAGE%:*}"

docker images "$APP_REPOSITORY" --format '{{.Repository}}:{{.Tag}}' |
while read -r IMAGE; do
if [ "$IMAGE" != "$APP_IMAGE" ] &&
[ "$IMAGE" != "$PREVIOUS_IMAGE" ]; then
docker image rm "$IMAGE" || true
fi
done

docker image prune -f

echo "$APP_IMAGE" > .last-deployed-tag
Expand Down
Loading