-
Notifications
You must be signed in to change notification settings - Fork 2
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
19 changed files
with
247 additions
and
121 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/com/hackathon/momento/auth/api/AuthController.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
2 changes: 1 addition & 1 deletion
2
...thon/momento/auth/api/dto/AuthResDto.java → ...nto/auth/api/dto/response/AuthResDto.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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/hackathon/momento/global/config/OpenAIConfig.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,23 @@ | ||
package com.hackathon.momento.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class OpenAIConfig { | ||
|
||
@Value("${openai.api.key}") | ||
private String openAIKey; | ||
|
||
@Bean | ||
public RestTemplate template() { | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.getInterceptors().add((request, body, execution) -> { | ||
request.getHeaders().add("Authorization", "Bearer " + openAIKey); | ||
return execution.execute(request, body); | ||
}); | ||
return restTemplate; | ||
} | ||
} |
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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/hackathon/momento/team/api/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,44 @@ | ||
package com.hackathon.momento.team.api; | ||
|
||
import com.hackathon.momento.global.template.RspTemplate; | ||
import com.hackathon.momento.team.api.dto.request.TeamBuildingReqDto; | ||
import com.hackathon.momento.team.application.TeamService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
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("/api/v1/team") | ||
@Tag(name = "팀", description = "팀을 담당하는 API 그룹") | ||
public class TeamController { | ||
|
||
private static final Long TEMP_MEMBER_ID = 1L; // 테스트용 임시 사용자 ID | ||
|
||
private final TeamService teamService; | ||
|
||
@PostMapping("/building") | ||
@Operation( | ||
summary = "팀 빌딩 정보 저장", | ||
description = "사용자가 팀 빌딩을 위해 필요한 정보들을 입력합니다.", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "팀 빌딩 정보 저장 성공"), | ||
@ApiResponse(responseCode = "400", description = "잘못된 요청"), | ||
@ApiResponse(responseCode = "500", description = "서버 오류") | ||
} | ||
) | ||
public RspTemplate<Void> saveTeamBuilding( | ||
// Principal principal, | ||
@Valid @RequestBody TeamBuildingReqDto reqDto) { | ||
|
||
teamService.saveTeamBuilding(TEMP_MEMBER_ID, reqDto); | ||
return new RspTemplate<>(HttpStatus.OK, "팀 빌딩 정보 저장 성공"); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/hackathon/momento/team/api/dto/request/TeamBuildingReqDto.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,43 @@ | ||
package com.hackathon.momento.team.api.dto.request; | ||
|
||
import com.hackathon.momento.member.domain.Member; | ||
import com.hackathon.momento.team.domain.Status; | ||
import com.hackathon.momento.team.domain.TeamBuilding; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
public record TeamBuildingReqDto( | ||
@NotNull(message = "프로젝트 시작 날짜는 필수 입력 항목입니다") | ||
@DateTimeFormat(pattern = "yyyy-MM-dd") | ||
LocalDate startDate, | ||
|
||
@NotNull(message = "프로젝트 종료 날짜는 필수 입력 항목입니다") | ||
@DateTimeFormat(pattern = "yyyy-MM-dd") | ||
LocalDate endDate, | ||
|
||
@Min(value = 2, message = "팀 인원 수는 최소 2명이어야 합니다") | ||
@Max(value = 6, message = "팀 인원 수는 최대 6명이어야 합니다") | ||
int teamSize, | ||
|
||
@NotBlank(message = "본인 포지션은 필수 입력 항목입니다") | ||
String myPosition, | ||
|
||
@NotBlank(message = "요구 포지션 조합은 필수 입력 항목입니다") | ||
String positionCombination | ||
) { | ||
public TeamBuilding toEntity(Member member) { | ||
return TeamBuilding.builder() | ||
.startDate(this.startDate) | ||
.endDate(this.endDate) | ||
.teamSize(this.teamSize) | ||
.myPosition(this.myPosition) | ||
.positionCombination(this.positionCombination) | ||
.status(Status.PENDING) | ||
.member(member) | ||
.build(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/hackathon/momento/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,34 @@ | ||
package com.hackathon.momento.team.application; | ||
|
||
import com.hackathon.momento.member.domain.Member; | ||
import com.hackathon.momento.member.domain.repository.MemberRepository; | ||
import com.hackathon.momento.member.exception.MemberNotFoundException; | ||
import com.hackathon.momento.team.api.dto.request.TeamBuildingReqDto; | ||
import com.hackathon.momento.team.domain.Status; | ||
import com.hackathon.momento.team.domain.repository.TeamBuildingRepository; | ||
import com.hackathon.momento.team.exception.TeamBuildingConflictException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class TeamService { | ||
|
||
private final TeamBuildingRepository teamBuildingRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Transactional | ||
public void saveTeamBuilding(Long memberId, TeamBuildingReqDto reqDto) { | ||
// Long memberId = Long.parseLong(principal.getName()); | ||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(MemberNotFoundException::new); | ||
|
||
if (teamBuildingRepository.existsByMemberAndStatus(member, Status.PENDING)) { | ||
throw new TeamBuildingConflictException(); | ||
} | ||
|
||
teamBuildingRepository.save(reqDto.toEntity(member)); | ||
} | ||
} |
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,5 +1,5 @@ | ||
package com.hackathon.momento.team.domain; | ||
|
||
public enum Status { | ||
PENDING, COMPLETED | ||
PENDING, RETRY, COMPLETED | ||
} |
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
Oops, something went wrong.