-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from ghdcksgml1/dev
Merge dev Branch
- Loading branch information
Showing
16 changed files
with
705 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...main/java/com/heachi/housework/api/controller/housework/info/HouseworkInfoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.heachi.housework.api.controller.housework.info; | ||
|
||
import com.heachi.admin.common.exception.HeachiException; | ||
import com.heachi.admin.common.response.JsonResult; | ||
import com.heachi.housework.api.controller.housework.info.request.HouseworkInfoCreateRequest; | ||
import com.heachi.housework.api.service.auth.AuthExternalService; | ||
import com.heachi.housework.api.service.housework.info.HouseworkInfoService; | ||
import com.heachi.housework.api.service.housework.info.request.HouseworkInfoCreateServiceRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RequestMapping("/housework") | ||
@RestController | ||
public class HouseworkInfoController { | ||
private final HouseworkInfoService houseworkInfoService; | ||
private final AuthExternalService authExternalService; | ||
|
||
@PostMapping("/{groupId}") | ||
public JsonResult<?> createHouseworkInfo(@RequestHeader(name = "Authorization") String authorization, | ||
@PathVariable(name = "groupId") Long groupId, | ||
@RequestBody HouseworkInfoCreateRequest request | ||
) { | ||
// Auth 서버로 요청자 인증 요청 - 해당 그룹원인지 판별하고 상태가 ACCEPT인지 확인 | ||
try { | ||
authExternalService.userAuthenticateAndGroupMatch(authorization, groupId); | ||
houseworkInfoService.createHouseworkInfo(HouseworkInfoCreateServiceRequest.of(request)); | ||
|
||
return JsonResult.successOf("Housework Create Success."); | ||
} catch (HeachiException e) { | ||
|
||
return JsonResult.failOf(e.getMessage()); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...om/heachi/housework/api/controller/housework/info/request/HouseworkInfoCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.heachi.housework.api.controller.housework.info.request; | ||
|
||
import com.heachi.mysql.define.housework.info.constant.HouseworkPeriodType; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class HouseworkInfoCreateRequest { | ||
@NotEmpty | ||
private List<Long> groupMemberIdList; | ||
|
||
private Long houseworkCategoryId; | ||
|
||
@NotEmpty | ||
private String title; // 집안일 제목 | ||
private String detail; // 집안일 내용 | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
private HouseworkPeriodType type; // 집안일 주기 타입 (한번, 매일, 매주, 매달) | ||
|
||
private LocalDate dayDate; // 단건: 날짜 정보 | ||
|
||
@Pattern(regexp = "^[1-7]$", | ||
message = "요일 정보는 1~7 사이의 문자열이어야 합니다.") // (1~7) | ||
private String weekDate; | ||
|
||
@Pattern(regexp = "^(0*[1-9]|[12][0-9]|3[0-1])$", | ||
message = "일 정보는 1~31 사이의 문자열이어야 합니다.") // (1~31) | ||
private String monthDate; | ||
|
||
@NotNull | ||
private LocalTime endTime; | ||
} |
113 changes: 113 additions & 0 deletions
113
...i/src/main/java/com/heachi/housework/api/service/housework/info/HouseworkInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.heachi.housework.api.service.housework.info; | ||
|
||
import com.heachi.admin.common.exception.ExceptionMessage; | ||
import com.heachi.admin.common.exception.group.member.GroupMemberException; | ||
import com.heachi.admin.common.exception.housework.HouseworkException; | ||
import com.heachi.housework.api.service.housework.info.request.HouseworkInfoCreateServiceRequest; | ||
import com.heachi.mysql.define.group.member.GroupMember; | ||
import com.heachi.mysql.define.group.member.repository.GroupMemberRepository; | ||
import com.heachi.mysql.define.housework.category.HouseworkCategory; | ||
import com.heachi.mysql.define.housework.category.repository.HouseworkCategoryRepository; | ||
import com.heachi.mysql.define.housework.info.HouseworkInfo; | ||
import com.heachi.mysql.define.housework.info.constant.HouseworkPeriodType; | ||
import com.heachi.mysql.define.housework.info.repository.HouseworkInfoRepository; | ||
import com.heachi.mysql.define.housework.member.HouseworkMember; | ||
import com.heachi.mysql.define.housework.member.repository.HouseworkMemberRepository; | ||
import com.heachi.mysql.define.housework.todo.HouseworkTodo; | ||
import com.heachi.mysql.define.housework.todo.constant.HouseworkTodoStatus; | ||
import com.heachi.mysql.define.housework.todo.repository.HouseworkTodoRepository; | ||
import com.heachi.redis.define.housework.todo.TodoList; | ||
import com.heachi.redis.define.housework.todo.repository.TodoListRepository; | ||
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.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class HouseworkInfoService { | ||
private final HouseworkInfoRepository houseworkInfoRepository; | ||
private final HouseworkMemberRepository houseworkMemberRepository; | ||
private final GroupMemberRepository groupMemberRepository; | ||
private final HouseworkCategoryRepository houseworkCategoryRepository; | ||
private final HouseworkTodoRepository houseworkTodoRepository; | ||
|
||
private final TodoListRepository todoListRepository; | ||
|
||
@Transactional(readOnly = false) | ||
public void createHouseworkInfo(HouseworkInfoCreateServiceRequest request) { | ||
try { | ||
// HOUSEWORK_CATEGORY 조회 | ||
HouseworkCategory category = houseworkCategoryRepository.findById(request.getHouseworkCategoryId()).orElseThrow(() -> { | ||
log.warn(">>>> HouseworkCategory Not Found : {}", ExceptionMessage.HOUSEWORK_CATEGORY_NOT_FOUND.getText()); | ||
|
||
throw new HouseworkException(ExceptionMessage.HOUSEWORK_CATEGORY_NOT_FOUND); | ||
}); | ||
|
||
// 담당자 지정 - HOUSEWORK_MEMBER 생성 | ||
List<GroupMember> groupMemberList = groupMemberRepository.findGroupMemberListByGroupMemberIdList(request.getGroupMemberIdList()); | ||
|
||
// 한 건이라도 조회 실패시 예외 발생 | ||
if (groupMemberList.size() != request.getGroupMemberIdList().size()) { | ||
log.warn(">>>> GourpMember Not Found : {}", ExceptionMessage.GROUP_MEMBER_NOT_FOUND.getText()); | ||
|
||
throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_NOT_FOUND); | ||
} | ||
|
||
// 딱 한번 하는 집안일의 경우 HOUSEWORK_INFO를 생성해줄 필요 없이, 바로 HOUSEWORK_TODO로 생성 | ||
if (request.getType() == HouseworkPeriodType.HOUSEWORK_PERIOD_DAY) { | ||
|
||
// HouseworkTodo 생성 | ||
houseworkTodoRepository.save(HouseworkTodo.builder() | ||
.houseworkInfo(null) // 단건은 HouseworkInfo가 존재하지 않는다. | ||
.groupInfo(groupMemberList.isEmpty() ? null : groupMemberList.get(0).getGroupInfo()) | ||
.houseworkMember(groupMemberList.stream() | ||
.map(gm -> gm.getId().toString()) | ||
.collect(Collectors.joining(","))) | ||
.category(category.getName()) | ||
.title(request.getTitle()) | ||
.detail(request.getDetail()) | ||
.status(HouseworkTodoStatus.HOUSEWORK_TODO_INCOMPLETE) | ||
.date(request.getDayDate()) | ||
.endTime(request.getEndTime()) | ||
.build()); | ||
|
||
// TODO: 해당 HouseworkTodo에 맞는 groupInfoId와 Date가 캐싱되어있다면, dirtyBit를 true로 바꿔줘야함. | ||
|
||
return ; | ||
} | ||
|
||
// HOUSEWORK_INFO 저장 | ||
HouseworkInfo houseworkInfo = houseworkInfoRepository.save(HouseworkInfo.builder() | ||
.houseworkCategory(category) | ||
.title(request.getTitle()) | ||
.detail(request.getDetail()) | ||
.type(request.getType()) | ||
.dayDate(request.getDayDate()) | ||
.weekDate(request.getWeekDate()) | ||
.monthDate(request.getMonthDate()) | ||
.endTime(request.getEndTime()) | ||
.build()); | ||
log.info(">>>> HouseworkInfo Create: {}", houseworkInfo.getId()); | ||
|
||
groupMemberList.stream() | ||
.map(gm -> HouseworkMember.builder() | ||
.groupMember(gm) | ||
.houseworkInfo(houseworkInfo) | ||
.build()) | ||
// HOUSEWORK_MEMBER 저장 | ||
.forEach(houseworkMemberRepository::save); | ||
|
||
} catch (RuntimeException e) { | ||
log.warn(">>>> Housework Add Fail : {}", e.getMessage()); | ||
|
||
throw e; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...eachi/housework/api/service/housework/info/request/HouseworkInfoCreateServiceRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.heachi.housework.api.service.housework.info.request; | ||
|
||
import com.heachi.housework.api.controller.housework.info.request.HouseworkInfoCreateRequest; | ||
import com.heachi.mysql.define.housework.info.constant.HouseworkPeriodType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
public class HouseworkInfoCreateServiceRequest { | ||
private List<Long> groupMemberIdList; | ||
private Long houseworkCategoryId; | ||
private String title; | ||
private String detail; | ||
private HouseworkPeriodType type; | ||
private LocalDate dayDate; | ||
private String weekDate; | ||
private String monthDate; | ||
private LocalTime endTime; | ||
|
||
@Builder | ||
private HouseworkInfoCreateServiceRequest(List<Long> groupMemberIdList, Long houseworkCategoryId, String title, | ||
String detail, HouseworkPeriodType type, LocalDate dayDate, String weekDate, | ||
String monthDate, LocalTime endTime) { | ||
this.groupMemberIdList = groupMemberIdList == null ? new ArrayList<>() : groupMemberIdList; | ||
this.houseworkCategoryId = houseworkCategoryId; | ||
this.title = title; | ||
this.detail = detail; | ||
this.type = type; | ||
this.dayDate = dayDate; | ||
this.weekDate = weekDate; | ||
this.monthDate = monthDate; | ||
this.endTime = endTime; | ||
} | ||
|
||
public static HouseworkInfoCreateServiceRequest of(HouseworkInfoCreateRequest request) { | ||
|
||
return HouseworkInfoCreateServiceRequest.builder() | ||
.groupMemberIdList(request.getGroupMemberIdList()) | ||
.houseworkCategoryId(request.getHouseworkCategoryId()) | ||
.title(request.getTitle()) | ||
.detail(request.getDetail()) | ||
.type(request.getType()) | ||
.dayDate(request.getDayDate()) | ||
.weekDate(request.getWeekDate()) | ||
.monthDate(request.getMonthDate()) | ||
.endTime(request.getEndTime()) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...core/housework-api/src/test/java/com/heachi/housework/HeachiHouseworkApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.heachi.housework; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@ActiveProfiles("test") | ||
@SpringBootTest | ||
@ConfigurationPropertiesScan | ||
class HeachiHouseworkApplicationTest { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.