Skip to content

Commit

Permalink
Merge pull request #14 from Timetris-Trendithon/mainpage
Browse files Browse the repository at this point in the history
πŸ› Fix: LocalTime ν•„λ“œ 데이터 μ €μž₯ μ•ˆλ˜λ˜ 문제 μˆ˜μ •, μΉ΄ν…Œκ³ λ¦¬ μ—…λ°μ΄νŠΈ μ‹œ 아이디 ν•„μš”ν–ˆλ˜ ν˜„μƒ μˆ˜μ •
  • Loading branch information
Zena0128 authored Feb 19, 2024
2 parents 3db18e7 + ca09d76 commit 2e4862e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public ApiResponse<CategoryRequestDTO> createCategory(HttpServletRequest request
}

@PutMapping("/{categoryId}")
public ApiResponse<CategoryViewDTO> updateCategory(HttpServletRequest request,
public ApiResponse<CategoryRequestDTO> updateCategory(HttpServletRequest request,
@PathVariable long categoryId,
@RequestBody CategoryViewDTO categoryViewDTO)
@RequestBody CategoryRequestDTO categoryRequestDTO)
{
String accessToken = tokenProvider.extractAccessToken(request).orElse(null);

Expand All @@ -90,8 +90,8 @@ public ApiResponse<CategoryViewDTO> updateCategory(HttpServletRequest request,
throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR);
}

categoryService.updateCategory(userId, categoryId, categoryViewDTO);
return ApiResponse.success(SuccessStatus.OK, categoryViewDTO);
categoryService.updateCategory(userId, categoryId, categoryRequestDTO);
return ApiResponse.success(SuccessStatus.OK, categoryRequestDTO);
}

@DeleteMapping("/{categoryId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.trendithon.timetris.domain.mainpage.repository.PlanRepository;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;

import java.time.LocalTime;

Expand All @@ -19,7 +20,7 @@ public class Plan {
private String title;
private LocalTime startTime;
private LocalTime endTime;
private boolean status = false;
private boolean status;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "categoryId")
private Category category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
public class DoRequestDTO {

private String title;
private LocalTime startTime;
private LocalTime endTime;
private String startTime;
private String endTime;
private long categoryId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
public class PlanRequestDTO {

private String title;
private LocalTime startTime;
private LocalTime endTime;
private boolean status;
private String startTime;
private String endTime;
private long categoryId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface CategoryService {

List<CategoryViewDTO> readCategoryAll(long userId);
Category createCategory(long userId, CategoryRequestDTO categoryRequestDTO);
void updateCategory(long userId, long categoryId, CategoryViewDTO categoryViewDTO);
void updateCategory(long userId, long categoryId, CategoryRequestDTO categoryRequestDTO);
void deleteCategory(long userId, long categoryId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public Category createCategory(long userId, CategoryRequestDTO categoryRequestDT
}

@Override
public void updateCategory(long userId, long categoryId, CategoryViewDTO categoryViewDTO) {
public void updateCategory(long userId, long categoryId, CategoryRequestDTO categoryRequestDTO) {
Category category = categoryRepository.findById(categoryId)
.orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR));
if (category.getUser().getId() != userId){
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
category.updateCategory(categoryViewDTO.getName(), categoryViewDTO.getColorCode());
category.updateCategory(categoryRequestDTO.getName(), categoryRequestDTO.getColorCode());
categoryRepository.save(category);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -35,7 +37,11 @@ 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);
String[] startTime = doRequestDTO.getStartTime().split(":");
LocalTime localStartTime = LocalTime.of(Integer.parseInt(startTime[0]), Integer.parseInt(startTime[1]));
String[] endTime = doRequestDTO.getEndTime().split(":");
LocalTime localEndTime = LocalTime.of(Integer.parseInt(endTime[0]), Integer.parseInt(endTime[1]));
DoCreateDTO doCreateDTO = new DoCreateDTO(doRequestDTO.getTitle(), localStartTime, localEndTime, category);
Do done = new Do(doCreateDTO, userDate);
return doRepository.save(done);
}
Expand All @@ -49,7 +55,11 @@ public void updateDo(long userId, long doId, DoRequestDTO doRequestDTO) {
}
Category category = categoryRepository.findById(doRequestDTO.getCategoryId())
.orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR));
done.updateDo(doRequestDTO.getTitle(), doRequestDTO.getStartTime(), doRequestDTO.getEndTime(), category);
String[] startTime = doRequestDTO.getStartTime().split(":");
LocalTime localStartTime = LocalTime.of(Integer.parseInt(startTime[0]), Integer.parseInt(startTime[1]));
String[] endTime = doRequestDTO.getEndTime().split(":");
LocalTime localEndTime = LocalTime.of(Integer.parseInt(endTime[0]), Integer.parseInt(endTime[1]));
done.updateDo(doRequestDTO.getTitle(), localStartTime, localEndTime, category);
doRepository.save(done);
}

Expand Down
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.time.LocalTime;

@Service
@RequiredArgsConstructor
Expand All @@ -34,7 +35,11 @@ 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);
String[] startTime = planRequestDTO.getStartTime().split(":");
LocalTime localStartTime = LocalTime.of(Integer.parseInt(startTime[0]), Integer.parseInt(startTime[1]));
String[] endTime = planRequestDTO.getEndTime().split(":");
LocalTime localEndTime = LocalTime.of(Integer.parseInt(endTime[0]), Integer.parseInt(endTime[1]));
PlanCreateDTO planCreateDTO = new PlanCreateDTO(planRequestDTO.getTitle(), localStartTime, localEndTime, false, category);
Plan plan = new Plan(planCreateDTO, userDate);
return planRepository.save(plan);
}
Expand All @@ -49,7 +54,11 @@ public void updatePlan(long userId, long planId, PlanRequestDTO planRequestDTO)
if (plan.getUserDate().getUser().getId() != userId) {
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
plan.updatePlan(planRequestDTO.getTitle(), planRequestDTO.getStartTime(), planRequestDTO.getEndTime(), category);
String[] startTime = planRequestDTO.getStartTime().split(":");
LocalTime localStartTime = LocalTime.of(Integer.parseInt(startTime[0]), Integer.parseInt(startTime[1]));
String[] endTime = planRequestDTO.getEndTime().split(":");
LocalTime localEndTime = LocalTime.of(Integer.parseInt(endTime[0]), Integer.parseInt(endTime[1]));
plan.updatePlan(planRequestDTO.getTitle(), localStartTime, localEndTime, category);
planRepository.save(plan);
}

Expand All @@ -71,5 +80,6 @@ public void donePlan(long userId, long planId) {
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
plan.donePlan();
planRepository.save(plan);
}
}

0 comments on commit 2e4862e

Please sign in to comment.