-
Notifications
You must be signed in to change notification settings - Fork 0
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 #19 from Domitory-CheckMate/feature/12-checkList
[feat] 체크리스트 관련 기능
- Loading branch information
Showing
9 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/org/gachon/checkmate/domain/checkList/controller/CheckListController.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,38 @@ | ||
package org.gachon.checkmate.domain.checkList.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto; | ||
import org.gachon.checkmate.domain.checkList.dto.response.CheckListResponseDto; | ||
import org.gachon.checkmate.domain.checkList.service.CheckListService; | ||
import org.gachon.checkmate.global.common.SuccessResponse; | ||
import org.gachon.checkmate.global.config.auth.UserId; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/api/checkList") | ||
@RestController | ||
public class CheckListController { | ||
private final CheckListService checkListService; | ||
|
||
@PostMapping("/new") | ||
public ResponseEntity<SuccessResponse<?>> createCheckList(@UserId final Long userId, | ||
@RequestBody final CheckListRequestDto checkListRequestDto) { | ||
checkListService.createCheckList(userId, checkListRequestDto); | ||
return SuccessResponse.created(null); | ||
} | ||
|
||
@PatchMapping("/my") | ||
public ResponseEntity<SuccessResponse<?>> updateCheckList(@UserId final Long userId, | ||
@RequestBody final CheckListRequestDto checkListRequestDto) { | ||
checkListService.updateCheckList(userId, checkListRequestDto); | ||
return SuccessResponse.ok(null); | ||
} | ||
|
||
@GetMapping("/my") | ||
public ResponseEntity<SuccessResponse<?>> getCheckList(@UserId final Long userId) { | ||
final CheckListResponseDto checkListResponseDto = checkListService.getCheckList(userId); | ||
return SuccessResponse.ok(checkListResponseDto); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/gachon/checkmate/domain/checkList/dto/request/CheckListRequestDto.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,14 @@ | ||
package org.gachon.checkmate.domain.checkList.dto.request; | ||
|
||
import org.gachon.checkmate.domain.checkList.entity.*; | ||
|
||
public record CheckListRequestDto( | ||
CleanType cleanType, | ||
DrinkType drinkType, | ||
HomeType homeType, | ||
LifePatterType lifePatterType, | ||
NoiseType noiseType, | ||
SleepType sleepType | ||
|
||
) { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/gachon/checkmate/domain/checkList/dto/response/CheckListResponseDto.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,29 @@ | ||
package org.gachon.checkmate.domain.checkList.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CheckListResponseDto( | ||
String cleanType, | ||
String drinkType, | ||
String homeType, | ||
String lifePatterType, | ||
String noiseType, | ||
String sleepType | ||
) { | ||
public static CheckListResponseDto of(String cleanType, | ||
String drinkType, | ||
String homeType, | ||
String lifePatterType, | ||
String noiseType, | ||
String sleepType) { | ||
return CheckListResponseDto.builder() | ||
.cleanType(cleanType) | ||
.drinkType(drinkType) | ||
.homeType(homeType) | ||
.lifePatterType(lifePatterType) | ||
.noiseType(noiseType) | ||
.sleepType(sleepType) | ||
.build(); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
src/main/java/org/gachon/checkmate/domain/checkList/repository/CheckListRepository.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package org.gachon.checkmate.domain.checkList.repository; | ||
|
||
import org.gachon.checkmate.domain.checkList.entity.CheckList; | ||
import org.gachon.checkmate.domain.member.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CheckListRepository extends JpaRepository<CheckList, Long> { | ||
Optional<CheckList> findByUserId(Long userId); | ||
|
||
boolean existsByUser(User user); | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/org/gachon/checkmate/domain/checkList/service/CheckListService.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,70 @@ | ||
package org.gachon.checkmate.domain.checkList.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.domain.checkList.dto.request.CheckListRequestDto; | ||
import org.gachon.checkmate.domain.checkList.dto.response.CheckListResponseDto; | ||
import org.gachon.checkmate.domain.checkList.entity.CheckList; | ||
import org.gachon.checkmate.domain.checkList.repository.CheckListRepository; | ||
import org.gachon.checkmate.domain.member.entity.User; | ||
import org.gachon.checkmate.domain.member.repository.UserRepository; | ||
import org.gachon.checkmate.global.error.exception.ConflictException; | ||
import org.gachon.checkmate.global.error.exception.EntityNotFoundException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static org.gachon.checkmate.global.error.ErrorCode.*; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class CheckListService { | ||
|
||
private final CheckListRepository checkListRepository; | ||
private final UserRepository userRepository; | ||
|
||
public void createCheckList(Long userId, CheckListRequestDto checkListRequestDto) { | ||
User user = findByIdOrThrow(userId); | ||
checkIfCheckListExists(user); | ||
CheckList checkList = CheckList.createCheckList(user, checkListRequestDto); | ||
checkListRepository.save(checkList); | ||
} | ||
|
||
public void updateCheckList(Long userId, CheckListRequestDto checkListRequestDto) { | ||
User user = findByIdOrThrow(userId); | ||
checkIfCheckListNotExists(user); | ||
CheckList checkList = user.getCheckList(); | ||
checkList.updateCheckList(checkListRequestDto); | ||
checkListRepository.save(checkList); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public CheckListResponseDto getCheckList(Long userId) { | ||
User user = findByIdOrThrow(userId); | ||
CheckList checkList = user.getCheckList(); | ||
return CheckListResponseDto.of(checkList.getCleanType().getDesc(), | ||
checkList.getDrinkType().getDesc(), | ||
checkList.getHomeType().getDesc(), | ||
checkList.getLifePatterType().getDesc(), | ||
checkList.getNoiseType().getDesc(), | ||
checkList.getSleepType().getDesc()); | ||
} | ||
|
||
private User findByIdOrThrow(Long userId) { | ||
return userRepository.findById(userId) | ||
.orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND)); | ||
} | ||
|
||
public void checkIfCheckListExists(User user) { | ||
if (checkListRepository.existsByUser(user)) { | ||
throw new ConflictException(DUPLICATE_CHECK_LIST); | ||
} | ||
} | ||
|
||
public void checkIfCheckListNotExists(User user) { | ||
if (!checkListRepository.existsByUser(user)) { | ||
throw new EntityNotFoundException(CHECK_LIST_NOT_FOUND); | ||
} | ||
} | ||
|
||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/org/gachon/checkmate/global/config/WebConfig.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,21 @@ | ||
package org.gachon.checkmate.global.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.global.config.auth.UserIdArgumentResolver; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
private final UserIdArgumentResolver userIdArgumentResolver; | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers){ | ||
resolvers.add(userIdArgumentResolver); | ||
} | ||
} |
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