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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.sopt.app.application.user.UserWithdrawEvent;
import org.sopt.app.common.event.EventPublisher;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.exception.ForbiddenException;
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.domain.entity.soptamp.Stamp;
import org.sopt.app.interfaces.postgres.StampRepository;
Expand Down Expand Up @@ -185,9 +186,9 @@ public Long getMissionIdByStampId(Long stampId) {
}

@Transactional(readOnly = true)
public Stamp getStampById(Long stampId) {
return stampRepository.findById(stampId)
.orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND));
public Stamp getStampForDelete(Long stampId, Long userId) {
return stampRepository.findByIdAndUserId(stampId, userId)
.orElseThrow(() -> new ForbiddenException(ErrorCode.STAMP_DELETE_FORBIDDEN));
}

public void deleteAll() {
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/sopt/app/facade/SoptampFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.sopt.app.application.soptamp.*;
import org.sopt.app.application.stamp.StampInfo.Stamp;
import org.sopt.app.application.stamp.StampService;
import org.sopt.app.common.exception.ForbiddenException;
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.domain.entity.soptamp.Mission;
import org.sopt.app.presentation.rank.*;
import org.sopt.app.presentation.stamp.StampRequest;
Expand Down Expand Up @@ -49,11 +47,7 @@ public Stamp editStamp(Long userId, StampRequest.EditStampRequest request){

@Transactional
public void deleteStamp(Long userId, Long stampId){
val stamp = stampService.getStampById(stampId);
if(!stamp.getUserId().equals(userId)){
throw new ForbiddenException(ErrorCode.STAMP_DELETE_FORBIDDEN);
}

val stamp = stampService.getStampForDelete(stampId, userId);
val mission = missionService.getMissionById(stamp.getMissionId());
soptampUserService.subtractPointByLevel(userId, mission.getLevel());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface StampRepository extends JpaRepository<Stamp, Long> {

void deleteAllByUserId(Long userId);

Optional<Stamp> findByIdAndUserId(Long id, Long userId);

}
4 changes: 2 additions & 2 deletions src/test/java/org/sopt/app/facade/SoptampFacadeTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.app.facade;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.sopt.app.common.fixtures.SoptampFixture.*;
Expand Down Expand Up @@ -78,7 +78,7 @@ void SUCCESS_deleteStamp() {
.contents(STAMP_CONTENTS)
.activityDate(STAMP_ACTIVITY_DATE)
.build();
given(stampService.getStampById(STAMP_ID)).willReturn(stamp);
given(stampService.getStampForDelete(STAMP_ID, SOPTAMP_USER_ID)).willReturn(stamp);
given(missionService.getMissionById(MISSION_ID)).willReturn(MissionInfo.Level.of(MISSION_LEVEL));

// when
Expand Down