Skip to content

Commit

Permalink
Merge pull request #12 from Timetris-Trendithon/mainpage
Browse files Browse the repository at this point in the history
πŸ› Fix: read μ‹œ id 리턴, μΉ΄ν…Œκ³ λ¦¬ μˆ˜μ • κ°€λŠ₯ν•˜κ²Œλ”, post/put request μ‹œ userdate 없이도 κ°€λŠ₯ν•˜κ²Œλ”
  • Loading branch information
Zena0128 authored Feb 19, 2024
2 parents afa60a2 + 245d765 commit bb0b89e
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 28 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 @@ -35,10 +35,11 @@ public Do(DoCreateDTO doCreateDTO, UserDate userDate){
this.userDate = userDate;
}

public void updateDo(String title, LocalTime startTime, LocalTime endTime){
public void updateDo(String title, LocalTime startTime, LocalTime endTime, Category category){
this.title = title;
this.startTime = startTime;
this.endTime = endTime;
this.category = category;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public Plan(PlanCreateDTO planCreateDTO, UserDate userDate){
this.userDate = userDate;
}

public void updatePlan(String title, LocalTime startTime, LocalTime endTime){
public void updatePlan(String title, LocalTime startTime, LocalTime endTime, Category category){
this.title = title;
this.startTime = startTime;
this.endTime = endTime;
this.category = category;
}

public void donePlan(){
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 @@ -14,11 +14,13 @@
@AllArgsConstructor @NoArgsConstructor
public class CategoryViewDTO {

private long id;
private String name;
private String colorCode;

public static CategoryViewDTO of(Category category){
return CategoryViewDTO.builder()
.id(category.getId())
.name(category.getName())
.colorCode(category.getColorCode())
.build();
Expand Down
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 @@ -16,13 +16,15 @@
@AllArgsConstructor @NoArgsConstructor
public class DoViewDTO {

private long id;
private String title;
private LocalTime startTime;
private LocalTime endTime;
private CategoryViewDTO category;

public static DoViewDTO of(Do does){
return DoViewDTO.builder()
.id(does.getId())
.title(does.getTitle())
.startTime(does.getStartTime())
.endTime(does.getEndTime())
Expand Down
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 @@ -15,6 +15,7 @@
@AllArgsConstructor @NoArgsConstructor
public class PlanViewDTO {

private long id;
private String title;
private LocalTime startTime;
private LocalTime endTime;
Expand All @@ -23,6 +24,7 @@ public class PlanViewDTO {

public static PlanViewDTO of(Plan plan){
return PlanViewDTO.builder()
.id(plan.getId())
.title(plan.getTitle())
.startTime(plan.getStartTime())
.endTime(plan.getEndTime())
Expand Down
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 @@ -14,10 +14,12 @@
@AllArgsConstructor @NoArgsConstructor
public class SeeViewDTO {

private long id;
private String content;

public static SeeViewDTO of(See see){
return SeeViewDTO.builder()
.id(see.getId())
.content(see.getContent())
.build();
}
Expand Down
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 bb0b89e

Please sign in to comment.