Skip to content

Commit

Permalink
✨Feat: 메인페이지 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Zena0128 committed Feb 17, 2024
1 parent 86af4ee commit 4af4efd
Show file tree
Hide file tree
Showing 29 changed files with 779 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.trendithon.timetris.domain.mainpage.controller;

import com.trendithon.timetris.domain.mainpage.domain.Category;
import com.trendithon.timetris.domain.mainpage.dto.CategoryCreateDTO;
import com.trendithon.timetris.domain.mainpage.dto.CategoryRequestDTO;
import com.trendithon.timetris.domain.mainpage.dto.CategoryViewDTO;
import com.trendithon.timetris.domain.mainpage.service.CategoryService;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/category")
public class CategoryController {

private final CategoryService categoryService;

@GetMapping("/{userId}")
public ApiResponse<List<Category>> readCategoryAll(Authentication authentication,
@PathVariable long userId)
{
List<Category> categoryList = categoryService.readCategoryAll(userId);
return ApiResponse.success(SuccessStatus.OK, categoryList);
}

@PostMapping("")
public ApiResponse createCategory(Authentication authentication,
@RequestBody CategoryRequestDTO categoryRequestDTO)
{
long userId = 1;
Category category = categoryService.createCategory(userId, categoryRequestDTO);
if (category == null){
throw new CustomException(ErrorStatus.INVALID_FORMAT_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
}

@PutMapping("/{categoryId}")
public ApiResponse updateCategory(Authentication authentication,
@PathVariable long categoryId,
@RequestBody CategoryViewDTO categoryViewDTO)
{
long userId = 1;
categoryService.updateCategory(userId, categoryId, categoryViewDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{categoryId}")
public ApiResponse deleteCategory(Authentication authentication,
@PathVariable long categoryId)
{
long userId = 1;
categoryService.deleteCategory(userId, categoryId);
return ApiResponse.success(SuccessStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.trendithon.timetris.domain.mainpage.controller;

import com.trendithon.timetris.domain.mainpage.domain.Do;
import com.trendithon.timetris.domain.mainpage.dto.DoCreateDTO;
import com.trendithon.timetris.domain.mainpage.dto.DoRequestDTO;
import com.trendithon.timetris.domain.mainpage.dto.DoViewDTO;
import com.trendithon.timetris.domain.mainpage.service.DoService;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/do")
public class DoController {

private final DoService doService;

@PostMapping("")
public ApiResponse createDo(Authentication authentication,
@RequestBody DoRequestDTO doRequestDTO)
{
long userId = 1;
Do done = doService.createDo(userId, doRequestDTO);
if (done == null){
throw new CustomException(ErrorStatus.INVALID_FORMAT_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
}

@PutMapping("/{doId}")
public ApiResponse updateDo(Authentication authentication,
@PathVariable long doId,
@RequestBody DoViewDTO doViewDTO)
{
long userId = 1;
doService.updateDo(userId, doId, doViewDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{doId}")
public ApiResponse deleteDo(Authentication authentication,
@PathVariable long doId)
{
long userId = 1;
doService.deleteDo(userId, doId);
return ApiResponse.success(SuccessStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.trendithon.timetris.domain.mainpage.controller;

import com.trendithon.timetris.domain.mainpage.dto.MainPageDTO;
import com.trendithon.timetris.domain.mainpage.service.MainPageService;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequiredArgsConstructor
@RequestMapping("/main")
public class MainPageController {

private final MainPageService mainPageService;

@GetMapping("/{userId}")
public ApiResponse<MainPageDTO> getMainPage(Authentication authentication,
@PathVariable long userId)
{
MainPageDTO mainPageDTO = mainPageService.getMainPage(userId);
return ApiResponse.success(SuccessStatus.OK, mainPageDTO);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.trendithon.timetris.domain.mainpage.controller;

import com.trendithon.timetris.domain.mainpage.domain.Plan;
import com.trendithon.timetris.domain.mainpage.dto.PlanCreateDTO;
import com.trendithon.timetris.domain.mainpage.dto.PlanRequestDTO;
import com.trendithon.timetris.domain.mainpage.dto.PlanViewDTO;
import com.trendithon.timetris.domain.mainpage.service.PlanService;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/plan")
public class PlanController {

private final PlanService planService;

@PostMapping("")
public ApiResponse createPlan(Authentication authentication,
@RequestBody PlanRequestDTO planRequestDTO)
{
long userId = 1;
Plan plan = planService.createPlan(userId, planRequestDTO);
if (plan == null){
throw new CustomException(ErrorStatus.INVALID_FORMAT_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
}

@PutMapping("/{planId}")
public ApiResponse updatePlan(Authentication authentication,
@PathVariable long planId,
@RequestBody PlanViewDTO planViewDTO)
{
long userId = 1;
planService.updatePlan(userId, planId, planViewDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{planId}")
public ApiResponse deletePlan(Authentication authentication,
@PathVariable long planId)
{
long userId = 1;
planService.deletePlan(userId, planId);
return ApiResponse.success(SuccessStatus.OK);
}

@PutMapping("/{planId}/check")
public ApiResponse donePlan(Authentication authentication,
@PathVariable long planId)
{
long userId = 1;
planService.donePlan(userId, planId);
return ApiResponse.success(SuccessStatus.OK);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.trendithon.timetris.domain.mainpage.controller;

import com.trendithon.timetris.domain.mainpage.domain.See;
import com.trendithon.timetris.domain.mainpage.dto.SeeCreateDTO;
import com.trendithon.timetris.domain.mainpage.dto.SeeRequestDTO;
import com.trendithon.timetris.domain.mainpage.dto.SeeViewDTO;
import com.trendithon.timetris.domain.mainpage.service.SeeService;
import com.trendithon.timetris.global.exception.ApiResponse;
import com.trendithon.timetris.global.exception.CustomException;
import com.trendithon.timetris.global.exception.enums.ErrorStatus;
import com.trendithon.timetris.global.exception.enums.SuccessStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/see")
public class SeeController {

private final SeeService seeService;

@PostMapping("")
public ApiResponse createSee(Authentication authentication,
@RequestBody SeeRequestDTO seeRequestDTO)
{
long userId = 1;
See see = seeService.createSee(userId, seeRequestDTO);
if (see == null){
throw new CustomException(ErrorStatus.SEE_NOT_FOUND_ERROR);
}
return ApiResponse.success(SuccessStatus.OK);
}

@PutMapping("/{seeId}")
public ApiResponse updateSee(Authentication authentication,
@PathVariable long seeId,
@RequestBody SeeViewDTO seeViewDTO)
{
long userId = 1;
seeService.updateSee(userId, seeId, seeViewDTO);
return ApiResponse.success(SuccessStatus.OK);
}

@DeleteMapping("/{seeId}")
public ApiResponse deleteSee(Authentication authentication,
@PathVariable long seeId)
{
long userId = 1;
seeService.deleteSee(userId, seeId);
return ApiResponse.success(SuccessStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.trendithon.timetris.domain.mainpage.dto.PlanCreateDTO;
import com.trendithon.timetris.domain.mainpage.dto.PlanViewDTO;
import com.trendithon.timetris.domain.mainpage.repository.PlanRepository;
import jakarta.persistence.*;
import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.trendithon.timetris.domain.mainpage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor @NoArgsConstructor
public class CategoryRequestDTO {

private String name;
private String colorCode;

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package com.trendithon.timetris.domain.mainpage.dto;

import com.trendithon.timetris.domain.mainpage.domain.Category;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor @NoArgsConstructor
public class CategoryViewDTO {

private String name;
private String colorCode;

public static CategoryViewDTO of(Category category){
return CategoryViewDTO.builder()
.name(category.getName())
.colorCode(category.getColorCode())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.trendithon.timetris.domain.mainpage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalTime;

@Getter
@AllArgsConstructor @NoArgsConstructor
public class DoRequestDTO {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public class DoViewDTO {
private String title;
private LocalTime startTime;
private LocalTime endTime;
private Category category;
private CategoryViewDTO category;

public static DoViewDTO of(Do does){
return DoViewDTO.builder()
.title(does.getTitle())
.startTime(does.getStartTime())
.endTime(does.getEndTime())
.category(does.getCategory())
.category(CategoryViewDTO.of(does.getCategory()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.trendithon.timetris.domain.mainpage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalTime;

@Getter
@AllArgsConstructor @NoArgsConstructor
public class PlanRequestDTO {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public class PlanViewDTO {
private LocalTime startTime;
private LocalTime endTime;
private boolean status;
private Category category;
private CategoryViewDTO category;

public static PlanViewDTO of(Plan plan){
return PlanViewDTO.builder()
.title(plan.getTitle())
.startTime(plan.getStartTime())
.endTime(plan.getEndTime())
.status(plan.isStatus())
.category(plan.getCategory())
.category(CategoryViewDTO.of(plan.getCategory()))
.build();
}

Expand Down
Loading

0 comments on commit 4af4efd

Please sign in to comment.