Skip to content

Commit

Permalink
🐛Fix: request 시 userdate를 받는 현상 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Zena0128 committed Feb 19, 2024
1 parent 75ea4be commit 245d765
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ApiResponse createDo(HttpServletRequest request,
@PutMapping("/{doId}")
public ApiResponse updateDo(HttpServletRequest request,
@PathVariable long doId,
@RequestBody DoViewDTO doViewDTO)
@RequestBody DoRequestDTO doRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Expand All @@ -67,7 +67,7 @@ public ApiResponse updateDo(HttpServletRequest request,
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}

doService.updateDo(userId, doId, doViewDTO);
doService.updateDo(userId, doId, doRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ApiResponse createPlan(HttpServletRequest request,
@PutMapping("/{planId}")
public ApiResponse updatePlan(HttpServletRequest request,
@PathVariable long planId,
@RequestBody PlanViewDTO planViewDTO)
@RequestBody PlanRequestDTO planRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Expand All @@ -69,7 +69,7 @@ public ApiResponse updatePlan(HttpServletRequest request,
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}

planService.updatePlan(userId, planId, planViewDTO);
planService.updatePlan(userId, planId, planRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ApiResponse createSee(HttpServletRequest request,
@PutMapping("/{seeId}")
public ApiResponse updateSee(HttpServletRequest request,
@PathVariable long seeId,
@RequestBody SeeViewDTO seeViewDTO)
@RequestBody SeeRequestDTO seeRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Expand All @@ -67,7 +67,7 @@ public ApiResponse updateSee(HttpServletRequest request,
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}

seeService.updateSee(userId, seeId, seeViewDTO);
seeService.updateSee(userId, seeId, seeRequestDTO);
return ApiResponse.success(SuccessStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ public class CategoryCreateDTO {

private String name;
private String colorCode;
private User user;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ public class DoCreateDTO {
private LocalTime startTime;
private LocalTime endTime;
private Category category;
private UserDate userDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public class DoRequestDTO {
private LocalTime startTime;
private LocalTime endTime;
private long categoryId;
private long userDateId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ public class PlanCreateDTO {
private LocalTime endTime;
private boolean status;
private Category category;
private UserDate userDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public class PlanRequestDTO {
private LocalTime endTime;
private boolean status;
private long categoryId;
private long userDateId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
public class SeeCreateDTO {

private String content;
private UserDate userDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
public class SeeRequestDTO {

private String content;
private long userDateId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<CategoryViewDTO> readCategoryAll(long userId) {
public Category createCategory(long userId, CategoryRequestDTO categoryRequestDTO) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
CategoryCreateDTO categoryCreateDTO = new CategoryCreateDTO(categoryRequestDTO.getName(), categoryRequestDTO.getColorCode(), user);
CategoryCreateDTO categoryCreateDTO = new CategoryCreateDTO(categoryRequestDTO.getName(), categoryRequestDTO.getColorCode());
Category category = new Category(categoryCreateDTO, user);
return categoryRepository.save(category);
}
Expand All @@ -48,6 +48,7 @@ public void updateCategory(long userId, long categoryId, CategoryViewDTO categor
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
category.updateCategory(categoryViewDTO.getName(), categoryViewDTO.getColorCode());
categoryRepository.save(category);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@Service
public interface DoService {
Do createDo(long userId, DoRequestDTO doRequestDTO);
void updateDo(long userId, long doId, DoViewDTO doViewDTO);
void updateDo(long userId, long doId, DoRequestDTO doRequestDTO);
void deleteDo(long userId, long doId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.concurrent.CancellationException;

@Service
@RequiredArgsConstructor
Expand All @@ -34,19 +35,21 @@ public Do createDo(long userId, DoRequestDTO doRequestDTO) {
UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId());
Category category = categoryRepository.findById(doRequestDTO.getCategoryId())
.orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR));
DoCreateDTO doCreateDTO = new DoCreateDTO(doRequestDTO.getTitle(), doRequestDTO.getStartTime(), doRequestDTO.getEndTime(), category, userDate);
DoCreateDTO doCreateDTO = new DoCreateDTO(doRequestDTO.getTitle(), doRequestDTO.getStartTime(), doRequestDTO.getEndTime(), category);
Do done = new Do(doCreateDTO, userDate);
return doRepository.save(done);
}

@Override
public void updateDo(long userId, long doId, DoViewDTO doViewDTO) {
public void updateDo(long userId, long doId, DoRequestDTO doRequestDTO) {
Do done = doRepository.findById(doId)
.orElseThrow(() -> new CustomException(ErrorStatus.DO_NOT_FOUND_ERROR));
if (done.getUserDate().getUser().getId() != userId){
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
done.updateDo(doViewDTO.getTitle(), doViewDTO.getStartTime(), doViewDTO.getEndTime());
Category category = categoryRepository.findById(doRequestDTO.getCategoryId())
.orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR));
done.updateDo(doRequestDTO.getTitle(), doRequestDTO.getStartTime(), doRequestDTO.getEndTime(), category);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface PlanService {

Plan createPlan(long userId, PlanRequestDTO planRequestDTO);
void updatePlan(long userId, long planId, PlanViewDTO planViewDTO);
void updatePlan(long userId, long planId, PlanRequestDTO planRequestDTO);
void deletePlan(long userId, long planId);
void donePlan(long userId, long planId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ public Plan createPlan(long userId, PlanRequestDTO planRequestDTO) {
UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId());
Category category = categoryRepository.findById(planRequestDTO.getCategoryId())
.orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR));
PlanCreateDTO planCreateDTO = new PlanCreateDTO(planRequestDTO.getTitle(), planRequestDTO.getStartTime(), planRequestDTO.getEndTime(), planRequestDTO.isStatus(), category, userDate);
PlanCreateDTO planCreateDTO = new PlanCreateDTO(planRequestDTO.getTitle(), planRequestDTO.getStartTime(), planRequestDTO.getEndTime(), planRequestDTO.isStatus(), category);
Plan plan = new Plan(planCreateDTO, userDate);
return planRepository.save(plan);
}

@Override
public void updatePlan(long userId, long planId, PlanViewDTO planViewDTO) {
public void updatePlan(long userId, long planId, PlanRequestDTO planRequestDTO) {
Plan plan = planRepository.findById(planId)
.orElseThrow(() -> new CustomException(ErrorStatus.PLAN_NOT_FOUND_ERROR));
long categoryId = planRequestDTO.getCategoryId();
Category category = categoryRepository.findById(categoryId)
.orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR));
if (plan.getUserDate().getUser().getId() != userId) {
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
plan.updatePlan(planViewDTO.getTitle(), planViewDTO.getStartTime(), planViewDTO.getEndTime());
plan.updatePlan(planRequestDTO.getTitle(), planRequestDTO.getStartTime(), planRequestDTO.getEndTime(), category);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@Service
public interface SeeService {
See createSee(long userId, SeeRequestDTO seeRequestDTO);
void updateSee(long userId, long seeId, SeeViewDTO seeViewDTO);
void updateSee(long userId, long seeId, SeeRequestDTO seeRequestDTO);
void deleteSee(long userId, long seeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public See createSee(long userId, SeeRequestDTO seeRequestDTO) {
LocalDate localDate = LocalDate.now();
Date date = dateRepository.findByDate(localDate);
UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId());
SeeCreateDTO seeCreateDTO = new SeeCreateDTO(seeRequestDTO.getContent(), userDate);
SeeCreateDTO seeCreateDTO = new SeeCreateDTO(seeRequestDTO.getContent());
See see = new See(seeCreateDTO, userDate);
return seeRepository.save(see);
}

@Override
public void updateSee(long userId, long seeId, SeeViewDTO seeViewDTO) {
public void updateSee(long userId, long seeId, SeeRequestDTO seeRequestDTO) {
See see = seeRepository.findById(seeId)
.orElseThrow(() -> new CustomException(ErrorStatus.SEE_NOT_FOUND_ERROR));
if (see.getUserDate().getUser().getId() != userId){
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
see.updateSee(seeViewDTO.getContent());
see.updateSee(seeRequestDTO.getContent());
}

@Override
Expand Down

0 comments on commit 245d765

Please sign in to comment.