-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 리그 삭제
- Loading branch information
Showing
11 changed files
with
363 additions
and
168 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
29 changes: 19 additions & 10 deletions
29
src/main/java/com/sports/server/command/league/application/LeagueService.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,25 +1,34 @@ | ||
package com.sports.server.command.league.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.sports.server.auth.exception.AuthorizationErrorMessages; | ||
import com.sports.server.command.league.domain.League; | ||
import com.sports.server.command.league.domain.LeagueRepository; | ||
import com.sports.server.command.league.dto.LeagueRequestDto; | ||
import com.sports.server.command.member.domain.Member; | ||
import com.sports.server.command.organization.domain.Organization; | ||
import com.sports.server.common.application.EntityUtils; | ||
|
||
import com.sports.server.common.exception.UnauthorizedException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class LeagueService { | ||
private final EntityUtils entityUtils; | ||
private final LeagueRepository leagueRepository; | ||
private final EntityUtils entityUtils; | ||
private final LeagueRepository leagueRepository; | ||
|
||
public void register(final Member manager, final LeagueRequestDto.Register request) { | ||
Organization organization = entityUtils.getEntity(request.organizationId(), Organization.class); | ||
leagueRepository.save(request.toEntity(manager, organization)); | ||
} | ||
|
||
public void register(final Member manager, final LeagueRequestDto.Register request) { | ||
Organization organization = entityUtils.getEntity(request.organizationId(), Organization.class); | ||
leagueRepository.save(request.toEntity(manager, organization)); | ||
} | ||
public void delete(final Member manager, final Long leagueId) { | ||
League league = entityUtils.getEntity(leagueId, League.class); | ||
if (!league.isManagedBy(manager)) { | ||
throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); | ||
} | ||
leagueRepository.delete(league); | ||
} | ||
} |
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
32 changes: 20 additions & 12 deletions
32
src/main/java/com/sports/server/command/league/presentation/LeagueController.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,24 +1,32 @@ | ||
package com.sports.server.command.league.presentation; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.sports.server.command.league.application.LeagueService; | ||
import com.sports.server.command.league.dto.LeagueRequestDto; | ||
import com.sports.server.command.member.domain.Member; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
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.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/leagues") | ||
public class LeagueController { | ||
private final LeagueService leagueService; | ||
private final LeagueService leagueService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> register(@RequestBody final LeagueRequestDto.Register register, Member member) { | ||
leagueService.register(member, register); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PostMapping("/leagues") | ||
public ResponseEntity<Void> register(@RequestBody final LeagueRequestDto.Register register, Member member) { | ||
leagueService.register(member, register); | ||
return ResponseEntity.ok().build(); | ||
} | ||
@DeleteMapping("/{leagueId}") | ||
public ResponseEntity<Void> delete(final Member member, @PathVariable final Long leagueId) { | ||
leagueService.delete(member, leagueId); | ||
return ResponseEntity.ok().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
75 changes: 46 additions & 29 deletions
75
src/test/java/com/sports/server/command/league/acceptance/LeagueAcceptanceTest.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,41 +1,58 @@ | ||
package com.sports.server.command.league.acceptance; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import com.sports.server.command.league.dto.LeagueRequestDto; | ||
import com.sports.server.support.AcceptanceTest; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
@Sql("/league-fixture.sql") | ||
public class LeagueAcceptanceTest extends AcceptanceTest { | ||
@Test | ||
void 대회를_저장한다() throws Exception { | ||
// given | ||
LeagueRequestDto.Register request = new LeagueRequestDto.Register(1L, "우물정 제기차기 대회", "4강", LocalDateTime.now(), | ||
LocalDateTime.now()); | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
|
||
// when | ||
ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
.cookie(COOKIE_NAME, mockToken) | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.post("/leagues") | ||
.then().log().all() | ||
.extract(); | ||
|
||
// then | ||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); | ||
} | ||
@Test | ||
void 대회를_저장한다() { | ||
// given | ||
LeagueRequestDto.Register request = new LeagueRequestDto.Register(1L, "우물정 제기차기 대회", "4강", LocalDateTime.now(), | ||
LocalDateTime.now()); | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
|
||
// when | ||
ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
.cookie(COOKIE_NAME, mockToken) | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.post("/leagues") | ||
.then().log().all() | ||
.extract(); | ||
|
||
// then | ||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); | ||
} | ||
|
||
@Test | ||
void 리그를_삭제한다() { | ||
// given | ||
Long leagueId = 1L; | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
|
||
// when | ||
ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
.cookie(COOKIE_NAME, mockToken) | ||
.pathParam("leagueId", leagueId) | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.delete("/leagues/{leagueId}") | ||
.then().log().all() | ||
.extract(); | ||
|
||
// then | ||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); | ||
} | ||
} |
Oops, something went wrong.