-
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.
* chore: timezone seoul 설정 * chore: 깃 템플릿 추가, readme.md 추가 * chore: 예외처리, 전역 환경 설정 외 * feat: 데이터 모델링 * chore: 🐳 cicd 설정 * chore: 🐳 workflow lowercase 로 수정 * chore: 디스코드 webhook 테스트 * chore: :global: cors 설정 * chore: 🐳 cors 변경사항 yml 재적용 * feat: ✨ 팀(방) 생성 기능 구현 (#9)
- Loading branch information
1 parent
4dc0f12
commit 76452d7
Showing
10 changed files
with
163 additions
and
7 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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/goormdari/domain/calendar/domain/repository/CalendarRepository.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,7 @@ | ||
package com.goormdari.domain.calendar.domain.repository; | ||
|
||
import com.goormdari.domain.calendar.domain.Calendar; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CalendarRepository extends JpaRepository<Calendar, Long> { | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/goormdari/domain/team/application/TeamService.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,56 @@ | ||
package com.goormdari.domain.team.application; | ||
|
||
import com.amazonaws.services.kms.model.NotFoundException; | ||
import com.goormdari.domain.team.domain.Team; | ||
import com.goormdari.domain.team.domain.repository.TeamRepository; | ||
import com.goormdari.domain.team.dto.request.CreateTeamRequest; | ||
import com.goormdari.domain.team.dto.response.CreateTeamResponse; | ||
import com.goormdari.domain.team.exception.TeamAlreadyExistException; | ||
import com.goormdari.domain.user.domain.User; | ||
import com.goormdari.domain.user.domain.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class TeamService { | ||
|
||
private final TeamRepository teamRepository; | ||
private final UserRepository userRepository; | ||
|
||
|
||
@Transactional | ||
public CreateTeamResponse createNewTeam(final Long userId, final CreateTeamRequest createTeamRequest) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new NotFoundException("User not found")); | ||
|
||
if (user.getTeam() != null) { | ||
throw new TeamAlreadyExistException(); | ||
} | ||
|
||
String joinCode = UUID.randomUUID().toString(); | ||
|
||
Team team = Team.builder() | ||
.goal(createTeamRequest.goal()) | ||
.deadLine(createTeamRequest.deadline()) | ||
.routine1(createTeamRequest.routine1()) | ||
.routine2(createTeamRequest.routine2()) | ||
.routine3(createTeamRequest.routine3()) | ||
.routine4(createTeamRequest.routine4()) | ||
.joinCode(joinCode) | ||
.build(); | ||
|
||
teamRepository.save(team); | ||
|
||
user.updateTeam(team); | ||
|
||
return CreateTeamResponse | ||
.builder() | ||
.joinCode(joinCode) | ||
.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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/goormdari/domain/team/domain/repository/TeamRepository.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,7 @@ | ||
package com.goormdari.domain.team.domain.repository; | ||
|
||
import com.goormdari.domain.team.domain.Team; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TeamRepository extends JpaRepository<Team, Long> { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/goormdari/domain/team/dto/request/CreateTeamRequest.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,16 @@ | ||
package com.goormdari.domain.team.dto.request; | ||
|
||
import lombok.Builder; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Builder | ||
public record CreateTeamRequest( | ||
String goal, | ||
LocalDate deadline, | ||
String routine1, | ||
String routine2, | ||
String routine3, | ||
String routine4 | ||
) { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/goormdari/domain/team/dto/response/CreateTeamResponse.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,9 @@ | ||
package com.goormdari.domain.team.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CreateTeamResponse( | ||
String joinCode | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/goormdari/domain/team/exception/TeamAlreadyExistException.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,8 @@ | ||
package com.goormdari.domain.team.exception; | ||
|
||
public class TeamAlreadyExistException extends RuntimeException { | ||
|
||
public TeamAlreadyExistException() { | ||
super("해당 유저의 팀이 이미 존재합니다."); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/goormdari/domain/team/presentation/TeamController.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,40 @@ | ||
package com.goormdari.domain.team.presentation; | ||
|
||
import com.goormdari.domain.team.application.TeamService; | ||
import com.goormdari.domain.team.dto.request.CreateTeamRequest; | ||
import com.goormdari.domain.team.dto.response.CreateTeamResponse; | ||
import com.goormdari.global.payload.ErrorResponse; | ||
import com.goormdari.global.payload.ResponseCustom; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Tag(name = "Team", description = "Team API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/team") | ||
public class TeamController { | ||
|
||
private final TeamService teamService; | ||
|
||
@Operation(summary = "팀(방) 생성", description = "팀(방)을 생성합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "팀(방) 생성 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CreateTeamResponse.class))}), | ||
@ApiResponse(responseCode = "400", description = "팀(방) 생성 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), | ||
}) | ||
@PostMapping | ||
public ResponseCustom<CreateTeamResponse> createTeam( | ||
@Parameter(description = "Accesstoken을 입력해주세요.", required = true) @RequestHeader Long userId, | ||
@Parameter(description = "Schemas의 CreateTeamRequest를 참고해주세요.", required = true) @Valid @RequestBody CreateTeamRequest createTeamRequest | ||
) { | ||
return ResponseCustom.OK(teamService.createNewTeam(userId, createTeamRequest)); | ||
} | ||
|
||
} |
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