-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 검수 중인 장소에 대한 등록 승인 거절 API 구현 (#401)
* refactor: 바뀐 API 명세에 따라 컨트롤러 로직 리팩터링 * feat: 리베이스 충돌 해결 * feat: 검수 장소에 대한 테스트 빌더 구현 * feat: 검수 장소 삭제 API 구현 * feat: 검수 장소 삭제 API 에 ManagerAuthInterceptor 적용 * feat: 검수 장소에서 Player 에 대해 지연로딩 적용 * test: mocking 삭제 및 상태 검증 테스트로 변경 * test: 행위 검증에서 상태 검증 테스트로 변경
- Loading branch information
Showing
9 changed files
with
249 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
package com.now.naaga.temporaryplace.application; | ||
|
||
import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional | ||
@Service | ||
public class TemporaryPlaceService { | ||
|
||
private final TemporaryPlaceRepository temporaryPlaceRepository; | ||
|
||
public TemporaryPlaceService(final TemporaryPlaceRepository temporaryPlaceRepository) { | ||
this.temporaryPlaceRepository = temporaryPlaceRepository; | ||
} | ||
|
||
public void deleteById(final Long id) { | ||
return; | ||
temporaryPlaceRepository.deleteById(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...end/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
package com.now.naaga.temporaryplace.presentation; | ||
|
||
import com.now.naaga.temporaryplace.application.TemporaryPlaceService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/temporary-places") | ||
@RestController | ||
public class TemporaryPlaceController { | ||
|
||
private final TemporaryPlaceService temporaryPlaceService; | ||
|
||
public TemporaryPlaceController(final TemporaryPlaceService temporaryPlaceService) { | ||
this.temporaryPlaceService = temporaryPlaceService; | ||
} | ||
|
||
@DeleteMapping("/{temporaryPlaceId}") | ||
public ResponseEntity<Void> deleteTemporaryPlace(@PathVariable final Long temporaryPlaceId) { | ||
temporaryPlaceService.deleteById(temporaryPlaceId); | ||
return ResponseEntity | ||
.status(HttpStatus.NO_CONTENT) | ||
.build(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
backend/src/test/java/com/now/naaga/common/builder/TemporaryPlaceBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.now.naaga.common.builder; | ||
|
||
import static com.now.naaga.common.fixture.PlaceFixture.DESCRIPTION; | ||
import static com.now.naaga.common.fixture.PlaceFixture.IMAGE_URL; | ||
import static com.now.naaga.common.fixture.PlaceFixture.NAME; | ||
import static com.now.naaga.common.fixture.PositionFixture.잠실역_교보문고_좌표; | ||
|
||
import com.now.naaga.place.domain.Position; | ||
import com.now.naaga.player.domain.Player; | ||
import com.now.naaga.temporaryplace.domain.TemporaryPlace; | ||
import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; | ||
import java.util.Optional; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class TemporaryPlaceBuilder { | ||
|
||
@Autowired | ||
private TemporaryPlaceRepository temporaryPlaceRepository; | ||
|
||
@Autowired | ||
private PlayerBuilder playerBuilder; | ||
|
||
private String name; | ||
|
||
private String description; | ||
|
||
private Position position; | ||
|
||
private String imageUrl; | ||
|
||
private Optional<Player> registeredPlayer; | ||
|
||
public TemporaryPlaceBuilder init() { | ||
this.name = NAME; | ||
this.description = DESCRIPTION; | ||
this.position = 잠실역_교보문고_좌표; | ||
this.imageUrl = IMAGE_URL; | ||
this.registeredPlayer = Optional.empty(); | ||
return this; | ||
} | ||
|
||
public TemporaryPlaceBuilder name(final String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public TemporaryPlaceBuilder description(final String description) { | ||
this.description = description; | ||
return this; | ||
} | ||
|
||
public TemporaryPlaceBuilder position(final Position position) { | ||
this.position = position; | ||
return this; | ||
} | ||
|
||
public TemporaryPlaceBuilder imageUrl(final String imageUrl) { | ||
this.imageUrl = imageUrl; | ||
return this; | ||
} | ||
|
||
public TemporaryPlaceBuilder registeredPlayer(final Player persistedPlayer) { | ||
this.registeredPlayer = Optional.ofNullable(persistedPlayer); | ||
return this; | ||
} | ||
|
||
public TemporaryPlace build() { | ||
final Player persistedPlayer = registeredPlayer.orElseGet(this::getPersistedPlayer); | ||
final TemporaryPlace temporaryPlace = new TemporaryPlace(name, description, position, imageUrl, persistedPlayer); | ||
return temporaryPlaceRepository.save(temporaryPlace); | ||
} | ||
|
||
private Player getPersistedPlayer() { | ||
return playerBuilder.init() | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...end/src/test/java/com/now/naaga/temporaryplace/application/TemporaryPlaceServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.now.naaga.temporaryplace.application; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.now.naaga.common.builder.TemporaryPlaceBuilder; | ||
import com.now.naaga.temporaryplace.domain.TemporaryPlace; | ||
import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
@Sql("/truncate.sql") | ||
@ActiveProfiles("test") | ||
@SpringBootTest | ||
class TemporaryPlaceServiceTest { | ||
|
||
@Autowired | ||
private TemporaryPlaceRepository temporaryPlaceRepository; | ||
|
||
@Autowired | ||
private TemporaryPlaceService temporaryPlaceService; | ||
|
||
@Autowired | ||
private TemporaryPlaceBuilder temporaryPlaceBuilder; | ||
|
||
@Test | ||
void ID로_검수_장소_데이터를_삭제한다() { | ||
// given | ||
final TemporaryPlace temporaryPlace = temporaryPlaceBuilder.init() | ||
.build(); | ||
|
||
final Long id = temporaryPlace.getId(); | ||
|
||
// when | ||
temporaryPlaceService.deleteById(id); | ||
|
||
// then | ||
final TemporaryPlace actual = temporaryPlaceRepository.findById(id) | ||
.orElse(null); | ||
|
||
assertThat(actual).isNull(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.now.naaga.temporaryplace.presentation; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.now.naaga.common.CommonControllerTest; | ||
import com.now.naaga.common.builder.TemporaryPlaceBuilder; | ||
import com.now.naaga.temporaryplace.domain.TemporaryPlace; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
@ActiveProfiles("test") | ||
class TemporaryPlaceControllerTest extends CommonControllerTest { | ||
|
||
@Autowired | ||
private TemporaryPlaceBuilder temporaryPlaceBuilder; | ||
|
||
@Value("${manager.id}") | ||
private String id; | ||
|
||
@Value("${manager.password}") | ||
private String password; | ||
|
||
@BeforeEach | ||
protected void setUp() { | ||
super.setUp(); | ||
} | ||
|
||
@Test | ||
void ID를_통한_삭제_요청이_성공하면_204_응답코드를_반환한다() { | ||
// given | ||
final TemporaryPlace temporaryPlace = temporaryPlaceBuilder.init() | ||
.build(); | ||
|
||
// when | ||
final ExtractableResponse<Response> extract = RestAssured.given() | ||
.log().all() | ||
.auth().preemptive().basic(id, password) | ||
.when() | ||
.delete("/temporary-places/{temporaryPlaceId}", temporaryPlace.getId()) | ||
.then() | ||
.log().all() | ||
.extract(); | ||
|
||
// then | ||
final int statusCode = extract.statusCode(); | ||
assertThat(statusCode).isEqualTo(HttpStatus.NO_CONTENT.value()); | ||
} | ||
} |