Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#99): housework category #100

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.heachi.housework.api.controller.housework.category;

import com.heachi.admin.common.response.JsonResult;
import com.heachi.housework.api.service.housework.category.HouseworkCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/housework/category")
public class HouseworkCategoryController {

private final HouseworkCategoryService houseworkCategoryService;

@GetMapping("/")
public JsonResult<?> selectCategory() {

return JsonResult.successOf(houseworkCategoryService.selectCategory());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.heachi.housework.api.service.housework.category;

import com.heachi.housework.api.service.housework.category.response.HouseworkCategoryResponse;
import com.heachi.mysql.define.housework.category.repository.HouseworkCategoryRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class HouseworkCategoryService {

private final HouseworkCategoryRepository houseworkCategoryRepository;

public List<HouseworkCategoryResponse> selectCategory() {

return houseworkCategoryRepository.findAll().stream()
.map(HouseworkCategoryResponse::of)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.heachi.housework.api.service.housework.category.response;

import com.heachi.mysql.define.housework.category.HouseworkCategory;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class HouseworkCategoryResponse {
private Long id; // 카테고리 아이디
private String name; // 카테고리 이름

@Builder
private HouseworkCategoryResponse(Long id, String name) {
this.id = id;
this.name = name;
}

public static HouseworkCategoryResponse of(HouseworkCategory houseworkCategory) {

return HouseworkCategoryResponse.builder()
.id(houseworkCategory.getId())
.name(houseworkCategory.getName())
.build();
}
}