Skip to content

Commit

Permalink
feat: ✨ 목표 재설정 구현 (#67)
Browse files Browse the repository at this point in the history
* feat: 몇가지 소소한 수정

* refactor: ♻️ user 디렉토리 구조 수정 (#53)

* hotfix: conflict solve (#55)

* refactor: ♻️ user 디렉토리 구조 수정

* hotfix: conflict solve

* hotfix: 🚑 build error 해결 (#57)

* refactor: ♻️ user 디렉토리 구조 수정

* hotfix: conflict solve

* hotfix: 🚑 sever restart

* fix: 루틴 삭제 기능 수정

* fix: 루틴 삭제 기능 수정

* docs: 📝 auth api 문서 추가 (#61)

* hotfix: server restart

* docs: 📝 auth api 문서 추가

* fix: 루틴 완수 예외처리

* fix: 루틴 완수 예외처리

* fix: 루틴 완수 예외처리

* feat: ✨ 목표 재설정 구현

---------

Co-authored-by: gzhan0226 <[email protected]>
  • Loading branch information
LEEJaeHyeok97 and gzhan0226 authored Sep 28, 2024
1 parent 91256f2 commit ae6945c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.request.RegenerateTeamRequest;
import com.goormdari.domain.team.dto.response.CreateTeamResponse;
import com.goormdari.domain.team.dto.response.findAllRoutineByUserIdResponse;
import com.goormdari.domain.team.exception.TeamAlreadyExistException;
Expand All @@ -12,6 +13,7 @@
import com.goormdari.domain.user.domain.repository.UserRepository;
import com.goormdari.global.config.email.EmailClient;
import com.goormdari.global.payload.Message;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -127,4 +129,19 @@ public Message join(String username, String joinCode) {
.message("팀(방)에 참여했습니다.")
.build();
}

@Transactional
public Message regenerateNewTeam(String username, RegenerateTeamRequest regenerateTeamRequest) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new NotFoundException("User not found"));


user.getTeam().updateForRegenerateObject(regenerateTeamRequest.goal(), regenerateTeamRequest.deadline(), regenerateTeamRequest.routine1(), regenerateTeamRequest.routine2(), regenerateTeamRequest.routine3(), regenerateTeamRequest.routine4());


return Message
.builder()
.message("목표를 재생성 했습니다.")
.build();
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/goormdari/domain/team/domain/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ public Team(String name, String goal, LocalDate deadLine, String routine1, Strin
this.routine4 = routine4;
this.joinCode = joinCode;
}

public void updateForRegenerateObject(String goal, LocalDate deadLine, String routine1, String routine2, String routine3, String routine4) {
this.goal = goal;
this.deadLine = deadLine;
this.routine1 = routine1;
this.routine2 = routine2;
this.routine3 = routine3;
this.routine4 = routine4;
}
}
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 RegenerateTeamRequest(
String goal,
LocalDate deadline,
String routine1,
String routine2,
String routine3,
String routine4
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.goormdari.domain.calendar.exception.InvalidTokenException;
import com.goormdari.domain.team.application.TeamService;
import com.goormdari.domain.team.dto.request.CreateTeamRequest;
import com.goormdari.domain.team.dto.request.RegenerateTeamRequest;
import com.goormdari.domain.team.dto.response.CreateTeamResponse;
import com.goormdari.domain.team.dto.response.findAllRoutineByUserIdResponse;
import com.goormdari.domain.team.dto.response.findByTeamIdResponse;
Expand Down Expand Up @@ -51,6 +52,24 @@ public ResponseCustom<CreateTeamResponse> createTeam(
return ResponseCustom.OK(teamService.createNewTeam(username, createTeamRequest));
}

@Operation(summary = "목표 재생성", description = "목표 기한 만료 후 목표를 재생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "목표 재생성 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
@ApiResponse(responseCode = "400", description = "목표 재생성 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PostMapping("/regenerate")
public ResponseCustom<Message> createTeam(
@Parameter(description = "Accesstoken을 입력해주세요.", required = true) @RequestHeader("Authorization") String token,
@Parameter(description = "Schemas의 CreateTeamRequest를 참고해주세요.", required = true) @Valid @RequestBody RegenerateTeamRequest regenerateTeamRequest
) {
String jwt = token.startsWith("Bearer ") ? token.substring(7) : token;
if (!jwtUtil.validateToken(jwt)) {
throw new IllegalArgumentException("Invalid token");
}
String username = jwtUtil.extractUsername(jwt);
return ResponseCustom.OK(teamService.regenerateNewTeam(username, regenerateTeamRequest));
}

@Operation(summary = "팀(방) 참여코드 전달", description = "팀(방) 참여코드를 이메일로 전달합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "팀(방) 참여코드 전달 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
Expand Down

0 comments on commit ae6945c

Please sign in to comment.