From 229315085d43bdc6ba84b9ed40d8cdbb7d7942f3 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 28 Dec 2023 20:27:26 +0900 Subject: [PATCH 01/20] =?UTF-8?q?fix:=20=EB=8B=A8=ED=98=BC=EB=B0=A5=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20EatingAlone=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/entity/type/{EatingAlong.java => EatingAlone.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/java/com/dku/council/domain/with_dankook/model/entity/type/{EatingAlong.java => EatingAlone.java} (87%) diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/EatingAlong.java b/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/EatingAlone.java similarity index 87% rename from src/main/java/com/dku/council/domain/with_dankook/model/entity/type/EatingAlong.java rename to src/main/java/com/dku/council/domain/with_dankook/model/entity/type/EatingAlone.java index fc3ac472..49bc66fa 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/EatingAlong.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/EatingAlone.java @@ -12,7 +12,7 @@ @Entity @Getter @NoArgsConstructor(access = PROTECTED) -public class EatingAlong extends WithDankook { +public class EatingAlone extends WithDankook { @Id @GeneratedValue @@ -27,7 +27,7 @@ public class EatingAlong extends WithDankook { private String content; @Builder - private EatingAlong(User user, String title, String content) { + private EatingAlone(User user, String title, String content) { super(user); this.title = title; this.content = content; From 43cbfbd6e7f0d3359e09d00ad71ed661570a0bd4 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 28 Dec 2023 20:27:46 +0900 Subject: [PATCH 02/20] =?UTF-8?q?feat:=20=EB=8B=A8=ED=98=BC=EB=B0=A5=20?= =?UTF-8?q?=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/EatingAloneRepository.java | 13 +++++++++++++ .../repository/WithDankookRepository.java | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java new file mode 100644 index 00000000..04c28740 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java @@ -0,0 +1,13 @@ +package com.dku.council.domain.with_dankook.repository; + +import com.dku.council.domain.with_dankook.model.entity.type.EatingAlone; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface EatingAloneRepository extends WithDankookRepository { + @Query("select e from EatingAlone e where e.masterUser.id = :userId and " + + "(e.withDankookStatus='ACTIVE' or e.withDankookStatus='CLOSED') ") + Page findAllEatingAloneByUserId(@Param("userId") Long userId, Pageable pageable); +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java index 6b851a62..e0655b6d 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import javax.validation.constraints.NotNull; import java.util.Optional; public interface WithDankookRepository extends JpaRepository, JpaSpecificationExecutor { @@ -33,4 +34,11 @@ public interface WithDankookRepository extends JpaReposit @Query("select w from WithDankook w " + "where w.withDankookStatus='ACTIVE' order by w.createdAt desc") Page findTop5OrderByCreatedAtDesc(Pageable pageable); + + @Query("select w from WithDankook w " + + "where w.withDankookStatus='ACTIVE' or w.withDankookStatus='FULL' order by w.createdAt desc") + Page findAllWithActive(Pageable pageable); + + @Override + Page findAll(Pageable pageable); } From 9ba87a1044282c77741c42c8823f6381a2a073c2 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 28 Dec 2023 20:28:19 +0900 Subject: [PATCH 03/20] =?UTF-8?q?feat:=20=EB=8B=A8=ED=98=BC=EB=B0=A5=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=9E=91=EC=84=B1=20Dto=20?= =?UTF-8?q?=EB=B0=8F=20final=20=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/RequestCreateBearEatsDto.java | 8 ++--- .../request/RequestCreateEatingAloneDto.java | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateEatingAloneDto.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateBearEatsDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateBearEatsDto.java index 85190eaa..6bc3fd97 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateBearEatsDto.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateBearEatsDto.java @@ -15,20 +15,20 @@ public class RequestCreateBearEatsDto extends RequestCreateWithDankookDto { + + @NotBlank + @Schema(description = "제목", example = "제목") + private final String title; + + @NotBlank + @Schema(description = "본문", example = "내용") + private final String content; + + public RequestCreateEatingAloneDto(@NotBlank String title, + @NotBlank String content) { + this.title = title; + this.content = content; + } + + @Override + public EatingAlone toEntity(User user) { + return EatingAlone.builder() + .user(user) + .title(title) + .content(content) + .build(); + } +} From fb31d29a7072b07ecbc37f45c72c0acfec6754c9 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 28 Dec 2023 20:28:32 +0900 Subject: [PATCH 04/20] =?UTF-8?q?feat:=20=EB=8B=A8=ED=98=BC=EB=B0=A5=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EB=8B=A8=EC=9D=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20Dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseSingleEatingAloneDto.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleEatingAloneDto.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleEatingAloneDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleEatingAloneDto.java new file mode 100644 index 00000000..dd3ec0fc --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleEatingAloneDto.java @@ -0,0 +1,35 @@ +package com.dku.council.domain.with_dankook.model.dto.response; + +import com.dku.council.domain.with_dankook.model.dto.RecruitedUsersDto; +import com.dku.council.domain.with_dankook.model.entity.type.EatingAlone; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +public class ResponseSingleEatingAloneDto extends ResponseSingleWithDankookDto { + + @Schema(description = "제목", example = "피자헛에서 피자를 시켜먹을 사람을 구합니다.") + private final String title; + + @Schema(description = "내용", example = "학교 앞에서 먹을겁니다.") + private final String content; + + @Schema(description = "모집된 인원", example = "1") + private final int recruitedCount; + + @Schema(description = "모집된 사용자들") + private final List recruitedUsers; + + public ResponseSingleEatingAloneDto(ResponseSingleWithDankookDto dto, EatingAlone eatingAlone, int recruitedCount) { + super(dto); + this.title = eatingAlone.getTitle(); + this.content = eatingAlone.getContent(); + this.recruitedCount = recruitedCount; + this.recruitedUsers = eatingAlone.getUsers().stream() + .map(RecruitedUsersDto::new) + .collect(Collectors.toList()); + } +} From 88363881e65a4e2c68d0dd6a031f04e7fb9b96f6 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 28 Dec 2023 20:28:43 +0900 Subject: [PATCH 05/20] =?UTF-8?q?feat:=20=EB=8B=A8=ED=98=BC=EB=B0=A5=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20Dto=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/list/SummarizedEatingAloneDto.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedEatingAloneDto.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedEatingAloneDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedEatingAloneDto.java new file mode 100644 index 00000000..056a18be --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedEatingAloneDto.java @@ -0,0 +1,25 @@ +package com.dku.council.domain.with_dankook.model.dto.list; + +import com.dku.council.domain.with_dankook.model.entity.type.EatingAlone; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; + +@Getter +public class SummarizedEatingAloneDto extends SummarizedWithDankookDto { + + @Schema(description = "제목", example = "저녁 같이 먹을 사람 구해요") + private final String title; + + @Schema(description = "내용", example = "저녁 같이 먹을 사람 구해요") + private final String content; + + @Schema(description = "모집된 인원", example = "1") + private final int recruitedCount; + + public SummarizedEatingAloneDto(SummarizedWithDankookDto dto, EatingAlone eatingAlone, int recruitedCount) { + super(dto); + this.title = eatingAlone.getTitle(); + this.content = eatingAlone.getContent(); + this.recruitedCount = recruitedCount; + } +} From 2a48112c2c0b22b2829d8e2f459baa5bab1aa139 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 28 Dec 2023 20:28:59 +0900 Subject: [PATCH 06/20] =?UTF-8?q?feat:=20=EB=8B=A8=ED=98=BC=EB=B0=A5=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=B0=8F=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EatingAloneController.java | 102 +++++++++++++++++ .../service/EatingAloneService.java | 108 ++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/controller/EatingAloneController.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/controller/EatingAloneController.java b/src/main/java/com/dku/council/domain/with_dankook/controller/EatingAloneController.java new file mode 100644 index 00000000..ed9446b7 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/controller/EatingAloneController.java @@ -0,0 +1,102 @@ +package com.dku.council.domain.with_dankook.controller; + +import com.dku.council.domain.post.model.dto.response.ResponsePage; +import com.dku.council.domain.with_dankook.model.dto.list.SummarizedEatingAloneDto; +import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateEatingAloneDto; +import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleEatingAloneDto; +import com.dku.council.domain.with_dankook.service.EatingAloneService; +import com.dku.council.global.auth.jwt.AppAuthentication; +import com.dku.council.global.auth.role.UserAuth; +import com.dku.council.global.model.dto.ResponseIdDto; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springdoc.api.annotations.ParameterObject; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +@RestController +@Tag(name = "단혼밥", description = "단혼밥 게시판") +@RequestMapping("with-dankook/eating-alone") +@RequiredArgsConstructor +public class EatingAloneController { + + private final EatingAloneService eatingAloneService; + + /** + * 단혼밥 게시글 목록 조회 + * + * @param bodySize 게시글 본문 길이. (글자 단위) 지정하지 않으면 50 글자. + * @param pageable 페이징 size, sort, page + * @return 페이징된 EatingAlone 게시판 목록 + */ + @GetMapping + public ResponsePage list(@RequestParam(defaultValue = "50") int bodySize, + @ParameterObject Pageable pageable) { + Page list = eatingAloneService.list(pageable, bodySize); + return new ResponsePage<>(list); + } + + /** + * 내가 쓴 단혼밥 게시글 목록 조회 + * + * @param pageable 페이징 size, sort, page + * @return 페이징된 내가 쓴 EatingAlone 게시판 목록 + */ + @GetMapping("/my") + @UserAuth + public ResponsePage listMyPosts(AppAuthentication auth, + @ParameterObject Pageable pageable) { + Page list = eatingAloneService.listMyPosts(auth.getUserId(), pageable); + return new ResponsePage<>(list); + } + + /** + * 단혼밥 게시글 상세 조회 + * + * @param id 게시글 id + */ + @GetMapping("/{id}") + @UserAuth + public ResponseSingleEatingAloneDto findOne(AppAuthentication auth, + @PathVariable Long id) { + return eatingAloneService.findOne(id, auth.getUserId(), auth.getUserRole()); + } + + /** + * 단혼밥 게시글 생성 + */ + @PostMapping + @UserAuth + public ResponseIdDto create(AppAuthentication auth, + @Valid @RequestBody RequestCreateEatingAloneDto dto) { + Long id = eatingAloneService.create(auth.getUserId(), dto); + return new ResponseIdDto(id); + } + + /** + * 단혼밥 게시글 참여 + * + * @param id 게시글 id + */ + @PostMapping("/{id}/enter") + @UserAuth + public void enter(AppAuthentication auth, + @PathVariable @Valid Long id) { + eatingAloneService.enter(id, auth.getUserId(), auth.getUserRole()); + } + + /** + * 단혼밥 게시글 삭제 + * + * @param id 게시글 id + */ + @DeleteMapping("/{id}") + @UserAuth + public void delete(AppAuthentication auth, + @PathVariable @Valid Long id) { + eatingAloneService.delete(id, auth.getUserId(), auth.getUserRole().isAdmin()); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java b/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java new file mode 100644 index 00000000..8c02eb11 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java @@ -0,0 +1,108 @@ +package com.dku.council.domain.with_dankook.service; + +import com.dku.council.domain.post.exception.PostCooltimeException; +import com.dku.council.domain.post.repository.PostTimeMemoryRepository; +import com.dku.council.domain.user.model.entity.User; +import com.dku.council.domain.user.repository.UserRepository; +import com.dku.council.domain.with_dankook.exception.WithDankookNotFoundException; +import com.dku.council.domain.with_dankook.model.dto.list.SummarizedEatingAloneDto; +import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateEatingAloneDto; +import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleEatingAloneDto; +import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; +import com.dku.council.domain.with_dankook.model.entity.type.EatingAlone; +import com.dku.council.domain.with_dankook.repository.EatingAloneRepository; +import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; +import com.dku.council.global.auth.role.UserRole; +import com.dku.council.global.error.exception.UserNotFoundException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.Clock; +import java.time.Duration; +import java.time.Instant; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Slf4j +@Transactional(readOnly = true) +public class EatingAloneService { + + public static final String EATING_ALONG_KEY = "eatingAlong"; + + private final WithDankookService withDankookService; + private final WithDankookUserService withDankookUserService; + + private final EatingAloneRepository eatingAloneRepository; + private final WithDankookUserRepository withDankookUserRepository; + private final PostTimeMemoryRepository postTimeMemoryRepository; + private final UserRepository userRepository; + + private final Clock clock; + + @Value("${app.with-dankook.eating-alone.write-cooltime}") + private final Duration writeCooltime; + + @Transactional + public Long create(Long userId, RequestCreateEatingAloneDto dto) { + User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + Instant now = Instant.now(clock); + if (postTimeMemoryRepository.isAlreadyContains(EATING_ALONG_KEY, userId, now)) { + throw new PostCooltimeException("eating-alone"); + } + + Long result = withDankookService.create(eatingAloneRepository, userId, dto); + + WithDankookUser withDankookUser = WithDankookUser.builder() + .user(user) + .withDankook(eatingAloneRepository.findById(result).orElseThrow(WithDankookNotFoundException::new)) + .build(); + withDankookUserRepository.save(withDankookUser); + + postTimeMemoryRepository.put(EATING_ALONG_KEY, userId, writeCooltime, now); + return result; + } + + public Page list(Pageable pageable, int bodySize) { + Page result = eatingAloneRepository.findAll(pageable); + return result.map(eatingAlone -> new SummarizedEatingAloneDto(withDankookService.makeListDto(bodySize, eatingAlone), eatingAlone, + withDankookUserService.recruitedCount(withDankookService.makeListDto(bodySize, eatingAlone).getId()))); + } + + public Page listMyPosts(Long userId, Pageable pageable) { + return eatingAloneRepository.findAllEatingAloneByUserId(userId, pageable) + .map(eatingAlone -> new SummarizedEatingAloneDto(withDankookService.makeListDto(50, eatingAlone), eatingAlone, + withDankookUserService.recruitedCount(withDankookService.makeListDto(50, eatingAlone).getId()))); + } + + public ResponseSingleEatingAloneDto findOne(Long id, Long userId, UserRole role) { + EatingAlone eatingAlone = findEatingAlone(eatingAloneRepository, id, role); + return new ResponseSingleEatingAloneDto(withDankookService.makeSingleDto(userId, eatingAlone), eatingAlone, + withDankookUserService.recruitedCount(withDankookService.makeSingleDto(userId, eatingAlone).getId())); + } + + private EatingAlone findEatingAlone(EatingAloneRepository eatingAloneRepository, Long id, UserRole role) { + Optional eatingAlone; + if (role == UserRole.ADMIN) { + eatingAlone = eatingAloneRepository.findWithClosedById(id); + } else { + eatingAlone = eatingAloneRepository.findById(id); + } + return eatingAlone.orElseThrow(WithDankookNotFoundException::new); + } + + @Transactional + public void enter(Long id, Long userId, UserRole role) { + withDankookService.enter(eatingAloneRepository, id, userId, role); + } + + @Transactional + public void delete(Long id, Long userId, boolean isAdmin) { + withDankookService.delete(eatingAloneRepository, id, userId, isAdmin); + } +} From 81b581e222cdf515ffe8628575f154177cebd7b5 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:34:55 +0900 Subject: [PATCH 07/20] =?UTF-8?q?fix:=20=EC=8B=9C=EA=B0=84=ED=91=9C=20?= =?UTF-8?q?=EA=B5=90=EC=96=91=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20null?= =?UTF-8?q?=EC=97=90=EC=84=9C=200=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/dto/response/LectureTemplateDto.java | 2 +- .../timetable/controller/TimeTableControllerTest.java | 2 +- .../domain/with_dankook/service/TradeServiceTest.java | 10 ++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/dku/council/domain/timetable/model/dto/response/LectureTemplateDto.java b/src/main/java/com/dku/council/domain/timetable/model/dto/response/LectureTemplateDto.java index 08d86cee..7543c553 100644 --- a/src/main/java/com/dku/council/domain/timetable/model/dto/response/LectureTemplateDto.java +++ b/src/main/java/com/dku/council/domain/timetable/model/dto/response/LectureTemplateDto.java @@ -55,7 +55,7 @@ public LectureTemplateDto(ObjectMapper mapper, LectureTemplate template) { this.grade = template.getGrade(); } else { this.major = null; - this.grade = null; + this.grade = 0; } } } diff --git a/src/test/java/com/dku/council/domain/timetable/controller/TimeTableControllerTest.java b/src/test/java/com/dku/council/domain/timetable/controller/TimeTableControllerTest.java index 6c9ac0db..3f109e90 100644 --- a/src/test/java/com/dku/council/domain/timetable/controller/TimeTableControllerTest.java +++ b/src/test/java/com/dku/council/domain/timetable/controller/TimeTableControllerTest.java @@ -94,7 +94,7 @@ void listLectures() throws Exception { .andExpect(jsonPath("$.content[0].classNumber").value(1)) .andExpect(jsonPath("$.content[0].credit").value(3)) .andExpect(jsonPath("$.content[0].major").isEmpty()) - .andExpect(jsonPath("$.content[0].grade").isEmpty()) + .andExpect(jsonPath("$.content[0].grade").value(0)) .andExpect(jsonPath("$.content[0].times[0].start").value("00:00:00")) .andExpect(jsonPath("$.content[0].times[0].end").value("06:00:00")) .andExpect(jsonPath("$.content[0].times[0].week").value(DayOfWeek.TUESDAY.name())) diff --git a/src/test/java/com/dku/council/domain/with_dankook/service/TradeServiceTest.java b/src/test/java/com/dku/council/domain/with_dankook/service/TradeServiceTest.java index 5172387f..b98b0860 100644 --- a/src/test/java/com/dku/council/domain/with_dankook/service/TradeServiceTest.java +++ b/src/test/java/com/dku/council/domain/with_dankook/service/TradeServiceTest.java @@ -1,18 +1,14 @@ package com.dku.council.domain.with_dankook.service; import com.dku.council.domain.like.service.LikeService; -import com.dku.council.domain.post.repository.PostTimeMemoryRepository; import com.dku.council.domain.post.service.ThumbnailService; import com.dku.council.domain.user.repository.UserRepository; import com.dku.council.domain.with_dankook.model.entity.type.Trade; -import com.dku.council.domain.with_dankook.repository.TradeRepository; -import com.dku.council.domain.with_dankook.repository.WithDankookMemoryRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.TradeRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookMemoryRepository; import com.dku.council.infra.nhn.s3.service.ImageUploadService; import com.dku.council.infra.nhn.s3.service.ObjectUploadContext; import com.dku.council.util.ClockUtil; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -20,8 +16,6 @@ import java.time.Clock; import java.time.Duration; -import static org.junit.jupiter.api.Assertions.*; - @ExtendWith(MockitoExtension.class) class TradeServiceTest { From 4b8448e5045f2cd0380e2d637e78d48fec6c6eb7 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:35:38 +0900 Subject: [PATCH 08/20] =?UTF-8?q?fix:=20=EB=82=B4=EA=B0=80=20=EC=93=B4=20?= =?UTF-8?q?=EC=B2=AD=EC=9B=90=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EB=B0=8F=20?= =?UTF-8?q?=EB=8F=99=EC=9D=98=ED=95=9C=20=EC=B2=AD=EC=9B=90=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=20/user=20=EA=B2=BD=EB=A1=9C=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PetitionController.java | 26 ----------------- .../user/controller/UserController.java | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/dku/council/domain/post/controller/PetitionController.java b/src/main/java/com/dku/council/domain/post/controller/PetitionController.java index 2046115f..63ffb111 100644 --- a/src/main/java/com/dku/council/domain/post/controller/PetitionController.java +++ b/src/main/java/com/dku/council/domain/post/controller/PetitionController.java @@ -57,32 +57,6 @@ public ResponsePage list(@RequestParam(required = false) return new ResponsePage<>(list); } - /** - * 내가 쓴 글 조회 - */ - @GetMapping("/my") - @UserAuth - public ResponsePage listMyPosts(AppAuthentication auth, - @ParameterObject Pageable pageable, - @RequestParam(defaultValue = "50") int bodySize) { - Page posts = - petitionService.listMyPosts(auth.getUserId(), pageable, bodySize); - return new ResponsePage<>(posts); - } - - /** - * 내가 동의한 글 조회 - */ - @GetMapping("/my/agreed") - @UserAuth - public ResponsePage listMyAgreedPosts(AppAuthentication auth, - @ParameterObject Pageable pageable, - @RequestParam(defaultValue = "50") int bodySize) { - Page posts = - petitionService.listMyAgreedPosts(auth.getUserId(), pageable, bodySize); - return new ResponsePage<>(posts); - } - /** * 게시글 등록 * diff --git a/src/main/java/com/dku/council/domain/user/controller/UserController.java b/src/main/java/com/dku/council/domain/user/controller/UserController.java index ad26f397..621a4df7 100644 --- a/src/main/java/com/dku/council/domain/user/controller/UserController.java +++ b/src/main/java/com/dku/council/domain/user/controller/UserController.java @@ -1,7 +1,9 @@ package com.dku.council.domain.user.controller; import com.dku.council.domain.post.model.dto.list.SummarizedGenericPostDto; +import com.dku.council.domain.post.model.dto.list.SummarizedPetitionDto; import com.dku.council.domain.post.model.dto.response.ResponsePage; +import com.dku.council.domain.post.service.post.PetitionService; import com.dku.council.domain.user.model.dto.request.*; import com.dku.council.domain.user.model.dto.response.*; import com.dku.council.domain.user.service.*; @@ -29,6 +31,7 @@ public class UserController { private final UserFindService userFindService; private final SignupService signupService; private final MyPostService myPostService; + private final PetitionService petitionService; private final UserWithdrawService userWithdrawService; /** @@ -206,6 +209,32 @@ public ResponsePage listMyCommentedPosts(AppAuthentica return new ResponsePage<>(commentedPosts); } + /** + * 내가 쓴 청원 글 조회 + */ + @GetMapping("/petition") + @UserAuth + public ResponsePage listMyPosts(AppAuthentication auth, + @ParameterObject Pageable pageable, + @RequestParam(defaultValue = "50") int bodySize) { + Page posts = + petitionService.listMyPosts(auth.getUserId(), pageable, bodySize); + return new ResponsePage<>(posts); + } + + /** + * 내가 동의한 청원 글 조회 + */ + @GetMapping("/petition/agreed") + @UserAuth + public ResponsePage listMyAgreedPosts(AppAuthentication auth, + @ParameterObject Pageable pageable, + @RequestParam(defaultValue = "50") int bodySize) { + Page posts = + petitionService.listMyAgreedPosts(auth.getUserId(), pageable, bodySize); + return new ResponsePage<>(posts); + } + /** * 내가 좋아요 한 글들 모두 조회하기 */ From ae67d7c5a242f82ee99f514255eb6c9406ee0fdb Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:35:53 +0900 Subject: [PATCH 09/20] =?UTF-8?q?feat:=20Boolean=20=EB=A6=AC=ED=84=B4=20dt?= =?UTF-8?q?o=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../council/global/model/dto/ResponseBooleanDto.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/dku/council/global/model/dto/ResponseBooleanDto.java diff --git a/src/main/java/com/dku/council/global/model/dto/ResponseBooleanDto.java b/src/main/java/com/dku/council/global/model/dto/ResponseBooleanDto.java new file mode 100644 index 00000000..f0f0ddde --- /dev/null +++ b/src/main/java/com/dku/council/global/model/dto/ResponseBooleanDto.java @@ -0,0 +1,11 @@ +package com.dku.council.global.model.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class ResponseBooleanDto { + + private final boolean result; +} From 46b00480edd1a841ebeaf721cffa7e608ae32acd Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:38:13 +0900 Subject: [PATCH 10/20] =?UTF-8?q?feat:=20=EA=B5=AC=ED=95=B4=EC=A4=98!=20?= =?UTF-8?q?=EB=A3=B8=EB=A9=94=20=EA=B4=80=EB=A0=A8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이미 설문조사를 한 경우 - 이미 구해줘 룸메 게시글을 작성한 경우 - MBTI 형식에 맞지 않을 경우 - 소음을 유발하는 습관이 true인데 detail을 작성하지 않은 경우 - 설문조사 데이터를 찾지 못한 경우 --- .../exception/AlreadySurveyException.java | 11 +++++++++++ .../exception/AlreadyWrittenRoommateException.java | 11 +++++++++++ .../with_dankook/exception/InvalidMBTIException.java | 11 +++++++++++ .../exception/InvalidNoiseHabitException.java | 11 +++++++++++ .../exception/RoommateSurveyNotFoundException.java | 11 +++++++++++ src/main/resources/errors.properties | 7 ++++++- src/main/resources/errors_en_US.properties | 5 +++++ 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/exception/AlreadySurveyException.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/exception/AlreadyWrittenRoommateException.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/exception/InvalidMBTIException.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/exception/InvalidNoiseHabitException.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/exception/RoommateSurveyNotFoundException.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/exception/AlreadySurveyException.java b/src/main/java/com/dku/council/domain/with_dankook/exception/AlreadySurveyException.java new file mode 100644 index 00000000..071c3816 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/exception/AlreadySurveyException.java @@ -0,0 +1,11 @@ +package com.dku.council.domain.with_dankook.exception; + +import com.dku.council.global.error.exception.LocalizedMessageException; +import org.springframework.http.HttpStatus; + +public class AlreadySurveyException extends LocalizedMessageException { + + public AlreadySurveyException() { + super(HttpStatus.BAD_REQUEST, "already.survey"); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/exception/AlreadyWrittenRoommateException.java b/src/main/java/com/dku/council/domain/with_dankook/exception/AlreadyWrittenRoommateException.java new file mode 100644 index 00000000..8dfe8bb5 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/exception/AlreadyWrittenRoommateException.java @@ -0,0 +1,11 @@ +package com.dku.council.domain.with_dankook.exception; + +import com.dku.council.global.error.exception.LocalizedMessageException; +import org.springframework.http.HttpStatus; + +public class AlreadyWrittenRoommateException extends LocalizedMessageException { + + public AlreadyWrittenRoommateException() { + super(HttpStatus.BAD_REQUEST, "already.written.roommate"); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/exception/InvalidMBTIException.java b/src/main/java/com/dku/council/domain/with_dankook/exception/InvalidMBTIException.java new file mode 100644 index 00000000..0a9e539b --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/exception/InvalidMBTIException.java @@ -0,0 +1,11 @@ +package com.dku.council.domain.with_dankook.exception; + +import com.dku.council.global.error.exception.LocalizedMessageException; +import org.springframework.http.HttpStatus; + +public class InvalidMBTIException extends LocalizedMessageException { + + public InvalidMBTIException() { + super(HttpStatus.BAD_REQUEST, "invalid.mbti"); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/exception/InvalidNoiseHabitException.java b/src/main/java/com/dku/council/domain/with_dankook/exception/InvalidNoiseHabitException.java new file mode 100644 index 00000000..802bc69b --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/exception/InvalidNoiseHabitException.java @@ -0,0 +1,11 @@ +package com.dku.council.domain.with_dankook.exception; + +import com.dku.council.global.error.exception.LocalizedMessageException; +import org.springframework.http.HttpStatus; + +public class InvalidNoiseHabitException extends LocalizedMessageException { + + public InvalidNoiseHabitException() { + super(HttpStatus.BAD_REQUEST, "required.noise-habit"); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/exception/RoommateSurveyNotFoundException.java b/src/main/java/com/dku/council/domain/with_dankook/exception/RoommateSurveyNotFoundException.java new file mode 100644 index 00000000..df47c879 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/exception/RoommateSurveyNotFoundException.java @@ -0,0 +1,11 @@ +package com.dku.council.domain.with_dankook.exception; + +import com.dku.council.global.error.exception.LocalizedMessageException; +import org.springframework.http.HttpStatus; + +public class RoommateSurveyNotFoundException extends LocalizedMessageException { + + public RoommateSurveyNotFoundException() { + super(HttpStatus.NOT_FOUND, "notfound.roommate-survey"); + } +} diff --git a/src/main/resources/errors.properties b/src/main/resources/errors.properties index 3fbe7885..c3d838c5 100644 --- a/src/main/resources/errors.properties +++ b/src/main/resources/errors.properties @@ -5,6 +5,7 @@ required.sms-authorization=\uD734\uB300\uD3F0 \uBC88\uD638 \uC778\uC99D\uC774 \u required.sms-sending=\uC778\uC99D \uBB38\uC790\uAC00 \uC804\uC1A1\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4. \uBB38\uC790\uBC1B\uC73C\uC2DC\uACE0 \uCF54\uB4DC\uB97C \uC785\uB825\uD558\uC138\uC694. required.parameter=\uBC18\uB4DC\uC2DC \uC785\uB825\uD574\uC57C\uD558\uB294 Query Parameter\uC785\uB2C8\uB2E4. required.coalition-type=\uBC18\uB4DC\uC2DC \uC81C\uD734\uC0AC\uC5C5 \uD0C0\uC785\uC744 \uC120\uD0DD\uD574\uC57C\uD569\uB2C8\uB2E4. +required.noise-habit=\uBC18\uB4DC\uC2DC \uC18C\uC74C\uC2B5\uAD00\uC744 \uC791\uC131\uD574\uC57C \uD569\uB2C8\uB2E4. failed.send-sms=SMS\uB97C \uC804\uC1A1\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4. failed.send-mms=MMS\uB97C \uC804\uC1A1\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4. @@ -49,6 +50,7 @@ invalid.imagesize=\uC774\uBBF8\uC9C0 \uAC1C\uC218\uAC00 \uCD08\uACFC\uD588\uC2B5 invalid.student-id=\uCD5C\uC18C \uD559\uBC88\uC5D0 \uD574\uB2F9\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. invalid.status=\uCC38\uC5EC\uAC00 \uBD88\uAC00\uB2A5\uD569\uB2C8\uB2E4. invalid.create-review-to-myself=\uC790\uC2E0\uC5D0\uAC8C\uB294 \uB9AC\uBDF0 \uC791\uC131\uC744 \uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +invalid.mbti=MBTI\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. notfound.user=\uC720\uC800\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. notfound.post=\uD574\uB2F9 \uAC8C\uC2DC\uAE00\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. @@ -67,7 +69,8 @@ notfound.homebus=\uD574\uB2F9 \uADC0\uD5A5\uBC84\uC2A4\uB97C \uCC3E\uC744 \uC218 notfound.homebus-ticket=\uD574\uB2F9 \uBC84\uC2A4 \uD2F0\uCF13\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. notfound.withdankook=\uD574\uB2F9 WithDankook \uAC8C\uC2DC\uAE00\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. notfound.withdankook-user=\uD574\uB2F9 WithDankook \uAC8C\uC2DC\uAE00\uC5D0 \uCC38\uC5EC\uD55C \uC720\uC800\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. -notfound.review=\uC791\uC131\uB41C \uB9AC\uBDF0\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +notfound.review=\uC791\uC131\uB41C \uB9AC\uBDF0\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +notfound.roommate-survey=\uB8F8\uBA54\uC774\uD2B8 \uC124\uBB38\uC870\uC0AC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. notsupport.http-method=\uC798\uBABB\uB41C Method \uC694\uCCAD\uC785\uB2C8\uB2E4. @@ -85,6 +88,8 @@ already.homebus-cancel=\uC774\uBBF8 \uCDE8\uC18C\uB97C \uC694\uCCAD\uD588\uC2B5\ already.full-recruited=\uC774\uBBF8 \uC2E0\uCCAD\uC790\uAC00 \uB2E4 \uCC2C \uC0C1\uD0DC\uC785\uB2C8\uB2E4. already.entered=\uC774\uBBF8 \uC2E0\uCCAD\uB41C \uC0C1\uD0DC\uC785\uB2C8\uB2E4. already.written-review=\uC774\uBBF8 \uB9AC\uBDF0\uB97C \uC791\uC131\uD55C \uC0C1\uD0DC\uC785\uB2C8\uB2E4. +already.survey=\uC774\uBBF8 \uB8F8\uBA54\uC774\uD2B8 \uC124\uBB38\uC870\uC0AC\uC5D0 \uCC38\uC5EC\uD588\uC2B5\uB2C8\uB2E4. +already.written.roommate=\uC774\uBBF8 \uB8F8\uBA54\uC774\uD2B8 \uAC8C\uC2DC\uAE00\uC744 \uC791\uC131\uD588\uC2B5\uB2C8\uB2E4. cooltime.petition=\uCCAD\uC6D0\uC744 \uC62C\uB9B0 \uB4A4\uB85C 1\uC77C\uC774 \uC9C0\uB098\uC57C \uB2E4\uC2DC \uAC8C\uC2DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4. cooltime.general-forum=\uAC8C\uC2DC\uAE00\uC744 \uC62C\uB9B0 \uB4A4\uB85C 3\uBD84\uC774 \uC9C0\uB098\uC57C \uB2E4\uC2DC \uAC8C\uC2DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4. diff --git a/src/main/resources/errors_en_US.properties b/src/main/resources/errors_en_US.properties index 5e37e0e4..ff47185d 100644 --- a/src/main/resources/errors_en_US.properties +++ b/src/main/resources/errors_en_US.properties @@ -5,6 +5,7 @@ required.sms-authorization=SMS authentication is required. required.sms-sending=The code is not sent. Please press send a code and enter the code. required.parameter=Query parameter is required. required.coalition-type=Coalition type is required. +required.noise-habit=Noise habit is required. failed.send-sms=Failed to send SMS. failed.send-mms=Failed to send MMS. @@ -49,6 +50,7 @@ invalid.imagesize=The number of images has exceeded the limit. invalid.student-id=It does not correspond to the minimum number of students. invalid.status=You can't enter because of your status. invalid.create-review-to-myself=You can't write a review to yourself. +invalid.mbti=Invalid MBTI. notfound.user=Cannot find that user. notfound.post=No such post was found. @@ -68,6 +70,7 @@ notfound.homebus-ticket=No such homecoming bus ticket was found. notfound.withdankook=No such withDankook post was found. notfound.withdankook-user=No such user participated in the WithDankook post. notfound.review=No such written review could be found. +notfound.roommate-survey=No such roommate survey was found. notsupport.http-method=Not supported HTTP method. @@ -85,6 +88,8 @@ already.homebus-cancel=You have already requested canceling a homebus ticket. already.full-recruited=The recruitment is already full. already.entered=You have already entered. already.written-review=You have already written the review. +already.survey=You have already participated in the roommate survey. +already.written.roommate=You have already written the roommate post. cooltime.petition=You can't post again until one day after posting the petition. cooltime.general-forum=You can't post again until 3 minutes after posting. From 765a6aa7e2297d50047242baf42ba5a433d015d4 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:39:17 +0900 Subject: [PATCH 11/20] =?UTF-8?q?refactor:=20WithDankook=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/impl/WithDankookRedisRepository.java | 2 +- .../repository/{ => with_dankook}/BearEatsRepository.java | 2 +- .../{ => with_dankook}/EatingAloneRepository.java | 2 +- .../repository/{ => with_dankook}/StudyRepository.java | 4 +--- .../repository/{ => with_dankook}/TradeRepository.java | 2 +- .../{ => with_dankook}/WithDankookMemoryRepository.java | 2 +- .../{ => with_dankook}/WithDankookRepository.java | 6 +++--- 7 files changed, 9 insertions(+), 11 deletions(-) rename src/main/java/com/dku/council/domain/with_dankook/repository/{ => with_dankook}/BearEatsRepository.java (89%) rename src/main/java/com/dku/council/domain/with_dankook/repository/{ => with_dankook}/EatingAloneRepository.java (90%) rename src/main/java/com/dku/council/domain/with_dankook/repository/{ => with_dankook}/StudyRepository.java (88%) rename src/main/java/com/dku/council/domain/with_dankook/repository/{ => with_dankook}/TradeRepository.java (67%) rename src/main/java/com/dku/council/domain/with_dankook/repository/{ => with_dankook}/WithDankookMemoryRepository.java (92%) rename src/main/java/com/dku/council/domain/with_dankook/repository/{ => with_dankook}/WithDankookRepository.java (94%) diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/impl/WithDankookRedisRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/impl/WithDankookRedisRepository.java index 1800ca83..834e1f81 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/impl/WithDankookRedisRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/impl/WithDankookRedisRepository.java @@ -1,6 +1,6 @@ package com.dku.council.domain.with_dankook.repository.impl; -import com.dku.council.domain.with_dankook.repository.WithDankookMemoryRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookMemoryRepository; import com.dku.council.global.base.AbstractKeyValueCacheRepository; import com.dku.council.global.config.redis.RedisKeys; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/BearEatsRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/BearEatsRepository.java similarity index 89% rename from src/main/java/com/dku/council/domain/with_dankook/repository/BearEatsRepository.java rename to src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/BearEatsRepository.java index c771069c..93587852 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/BearEatsRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/BearEatsRepository.java @@ -1,4 +1,4 @@ -package com.dku.council.domain.with_dankook.repository; +package com.dku.council.domain.with_dankook.repository.with_dankook; import com.dku.council.domain.with_dankook.model.entity.type.BearEats; import org.springframework.data.domain.Page; diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/EatingAloneRepository.java similarity index 90% rename from src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java rename to src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/EatingAloneRepository.java index 04c28740..52ec5a17 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/EatingAloneRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/EatingAloneRepository.java @@ -1,4 +1,4 @@ -package com.dku.council.domain.with_dankook.repository; +package com.dku.council.domain.with_dankook.repository.with_dankook; import com.dku.council.domain.with_dankook.model.entity.type.EatingAlone; import org.springframework.data.domain.Page; diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/StudyRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/StudyRepository.java similarity index 88% rename from src/main/java/com/dku/council/domain/with_dankook/repository/StudyRepository.java rename to src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/StudyRepository.java index 4463564d..ed735995 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/StudyRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/StudyRepository.java @@ -1,4 +1,4 @@ -package com.dku.council.domain.with_dankook.repository; +package com.dku.council.domain.with_dankook.repository.with_dankook; import com.dku.council.domain.with_dankook.model.entity.type.Study; import org.springframework.data.domain.Page; @@ -6,8 +6,6 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import java.util.List; - public interface StudyRepository extends WithDankookRepository{ @Query("select s from Study s where s.masterUser.id = :userId and " + diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/TradeRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/TradeRepository.java similarity index 67% rename from src/main/java/com/dku/council/domain/with_dankook/repository/TradeRepository.java rename to src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/TradeRepository.java index e7b9e74e..cd5ccda0 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/TradeRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/TradeRepository.java @@ -1,4 +1,4 @@ -package com.dku.council.domain.with_dankook.repository; +package com.dku.council.domain.with_dankook.repository.with_dankook; import com.dku.council.domain.with_dankook.model.entity.type.Trade; diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookMemoryRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookMemoryRepository.java similarity index 92% rename from src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookMemoryRepository.java rename to src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookMemoryRepository.java index cea2ddf1..c3c8fc7d 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookMemoryRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookMemoryRepository.java @@ -1,4 +1,4 @@ -package com.dku.council.domain.with_dankook.repository; +package com.dku.council.domain.with_dankook.repository.with_dankook; import java.time.Duration; import java.time.Instant; diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java similarity index 94% rename from src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java rename to src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java index 7d0107d2..49d7faa7 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java @@ -1,6 +1,7 @@ -package com.dku.council.domain.with_dankook.repository; +package com.dku.council.domain.with_dankook.repository.with_dankook; import com.dku.council.domain.with_dankook.model.entity.WithDankook; +import com.dku.council.domain.with_dankook.model.entity.type.Roommate; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -18,7 +19,6 @@ public interface WithDankookRepository extends JpaReposit "join fetch u.major " + "where w.id=:id and w.withDankookStatus ='ACTIVE' ") Optional findById(@Param("id") Long id); - @Query("select w from WithDankook w " + "join fetch w.masterUser u " + "join fetch u.major " + @@ -55,7 +55,7 @@ public interface WithDankookRepository extends JpaReposit int findWithClosedByIdToCreateReview(@Param("withDankookId") Long withDankookId); @Query("select COUNT(*) from WithDankook w " + - "where w.id = :withDankookId and (w.withDankookStatus in ('FULL', 'CLOSED'))") + "where w.id = :withDankookId and (w.withDankookStatus = 'FULL' or w.withDankookStatus = 'CLOSED')") int findWithClosedOrFullByIdToCreateReview(@Param("withDankookId") Long withDankookId); @Query(value = "select COUNT(*) from with_dankook w " + From 1ffb78713647a30a988d8661b25e0d6e93bf4732 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:39:45 +0900 Subject: [PATCH 12/20] =?UTF-8?q?fix:=20ReviewService=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dku/council/domain/review/service/ReviewService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dku/council/domain/review/service/ReviewService.java b/src/main/java/com/dku/council/domain/review/service/ReviewService.java index 54c7ae8f..fab1cbf0 100644 --- a/src/main/java/com/dku/council/domain/review/service/ReviewService.java +++ b/src/main/java/com/dku/council/domain/review/service/ReviewService.java @@ -11,11 +11,10 @@ import com.dku.council.domain.review.repository.ReviewRepository; import com.dku.council.domain.user.model.entity.User; import com.dku.council.domain.user.repository.UserRepository; -import com.dku.council.domain.with_dankook.exception.InvalidStatusException; import com.dku.council.domain.with_dankook.exception.WithDankookUserNotFoundException; import com.dku.council.domain.with_dankook.model.entity.WithDankook; import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; -import com.dku.council.domain.with_dankook.repository.WithDankookRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookRepository; import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; import com.dku.council.domain.with_dankook.service.WithDankookService; import com.dku.council.domain.with_dankook.service.WithDankookUserService; @@ -56,7 +55,7 @@ public class ReviewService { @Transactional public void create(Long writerUserId, RequestCreateReviewDto dto) { // 리뷰 작성자가 본인에 대해서 리뷰를 작성하려고 한다면 - if (writerUserId == dto.getTargetUserId()) { + if (writerUserId.equals(dto.getTargetUserId())) { throw new InvalidCreateReviewToMyselfException(); } From 170c5afe5499209382a4fc4133e5faeb7bca31a4 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:40:09 +0900 Subject: [PATCH 13/20] =?UTF-8?q?fix:=20=EA=B5=AC=ED=95=B4=EC=A4=98=20?= =?UTF-8?q?=EB=A3=B8=EB=A9=94=20=EC=97=94=ED=8B=B0=ED=8B=B0=20Dormitory=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Roommate=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/type/{Dormitory.java => Roommate.java} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename src/main/java/com/dku/council/domain/with_dankook/model/entity/type/{Dormitory.java => Roommate.java} (68%) diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/Dormitory.java b/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/Roommate.java similarity index 68% rename from src/main/java/com/dku/council/domain/with_dankook/model/entity/type/Dormitory.java rename to src/main/java/com/dku/council/domain/with_dankook/model/entity/type/Roommate.java index f38ce05a..14e878f7 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/Dormitory.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/entity/type/Roommate.java @@ -1,6 +1,7 @@ package com.dku.council.domain.with_dankook.model.entity.type; import com.dku.council.domain.user.model.entity.User; +import com.dku.council.domain.with_dankook.model.entity.ResidenceDuration; import com.dku.council.domain.with_dankook.model.entity.WithDankook; import lombok.*; @@ -15,7 +16,7 @@ @Getter @Entity @NoArgsConstructor(access = PROTECTED) -public class Dormitory extends WithDankook { +public class Roommate extends WithDankook { @Id @GeneratedValue @@ -29,18 +30,17 @@ public class Dormitory extends WithDankook { private int minStudentId; @NotNull - private String livingHall; + private String livingPlace; - @NotNull - private String duration; + private ResidenceDuration residenceDuration; @Builder - private Dormitory(User user, String title, int minStudentId, String livingHall, String duration) { + private Roommate(User user, String title, int minStudentId, String livingPlace, ResidenceDuration residenceDuration) { super(user); this.title = title; this.minStudentId = minStudentId; - this.livingHall = livingHall; - this.duration = duration; + this.livingPlace = livingPlace; + this.residenceDuration = residenceDuration; } @Override From 71ab1be6913e5cfdfa3f0c88dd8bf97125d3c384 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:41:13 +0900 Subject: [PATCH 14/20] =?UTF-8?q?feat:=20WithDankook=EA=B3=BC=20WithDankoo?= =?UTF-8?q?kUser=20=ED=81=B4=EB=9E=98=EC=8A=A4=EC=97=90=20Enum=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/with_dankook/model/ParticipantStatus.java | 5 +++++ .../with_dankook/model/entity/ResidenceDuration.java | 7 +++++++ .../with_dankook/model/entity/WithDankook.java | 4 ++++ .../with_dankook/model/entity/WithDankookUser.java | 12 ++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/entity/ResidenceDuration.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/ParticipantStatus.java b/src/main/java/com/dku/council/domain/with_dankook/model/ParticipantStatus.java index ac2a4509..75415372 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/ParticipantStatus.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/ParticipantStatus.java @@ -6,6 +6,11 @@ public enum ParticipantStatus { */ VALID, + /** + * 참여자가 신청 대기중인 상태 + */ + WAITING, + /** * 참여자가 유효하지 않은 상태 */ diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/entity/ResidenceDuration.java b/src/main/java/com/dku/council/domain/with_dankook/model/entity/ResidenceDuration.java new file mode 100644 index 00000000..6ca8bd9c --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/entity/ResidenceDuration.java @@ -0,0 +1,7 @@ +package com.dku.council.domain.with_dankook.model.entity; + +public enum ResidenceDuration { + SEMESTER, + HALF_YEAR, + YEAR +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankook.java b/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankook.java index 76d42f97..ecc286f5 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankook.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankook.java @@ -57,6 +57,10 @@ public void markAsFull() { this.withDankookStatus = WithDankookStatus.FULL; } + public void markAsClosed() { + this.withDankookStatus = WithDankookStatus.CLOSED; + } + public boolean isClosed() { return withDankookStatus == WithDankookStatus.CLOSED; } diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankookUser.java b/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankookUser.java index 54b1af71..32df583d 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankookUser.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/entity/WithDankookUser.java @@ -48,4 +48,16 @@ public WithDankookUser(User user, WithDankook withDankook) { public void changeReviewStatus() { this.reviewStatus = true; } + + public void changeStatusToWaiting() { + this.participantStatus = ParticipantStatus.WAITING; + } + + public void changeStatusToValid() { + this.participantStatus = ParticipantStatus.VALID; + } + + public void changeStatusToInvalid() { + this.participantStatus = ParticipantStatus.INVALID; + } } From b80b49d2690b323e6d4a585cdb2e50c284558a33 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:41:40 +0900 Subject: [PATCH 15/20] =?UTF-8?q?fix:=20=EC=84=A4=EB=AC=B8=EC=A1=B0?= =?UTF-8?q?=EC=82=AC=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EC=97=90=20=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EC=97=90=EB=84=88=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/with_dankook/model/entity/RoomMateSurvey.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/entity/RoomMateSurvey.java b/src/main/java/com/dku/council/domain/with_dankook/model/entity/RoomMateSurvey.java index 83dd1d16..d3f24c7e 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/model/entity/RoomMateSurvey.java +++ b/src/main/java/com/dku/council/domain/with_dankook/model/entity/RoomMateSurvey.java @@ -38,6 +38,8 @@ public class RoomMateSurvey extends BaseEntity { @NotNull private boolean noiseHabit; + private String noiseHabitDetail; + @Enumerated(EnumType.STRING) private SleepTime sleepTime; @@ -48,13 +50,14 @@ public class RoomMateSurvey extends BaseEntity { private String tendency; @Builder - public RoomMateSurvey(@NonNull User user, @NonNull String mbti, boolean sleepHabit, boolean sleepSensitive, boolean smoking, boolean noiseHabit, @NonNull SleepTime sleepTime, @NonNull CleanUpCount cleanUpCount, String tendency) { + public RoomMateSurvey(User user, String mbti, boolean sleepHabit, boolean sleepSensitive, boolean smoking, boolean noiseHabit, String noiseHabitDetail, SleepTime sleepTime, CleanUpCount cleanUpCount, String tendency) { this.user = user; this.mbti = mbti; this.sleepHabit = sleepHabit; this.sleepSensitive = sleepSensitive; this.smoking = smoking; this.noiseHabit = noiseHabit; + this.noiseHabitDetail = noiseHabitDetail; this.sleepTime = sleepTime; this.cleanUpCount = cleanUpCount; this.tendency = tendency; From e40b513d7d863bbe2354ecb91c2604bbf9329f1e Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:41:57 +0900 Subject: [PATCH 16/20] =?UTF-8?q?feat:=20=EA=B5=AC=ED=95=B4=EC=A4=98=20?= =?UTF-8?q?=EB=A3=B8=EB=A9=94=20=EA=B4=80=EB=A0=A8=20=EB=A0=88=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/RoomMateSurveyRepository.java | 17 ++++++++++++++ .../repository/WithDankookUserRepository.java | 14 +++++++++++ .../with_dankook/RoommateRepository.java | 23 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/repository/RoomMateSurveyRepository.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/RoommateRepository.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/RoomMateSurveyRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/RoomMateSurveyRepository.java new file mode 100644 index 00000000..c98b66bc --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/RoomMateSurveyRepository.java @@ -0,0 +1,17 @@ +package com.dku.council.domain.with_dankook.repository; + +import com.dku.council.domain.with_dankook.model.entity.RoomMateSurvey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.Optional; + +public interface RoomMateSurveyRepository extends JpaRepository { + + boolean existsByUserId(Long userId); + + @Query("select s from RoomMateSurvey s " + + "where s.user.id = :userId") + Optional findByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookUserRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookUserRepository.java index 73474337..f2086312 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookUserRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/WithDankookUserRepository.java @@ -29,4 +29,18 @@ public interface WithDankookUserRepository extends JpaRepository checkReviewStatus(Long withDankookId, Long userId); + + @Query("select u from WithDankookUser u " + + "where u.withDankook.id = :withDankookId " + + "and u.participant.id = :userId ") + Optional findByUserIdAndWithDankookId(@Param("userId") Long userId, @Param("withDankookId") Long withDankookId); + + @Query("select u from WithDankookUser u " + + "where u.participant.id =: targetUserId and " + + "u.participantStatus = 'VALID' ") + boolean findByUserIdCheckingValid(@Param("targetUserId") Long targetUserId); + + @Query("select u from WithDankookUser u " + + "where u.participant.id =: userId ") + Optional findByParticipantId(@Param("userId") Long userId); } diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/RoommateRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/RoommateRepository.java new file mode 100644 index 00000000..fdbbbb5d --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/RoommateRepository.java @@ -0,0 +1,23 @@ +package com.dku.council.domain.with_dankook.repository.with_dankook; + +import com.dku.council.domain.with_dankook.model.entity.type.Roommate; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import javax.swing.text.html.Option; +import java.util.Optional; + +public interface RoommateRepository extends WithDankookRepository{ + @Query("select r from Roommate r " + + "where r.masterUser.gender = :gender " + + "and r.withDankookStatus = 'ACTIVE' " + + "order by r.createdAt desc") + Page findAllByUserGender(@Param("gender") String gender, Pageable pageable); + + @Query("select r from Roommate r " + + "where r.masterUser.id = :userId and " + + "(r.withDankookStatus != 'DELETED' or r.withDankookStatus != 'DELETED_BY_ADMIN') ") + Optional findByUserId(@Param("userId") Long userId); +} From 2077063b304b4158ff8787ad492ac8abfc80e350 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:42:27 +0900 Subject: [PATCH 17/20] =?UTF-8?q?fix:=20import=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/with_dankook/service/BearEatsService.java | 2 +- .../with_dankook/service/EatingAloneService.java | 2 +- .../domain/with_dankook/service/StudyService.java | 6 ++---- .../with_dankook/service/WithDankookService.java | 10 +++++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/BearEatsService.java b/src/main/java/com/dku/council/domain/with_dankook/service/BearEatsService.java index dff7a20e..9ae72d47 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/service/BearEatsService.java +++ b/src/main/java/com/dku/council/domain/with_dankook/service/BearEatsService.java @@ -10,7 +10,7 @@ import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleBearEatsDto; import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; import com.dku.council.domain.with_dankook.model.entity.type.BearEats; -import com.dku.council.domain.with_dankook.repository.BearEatsRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.BearEatsRepository; import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; import com.dku.council.global.auth.role.UserRole; import com.dku.council.global.error.exception.UserNotFoundException; diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java b/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java index 8c02eb11..32acb369 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java +++ b/src/main/java/com/dku/council/domain/with_dankook/service/EatingAloneService.java @@ -10,7 +10,7 @@ import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleEatingAloneDto; import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; import com.dku.council.domain.with_dankook.model.entity.type.EatingAlone; -import com.dku.council.domain.with_dankook.repository.EatingAloneRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.EatingAloneRepository; import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; import com.dku.council.global.auth.role.UserRole; import com.dku.council.global.error.exception.UserNotFoundException; diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/StudyService.java b/src/main/java/com/dku/council/domain/with_dankook/service/StudyService.java index c2a75111..8e1287bb 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/service/StudyService.java +++ b/src/main/java/com/dku/council/domain/with_dankook/service/StudyService.java @@ -5,17 +5,15 @@ import com.dku.council.domain.user.model.entity.User; import com.dku.council.domain.user.repository.UserRepository; import com.dku.council.domain.with_dankook.exception.InvalidMinStudentIdException; -import com.dku.council.domain.with_dankook.exception.InvalidStatusException; import com.dku.council.domain.with_dankook.exception.StudyCooltimeException; import com.dku.council.domain.with_dankook.exception.WithDankookNotFoundException; -import com.dku.council.domain.with_dankook.model.ParticipantStatus; import com.dku.council.domain.with_dankook.model.dto.list.SummarizedStudyDto; import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateStudyDto; import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleStudyDto; import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; import com.dku.council.domain.with_dankook.model.entity.type.Study; -import com.dku.council.domain.with_dankook.repository.StudyRepository; -import com.dku.council.domain.with_dankook.repository.WithDankookMemoryRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.StudyRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookMemoryRepository; import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; import com.dku.council.domain.with_dankook.repository.spec.WithDankookSpec; import com.dku.council.global.auth.role.UserRole; diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java b/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java index 59527e86..2d3e00ed 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java +++ b/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java @@ -16,7 +16,7 @@ import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleWithDankookDto; import com.dku.council.domain.with_dankook.model.entity.WithDankook; import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; -import com.dku.council.domain.with_dankook.repository.WithDankookRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookRepository; import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; import com.dku.council.domain.with_dankook.repository.spec.WithDankookSpec; import com.dku.council.global.auth.role.UserRole; @@ -217,10 +217,10 @@ public void isPossibleCreateReview(Long withDankookId) { if (withDankookRepository.findWithClosedByIdToCreateReview(withDankookId) != 1) { throw new InvalidStatusException(); } - } else if (withDankookType.equals("Study") || withDankookType.equals("Dormitory")) { - if (withDankookRepository.findWithClosedOrFullOrActiveByIdToCreateReview(withDankookId) != 1) { - throw new InvalidStatusException(); - } +// } else if (withDankookType.equals("Study") || withDankookType.equals("Dormitory")) { +// if (withDankookRepository.findWithClosedOrFullOrActiveByIdToCreateReview(withDankookId) != 1) { +// throw new InvalidStatusException(); +// } } else if (withDankookType.equals("BearEats") || withDankookType.equals("EatingAlong")) { if (withDankookRepository.findWithClosedOrFullByIdToCreateReview(withDankookId) != 1) { throw new InvalidStatusException(); From 391a8adad554cfe0002075bcdc5f4d4688d38f41 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:42:36 +0900 Subject: [PATCH 18/20] =?UTF-8?q?fix:=20import=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../council/domain/with_dankook/service/TradeService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/TradeService.java b/src/main/java/com/dku/council/domain/with_dankook/service/TradeService.java index 3bc511ec..3de13b93 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/service/TradeService.java +++ b/src/main/java/com/dku/council/domain/with_dankook/service/TradeService.java @@ -7,14 +7,13 @@ import com.dku.council.domain.with_dankook.exception.ImageSizeExceededException; import com.dku.council.domain.with_dankook.exception.TradeCooltimeException; import com.dku.council.domain.with_dankook.exception.WithDankookNotFoundException; -import com.dku.council.domain.with_dankook.model.WithDankookStatus; import com.dku.council.domain.with_dankook.model.dto.list.SummarizedTradeDto; import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateTradeDto; import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleTradeDto; import com.dku.council.domain.with_dankook.model.entity.TradeImage; import com.dku.council.domain.with_dankook.model.entity.type.Trade; -import com.dku.council.domain.with_dankook.repository.TradeRepository; -import com.dku.council.domain.with_dankook.repository.WithDankookMemoryRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.TradeRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookMemoryRepository; import com.dku.council.domain.with_dankook.repository.spec.WithDankookSpec; import com.dku.council.global.auth.role.UserRole; import com.dku.council.global.error.exception.NotGrantedException; From 71338c81b7309983818af85c311f68981ff43866 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:43:02 +0900 Subject: [PATCH 19/20] =?UTF-8?q?feat:=20=EA=B5=AC=ED=95=B4=EC=A4=98!=20?= =?UTF-8?q?=EB=A3=B8=EB=A9=94=20=EA=B4=80=EB=A0=A8=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/dto/list/SummarizedRoommateDto.java | 51 +++++ .../dto/request/RequestCreateRoommateDto.java | 50 +++++ .../dto/request/RequestCreateSurveyDto.java | 84 ++++++++ .../response/ResponseRoommateSurveyDto.java | 41 ++++ .../response/ResponseSingleRoommateDto.java | 56 ++++++ .../with_dankook/service/RoommateService.java | 182 ++++++++++++++++++ .../with_dankook/service/SurveyService.java | 60 ++++++ src/main/resources/messages.properties | 24 ++- src/main/resources/messages_en_US.properties | 24 ++- 9 files changed, 552 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedRoommateDto.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateRoommateDto.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateSurveyDto.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseRoommateSurveyDto.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleRoommateDto.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/service/RoommateService.java create mode 100644 src/main/java/com/dku/council/domain/with_dankook/service/SurveyService.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedRoommateDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedRoommateDto.java new file mode 100644 index 00000000..512d570e --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedRoommateDto.java @@ -0,0 +1,51 @@ +package com.dku.council.domain.with_dankook.model.dto.list; + +import com.dku.council.domain.with_dankook.model.entity.type.Roommate; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +@Getter +public class SummarizedRoommateDto extends SummarizedWithDankookDto { + + @Schema(description = "작성자 닉네임", example = "익명") + private final String nickname; + + @Schema(description = "작성자 학번", example = "12345678") + private final String studentId; + + @Schema(description = "작성자 전공", example = "SW융합대학") + private final String major; + + @Schema(description = "작성자 학과", example = "소프트웨어학과") + private final String department; + + @Schema(description = "기숙사 생활관", example = "웅비홀") + private final String livingPlace; + + @Schema(description = "거주 기간", example = "SEMESTER") + private final String residenceDuration; + + @Schema(description = "모집된 인원", example = "1") + private final int recruitedCount; + + @Schema(description = "설문조사 일치 수", example = "1") + private final int equalCount; + + @Schema(description = "내가 작성한 게시글인지 여부", example = "true") + private final boolean isMine; + + public SummarizedRoommateDto(SummarizedWithDankookDto dto, Roommate roommate, MessageSource messageSource, int recruitedCount, int equalCount, boolean isMine) { + super(dto); + this.nickname = roommate.getMasterUser().getNickname(); + this.studentId = roommate.getMasterUser().getStudentId(); + this.major = roommate.getMasterUser().getMajor().getName(); + this.department = roommate.getMasterUser().getMajor().getDepartment(); + this.livingPlace = roommate.getLivingPlace(); + this.residenceDuration = messageSource.getMessage("withdankook.residence.duration." + roommate.getResidenceDuration().name().toLowerCase(), null , LocaleContextHolder.getLocale()); + this.recruitedCount = recruitedCount; + this.equalCount = equalCount; + this.isMine = isMine; + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateRoommateDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateRoommateDto.java new file mode 100644 index 00000000..4901309e --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateRoommateDto.java @@ -0,0 +1,50 @@ +package com.dku.council.domain.with_dankook.model.dto.request; + +import com.dku.council.domain.user.model.entity.User; +import com.dku.council.domain.with_dankook.model.entity.ResidenceDuration; +import com.dku.council.domain.with_dankook.model.entity.type.Roommate; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; + +import javax.validation.constraints.NotNull; + +@Getter +public class RequestCreateRoommateDto extends RequestCreateWithDankookDto { + + @NotNull + @Schema(description = "제목", example = "기숙사 구해요") + private final String title; + + @NotNull + @Schema(description = "최소 학번", example = "20190000") + private final int minStudentId; + + @NotNull + @Schema(description = "기숙사", example = "웅비홀") + private final String livingPlace; + + @NotNull + @Schema(description = "거주 기간", example = "HALF_YEAR") + private final ResidenceDuration residenceDuration; + + public RequestCreateRoommateDto(@NotNull String title, + @NotNull int minStudentId, + @NotNull String livingPlace, + @NotNull ResidenceDuration residenceDuration) { + this.title = title; + this.minStudentId = minStudentId; + this.livingPlace = livingPlace; + this.residenceDuration = residenceDuration; + } + + @Override + public Roommate toEntity(User user) { + return Roommate.builder() + .user(user) + .title(title) + .minStudentId(minStudentId) + .livingPlace(livingPlace) + .residenceDuration(residenceDuration) + .build(); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateSurveyDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateSurveyDto.java new file mode 100644 index 00000000..52230f2f --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateSurveyDto.java @@ -0,0 +1,84 @@ +package com.dku.council.domain.with_dankook.model.dto.request; + +import com.dku.council.domain.user.model.entity.User; +import com.dku.council.domain.with_dankook.model.CleanUpCount; +import com.dku.council.domain.with_dankook.model.SleepTime; +import com.dku.council.domain.with_dankook.model.entity.RoomMateSurvey; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +public class RequestCreateSurveyDto { + + @NotNull + @Schema(description = "MBTI", example = "INTJ") + private final String mbti; + + @NotNull + @Schema(description = "수면습관", example = "true") + private final boolean sleepHabit; + + @NotNull + @Schema(description = "수면민감도", example = "true") + private final boolean sleepSensitive; + + @NotNull + @Schema(description = "흡연", example = "true") + private final boolean smoking; + + @NotNull + @Schema(description = "소음습관", example = "true") + private final boolean noiseHabit; + + @Schema(description = "소음습관 상세", example = "") + private final String noiseHabitDetail; + + @NotNull + @Schema(description = "수면시간", example = "AVG_TWELVE") + private final SleepTime sleepTime; + + @NotNull + @Schema(description = "청소횟수", example = "ONCE_A_WEEK") + private final CleanUpCount cleanUpCount; + + @Schema(description = "기타 성향", example = "") + private final String tendency; + + public RequestCreateSurveyDto(@NotBlank String mbti, + @NotNull boolean sleepHabit, + @NotNull boolean sleepSensitive, + @NotNull boolean smoking, + @NotNull boolean noiseHabit, + String noiseHabitDetail, + @NotNull SleepTime sleepTime, + @NotNull CleanUpCount cleanUpCount, + String tendency) { + this.mbti = mbti.toUpperCase(); + this.sleepHabit = sleepHabit; + this.sleepSensitive = sleepSensitive; + this.smoking = smoking; + this.noiseHabit = noiseHabit; + this.noiseHabitDetail = noiseHabit ? noiseHabitDetail : null; + this.sleepTime = sleepTime; + this.cleanUpCount = cleanUpCount; + this.tendency = tendency; + } + + public RoomMateSurvey toEntity(User user) { + return RoomMateSurvey.builder() + .user(user) + .mbti(mbti) + .sleepHabit(sleepHabit) + .sleepSensitive(sleepSensitive) + .smoking(smoking) + .noiseHabit(noiseHabit) + .noiseHabitDetail(noiseHabitDetail) + .sleepTime(sleepTime) + .cleanUpCount(cleanUpCount) + .tendency(tendency) + .build(); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseRoommateSurveyDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseRoommateSurveyDto.java new file mode 100644 index 00000000..b6aea9a3 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseRoommateSurveyDto.java @@ -0,0 +1,41 @@ +package com.dku.council.domain.with_dankook.model.dto.response; + +import com.dku.council.domain.with_dankook.model.entity.RoomMateSurvey; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class ResponseRoommateSurveyDto { + + private final String mbti; + + private final boolean sleephabit; + + private final boolean sleepSensitive; + + private final boolean smoking; + + private final boolean noiseHabit; + + private final String noiseHabitDetail; + + private final String sleepTime; + + private final String cleanUpCount; + + private final String tendency; + + @Builder + public ResponseRoommateSurveyDto(RoomMateSurvey survey) { + this.mbti = survey.getMbti(); + this.sleephabit = survey.isSleepHabit(); + this.sleepSensitive = survey.isSleepSensitive(); + this.smoking = survey.isSmoking(); + this.noiseHabit = survey.isNoiseHabit(); + this.noiseHabitDetail = survey.getNoiseHabitDetail(); + this.sleepTime = survey.getSleepTime().name(); + this.cleanUpCount = survey.getCleanUpCount().name(); + this.tendency = survey.getTendency(); + } + +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleRoommateDto.java b/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleRoommateDto.java new file mode 100644 index 00000000..38ce1c1a --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleRoommateDto.java @@ -0,0 +1,56 @@ +package com.dku.council.domain.with_dankook.model.dto.response; + +import com.dku.council.domain.with_dankook.model.ParticipantStatus; +import com.dku.council.domain.with_dankook.model.dto.RecruitedUsersDto; +import com.dku.council.domain.with_dankook.model.entity.RoomMateSurvey; +import com.dku.council.domain.with_dankook.model.entity.type.Roommate; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +public class ResponseSingleRoommateDto extends ResponseSingleWithDankookDto { + + @Schema(description = "제목", example = "게시글 제목") + private final String title; + + @Schema(description = "최소 학번", example = "19") + private final int minStudentId; + + @Schema(description = "거주지", example = "웅비홀") + private final String livingPlace; + + @Schema(description = "거주 기간", example = "SEMESTER") + private final String residenceDuration; + + @Schema(description = "룸메이트 설문조사 내용") + private final ResponseRoommateSurveyDto survey; + + @Schema(description = "신청자 리스트") + private final List applicantList; + + @Schema(description = "승인한 사용자 리스트") + private final List approvedList; + + public ResponseSingleRoommateDto(ResponseSingleWithDankookDto dto, Roommate roommate, RoomMateSurvey survey, MessageSource messageSource) { + super(dto); + this.title = roommate.getTitle(); + this.minStudentId = roommate.getMinStudentId(); + this.livingPlace = roommate.getLivingPlace(); + this.residenceDuration = messageSource.getMessage("withdankook.residence.duration." + roommate.getResidenceDuration().name().toLowerCase(), null, LocaleContextHolder.getLocale()); + this.survey = new ResponseRoommateSurveyDto(survey); + this.applicantList = roommate.getUsers().stream().filter((user) -> + user.getParticipantStatus() == ParticipantStatus.WAITING) + .map(RecruitedUsersDto::new) + .collect(Collectors.toList()); + this.approvedList = roommate.getUsers().stream().filter((user) -> + user.getParticipantStatus() == ParticipantStatus.VALID && !user.getParticipant().getId().equals(roommate.getMasterUser().getId())) + .map(RecruitedUsersDto::new) + .collect(Collectors.toList()); + } + +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/RoommateService.java b/src/main/java/com/dku/council/domain/with_dankook/service/RoommateService.java new file mode 100644 index 00000000..4d6c5653 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/service/RoommateService.java @@ -0,0 +1,182 @@ +package com.dku.council.domain.with_dankook.service; + +import com.dku.council.domain.user.model.entity.User; +import com.dku.council.domain.user.repository.UserRepository; +import com.dku.council.domain.with_dankook.exception.*; +import com.dku.council.domain.with_dankook.model.ParticipantStatus; +import com.dku.council.domain.with_dankook.model.dto.list.SummarizedRoommateDto; +import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateRoommateDto; +import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleRoommateDto; +import com.dku.council.domain.with_dankook.model.entity.RoomMateSurvey; +import com.dku.council.domain.with_dankook.model.entity.WithDankookUser; +import com.dku.council.domain.with_dankook.model.entity.type.Roommate; +import com.dku.council.domain.with_dankook.repository.RoomMateSurveyRepository; +import com.dku.council.domain.with_dankook.repository.WithDankookUserRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.RoommateRepository; +import com.dku.council.domain.with_dankook.repository.with_dankook.WithDankookRepository; +import com.dku.council.global.auth.role.UserRole; +import com.dku.council.global.error.exception.NotGrantedException; +import com.dku.council.global.error.exception.UserNotFoundException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.MessageSource; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Slf4j +public class RoommateService { + + private final RoommateRepository roommateRepository; + private final WithDankookUserRepository withDankookUserRepository; + private final UserRepository userRepository; + private final RoomMateSurveyRepository surveyRepository; + + private final WithDankookService withDankookService; + private final WithDankookUserService withDankookUserService; + + private final MessageSource messageSource; + + @Transactional(readOnly = true) + public Page list(Long userId, Pageable pageable, int bodySize) { + User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + + RoomMateSurvey userSurvey = surveyRepository.findByUserId(userId).orElseThrow(RoommateSurveyNotFoundException::new); + Page list = roommateRepository.findAllByUserGender(user.getGender(), pageable); + return list.map((roommate) -> new SummarizedRoommateDto( + withDankookService.makeListDto(bodySize, roommate), + roommate, + messageSource, + withDankookUserService.recruitedCount(withDankookService.makeListDto(bodySize, roommate).getId()), + checkEqualCount(userSurvey, surveyRepository.findByUserId(roommate.getMasterUser().getId()).orElseThrow(RoommateSurveyNotFoundException::new)), + checkIsMine(userId, roommate) + )); + } + + @Transactional(readOnly = true) + public ResponseSingleRoommateDto findOne(Long roommateId, Long userId, UserRole role) { + Roommate roommate = findRoommate(roommateRepository, roommateId, role); + RoomMateSurvey survey = surveyRepository.findByUserId(roommate.getMasterUser().getId()).orElseThrow(RoommateSurveyNotFoundException::new); + return new ResponseSingleRoommateDto( + withDankookService.makeSingleDto(userId, roommate), roommate, survey, messageSource + ); + } + + private Roommate findRoommate(RoommateRepository roommateRepository, Long roommateId, UserRole role) { + Optional roommate; + if (role.isAdmin()) { + roommate = roommateRepository.findWithAllStatusById(roommateId); + } else { + roommate = roommateRepository.findWithNotDeletedById(roommateId); + } + return roommate.orElseThrow(WithDankookNotFoundException::new); + } + + @Transactional + public Long create(Long userId, RequestCreateRoommateDto dto) { + roommateRepository.findByUserId(userId).ifPresent((roommate) -> { + throw new AlreadyWrittenRoommateException(); + }); + Long result = withDankookService.create(roommateRepository, userId, dto); + WithDankookUser withDankookUser = WithDankookUser.builder() + .withDankook(roommateRepository.findById(result).orElseThrow(WithDankookNotFoundException::new)) + .user(userRepository.findById(userId).orElseThrow(UserNotFoundException::new)) + .build(); + withDankookUserRepository.save(withDankookUser); + + return result; + } + + @Transactional + public void apply(Long userId, Long roommateId, UserRole role) { + Roommate roommate = findRoommate(roommateRepository, roommateId, role); + User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + + validateApplicant(roommate, user); + + WithDankookUser applicant = WithDankookUser.builder() + .withDankook(roommate) + .user(user) + .build(); + applicant.changeStatusToWaiting(); + withDankookUserRepository.save(applicant); + } + + @Transactional + public void approve(Long writerId, Long roommateId, Long targetUserId) { + Roommate roommate = roommateRepository.findById(roommateId).orElseThrow(WithDankookNotFoundException::new); + WithDankookUser targetUser = withDankookUserRepository.findByUserIdAndWithDankookId(targetUserId, roommateId).orElseThrow(WithDankookUserNotFoundException::new); + + if (!checkIsMine(writerId, roommate)) { + throw new NotGrantedException(); + } + + if (targetUser.getParticipantStatus().equals(ParticipantStatus.WAITING) + && !withDankookUserRepository.findByUserIdCheckingValid(targetUserId)) { + targetUser.changeStatusToValid(); + withDankookUserRepository.save(targetUser); + } else { + throw new NotGrantedException(); + } + + if (withDankookUserService.recruitedCount(roommateId) == 2) { + roommate.markAsClosed(); + } + } + + @Transactional + public void delete(Long userId, boolean isAdmin, Long withDankookId) { + withDankookService.delete(roommateRepository, withDankookId, userId, isAdmin); + WithDankookUser withDankookUser = withDankookUserRepository.findByUserIdAndWithDankookId(userId, withDankookId).orElseThrow(WithDankookUserNotFoundException::new); + withDankookUser.changeStatusToInvalid(); + } + + private void validateApplicant(Roommate roommate, User user) { + boolean isInvalid = withDankookService.isInvalidParticipant(roommate, user); + if(isInvalid) { + throw new InvalidStatusException(); + } + if (roommate.getMinStudentId() < Integer.parseInt(String.valueOf(user.getYearOfAdmission()).substring(2))) { + throw new InvalidMinStudentIdException(); + } + if (withDankookUserService.isParticipant(roommate.getId(), user.getId())) { + throw new AlreadyEnteredException(); + } + } + + + private int checkEqualCount(RoomMateSurvey userSurvey, RoomMateSurvey writerSurvey) { + int count = 0; + if (userSurvey.getMbti().equals(writerSurvey.getMbti())) { + count++; + } + if (userSurvey.isSleepHabit() == writerSurvey.isSleepHabit()) { + count++; + } + if (userSurvey.isSleepSensitive() == writerSurvey.isSleepSensitive()) { + count++; + } + if (userSurvey.isSmoking() == writerSurvey.isSmoking()) { + count++; + } + if (userSurvey.isNoiseHabit() == writerSurvey.isNoiseHabit()) { + count++; + } + if (userSurvey.getSleepTime().equals(writerSurvey.getSleepTime())) { + count++; + } + if (userSurvey.getCleanUpCount() == writerSurvey.getCleanUpCount()) { + count++; + } + return count; + } + + private boolean checkIsMine(Long userId, Roommate roommate) { + return roommate.getMasterUser().getId().equals(userId); + } +} diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/SurveyService.java b/src/main/java/com/dku/council/domain/with_dankook/service/SurveyService.java new file mode 100644 index 00000000..d32655ab --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/service/SurveyService.java @@ -0,0 +1,60 @@ +package com.dku.council.domain.with_dankook.service; + +import com.dku.council.domain.user.model.entity.User; +import com.dku.council.domain.user.repository.UserRepository; +import com.dku.council.domain.with_dankook.exception.AlreadySurveyException; +import com.dku.council.domain.with_dankook.exception.InvalidMBTIException; +import com.dku.council.domain.with_dankook.exception.InvalidNoiseHabitException; +import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateSurveyDto; +import com.dku.council.domain.with_dankook.repository.RoomMateSurveyRepository; +import com.dku.council.global.error.exception.UserNotFoundException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +public class SurveyService { + + private static final List MBTIList = List.of( + "ISTJ", "ISFJ", "INFJ", "INTJ", "ISTP", "ISFP", "INFP", "INTP", + "ESTP", "ESFP", "ENFP", "ENTP", "ESTJ", "ESFJ", "ENFJ", "ENTJ"); + + private final RoomMateSurveyRepository surveyRepository; + private final UserRepository userRepository; + + @Transactional + public Long createSurvey(Long userId, RequestCreateSurveyDto dto) { + User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + + if (surveyRepository.existsByUserId(userId)) { + throw new AlreadySurveyException(); + + } else if (!isValidMBTI(dto.getMbti())) { + throw new InvalidMBTIException(); + + } else if (!checkSurveyNoiseHabit(dto.isNoiseHabit(), dto.getNoiseHabitDetail())) { + throw new InvalidNoiseHabitException(); + + } else { + return surveyRepository.save(dto.toEntity(user)).getId(); + } + } + + @Transactional(readOnly = true) + public boolean checkSurvey(Long userId) { + return surveyRepository.existsByUserId(userId); + } + + private boolean isValidMBTI(String mbti) { + return mbti.length() == 4 && MBTIList.contains(mbti); + } + + private boolean checkSurveyNoiseHabit(boolean noiseHabit, String noiseHabitDetail) { + return !noiseHabit || noiseHabitDetail != null; + } +} diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 1c92715f..734d3b6b 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -19,6 +19,10 @@ report.category.fraud=\uC720\uCD9C/\uC0AC\uCE6D/\uC0AC\uAE30 withdankook.trade.active=\uD310\uB9E4\uC911 withdankook.trade.closed=\uAC70\uB798\uC644\uB8CC +withdankook.residence.duration.semester=\uD559\uAE30 +withdankook.residence.duration.half_year=\uBC18\uAE30 +withdankook.residence.duration.year=1\uB144 + withdankook.review.eatingalong.positive.1=\uBC25\uC744 \uC798 \uC0AC\uC918\uC694 withdankook.review.eatingalong.positive.2=\uC2DC\uAC04 \uC57D\uC18D\uC744 \uC798 \uC9C0\uCF1C\uC694 withdankook.review.eatingalong.positive.3=\uBA54\uB274\uB97C \uC798 \uACE8\uB77C\uC694 @@ -63,14 +67,14 @@ withdankook.review.beareats.negative.3=\uBC30\uB2EC \uC7A5\uC18C\uB97C \uC790\uA withdankook.review.beareats.negative.4=\uBD88\uCE5C\uC808\uD574\uC694 withdankook.review.beareats.negative.5=\uC815\uC0B0\uC744 \uC81C\uB54C \uD574\uC8FC\uC9C0 \uC54A\uC544\uC694 -withdankook.review.dormitory.positive.1=\uADDC\uCE59\uC744 \uC798 \uC9C0\uCF1C\uC918\uC694 -withdankook.review.dormitory.positive.2=\uCE5C\uC808\uD574\uC694 -withdankook.review.dormitory.positive.3=\uC18C\uD1B5\uC774 \uC798 \uB3FC\uC694 -withdankook.review.dormitory.positive.4=\uC0C1\uB300\uBC29\uC744 \uC874\uC911\uD574\uC918\uC694 -withdankook.review.dormitory.positive.5=\uAE30\uC7AC\uD55C \uC0AC\uD56D\uACFC \uBE44\uC2B7\uD574\uC694 -withdankook.review.dormitory.negative.1=\uADDC\uCE59\uC744 \uC798 \uC9C0\uCF1C\uC8FC\uC9C0 \uC54A\uC544\uC694 -withdankook.review.dormitory.negative.2=\uBD88\uCE5C\uC808\uD574\uC694 -withdankook.review.dormitory.negative.3=\uC18C\uD1B5\uC758 \uC5B4\uB824\uC6C0\uC744 \uC790\uC8FC \uACAA\uC5C8\uC5B4\uC694 -withdankook.review.dormitory.negative.4=\uC0C1\uB300\uBC29\uC744 \uC874\uC911\uD558\uC9C0 \uC54A\uC544\uC694 -withdankook.review.dormitory.negative.5=\uAE30\uC7AC\uD55C \uC0AC\uD56D\uACFC \uB2EC\uB77C\uC694 +withdankook.review.roommate.positive.1=\uADDC\uCE59\uC744 \uC798 \uC9C0\uCF1C\uC918\uC694 +withdankook.review.roommate.positive.2=\uCE5C\uC808\uD574\uC694 +withdankook.review.roommate.positive.3=\uC18C\uD1B5\uC774 \uC798 \uB3FC\uC694 +withdankook.review.roommate.positive.4=\uC0C1\uB300\uBC29\uC744 \uC874\uC911\uD574\uC918\uC694 +withdankook.review.roommate.positive.5=\uAE30\uC7AC\uD55C \uC0AC\uD56D\uACFC \uBE44\uC2B7\uD574\uC694 +withdankook.review.roommate.negative.1=\uADDC\uCE59\uC744 \uC798 \uC9C0\uCF1C\uC8FC\uC9C0 \uC54A\uC544\uC694 +withdankook.review.roommate.negative.2=\uBD88\uCE5C\uC808\uD574\uC694 +withdankook.review.roommate.negative.3=\uC18C\uD1B5\uC758 \uC5B4\uB824\uC6C0\uC744 \uC790\uC8FC \uACAA\uC5C8\uC5B4\uC694 +withdankook.review.roommate.negative.4=\uC0C1\uB300\uBC29\uC744 \uC874\uC911\uD558\uC9C0 \uC54A\uC544\uC694 +withdankook.review.roommate.negative.5=\uAE30\uC7AC\uD55C \uC0AC\uD56D\uACFC \uB2EC\uB77C\uC694 diff --git a/src/main/resources/messages_en_US.properties b/src/main/resources/messages_en_US.properties index 60ea3ee3..a6dad397 100644 --- a/src/main/resources/messages_en_US.properties +++ b/src/main/resources/messages_en_US.properties @@ -19,6 +19,10 @@ report.category.fraud=leakage/impersonation/fraud withdankook.trade.active=Selling withdankook.trade.closed=Closed +withdankook.residence.duration.semester=Semester +withdankook.residence.duration.half_year=Half year +withdankook.residence.duration.year=Year + withdankook.review.eatingalong.positive.1=Provide good food withdankook.review.eatingalong.positive.2=Keep appointments well withdankook.review.eatingalong.positive.3=Choose menu items well @@ -63,13 +67,13 @@ withdankook.review.beareats.negative.3=Frequently changes the delivery location withdankook.review.beareats.negative.4=Unkind withdankook.review.beareats.negative.5=Does not settle the bill on time -withdankook.review.dormitory.positive.1=Follow the rules well -withdankook.review.dormitory.positive.2=Kind -withdankook.review.dormitory.positive.3=Good communication -withdankook.review.dormitory.positive.4=Respectful of others -withdankook.review.dormitory.positive.5=Matches the stated conditions -withdankook.review.dormitory.negative.1=Do not follow the rules well -withdankook.review.dormitory.negative.2=Unkind -withdankook.review.dormitory.negative.3=Frequently face difficulties in communication -withdankook.review.dormitory.negative.4=Do not respect others -withdankook.review.dormitory.negative.5=Different from the stated conditions +withdankook.review.roommate.positive.1=Follow the rules well +withdankook.review.roommate.positive.2=Kind +withdankook.review.roommate.positive.3=Good communication +withdankook.review.roommate.positive.4=Respectful of others +withdankook.review.roommate.positive.5=Matches the stated conditions +withdankook.review.roommate.negative.1=Do not follow the rules well +withdankook.review.roommate.negative.2=Unkind +withdankook.review.roommate.negative.3=Frequently face difficulties in communication +withdankook.review.roommate.negative.4=Do not respect others +withdankook.review.roommate.negative.5=Different from the stated conditions From 0154e8cda1188e02af9c5ea1c5c24787b55fb03d Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Thu, 4 Jan 2024 19:43:15 +0900 Subject: [PATCH 20/20] =?UTF-8?q?feat:=20=EA=B5=AC=ED=95=B4=EC=A4=98!=20?= =?UTF-8?q?=EB=A3=B8=EB=A9=94=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RoommateController.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/with_dankook/controller/RoommateController.java diff --git a/src/main/java/com/dku/council/domain/with_dankook/controller/RoommateController.java b/src/main/java/com/dku/council/domain/with_dankook/controller/RoommateController.java new file mode 100644 index 00000000..9119f806 --- /dev/null +++ b/src/main/java/com/dku/council/domain/with_dankook/controller/RoommateController.java @@ -0,0 +1,139 @@ +package com.dku.council.domain.with_dankook.controller; + +import com.dku.council.domain.post.model.dto.response.ResponsePage; +import com.dku.council.domain.with_dankook.model.dto.list.SummarizedRoommateDto; +import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateRoommateDto; +import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateSurveyDto; +import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleRoommateDto; +import com.dku.council.domain.with_dankook.service.RoommateService; +import com.dku.council.domain.with_dankook.service.SurveyService; +import com.dku.council.global.auth.jwt.AppAuthentication; +import com.dku.council.global.auth.role.UserAuth; +import com.dku.council.global.model.dto.ResponseBooleanDto; +import com.dku.council.global.model.dto.ResponseIdDto; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springdoc.api.annotations.ParameterObject; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +@RestController +@Tag(name = "구해줘! 룸메", description = "구해줘! 룸메 관련 API") +@RequiredArgsConstructor +@RequestMapping("with-dankook/roommate") +public class RoommateController { + + private final RoommateService roommateService; + private final SurveyService surveyService; + + /** + * 구해줘! 룸메 설문조사 작성 + *

SleepTime: AVG_TEN, AVG_ELEVEN, AVG_TWELVE, AVG_ONE, AVG_TWO, AVG_TWO_AFTER, ETC

+ *

CleanUpCount : ONCE_UNDER_WEEK, TWICE_WEEK, TWICE_OVER_WEEK, ONCE_MONTH

+ *

noiseHabit이 true 일 때는, noiseHabitDetail을 필수로 작성해야 한다.

+ * + * @param dto 룸메 설문조사 dto + * @return 설문조사 id + */ + @PostMapping("/create/survey") + @UserAuth + public ResponseIdDto createSurvey(AppAuthentication auth, + @RequestBody @Valid RequestCreateSurveyDto dto) { + Long result = surveyService.createSurvey(auth.getUserId(), dto); + return new ResponseIdDto(result); + } + + /** + * 구해줘! 룸메 게시글 작성 + *

ResidenceDuration : SEMESTER , HALF_YEAR, YEAR

+ */ + @PostMapping + @UserAuth + public ResponseIdDto create(AppAuthentication auth, + @RequestBody @Valid RequestCreateRoommateDto dto) { + Long result = roommateService.create(auth.getUserId(), dto); + return new ResponseIdDto(result); + } + + /** + * 구해줘! 룸메 게시글 목록 조회 + * + * @param bodySize 게시글 본문 길이. (글자 단위) 지정하지 않으면 50 글자. + * @param pageable 페이징 size, sort, page + * @return 페이징된 게시판 목록 + */ + @GetMapping + @UserAuth + public ResponsePage list(AppAuthentication auth, + @RequestParam(defaultValue = "50") int bodySize, + @ParameterObject Pageable pageable) { + Page list = roommateService.list(auth.getUserId(), pageable, bodySize); + return new ResponsePage<>(list); + } + + /** + * 구해줘! 룸메 게시글 상세 조회 + * + * @param id 게시글 id + */ + @GetMapping("/{id}") + @UserAuth + public ResponseSingleRoommateDto findOne(AppAuthentication auth, + @PathVariable Long id) { + return roommateService.findOne(id, auth.getUserId(), auth.getUserRole()); + } + + /** + * 구해줘! 룸메 게시글 신청 + *

게시글에 신청할 경우 바로 신청되는 것이 아닌 대기중으로 설정됩니다.

+ * + * @param id 게시글 id + */ + @PostMapping("/apply/{id}") + @UserAuth + public void apply(AppAuthentication auth, + @Valid @PathVariable Long id) { + roommateService.apply(auth.getUserId(), id, auth.getUserRole()); + } + + /** + * 구해줘! 룸메 게시글 승인 + *

게시글 작성자가 신청자 id로 승인합니다.

+ * + * @param id 게시글 id + * @param targetUserId 승인할 사용자 id + */ + @PatchMapping("/approve/{id}") + @UserAuth + public void approve(AppAuthentication auth, + @Valid @PathVariable Long id, + Long targetUserId) { + roommateService.approve(auth.getUserId(), id, targetUserId); + } + + /** + * 구해줘! 룸메 게시글 삭제 + * + * @param roommateId 게시글 id + */ + @DeleteMapping + @UserAuth + public void delete(AppAuthentication auth, + @Valid @RequestParam Long roommateId) { + roommateService.delete(auth.getUserId(), auth.isAdmin(), roommateId); + } + + /** + * 구해줘! 룸메 설문조사 작성 여부 확인 + *

설문조사를 하지 않았을 때는 설문조사를 먼저 받아야하며, 설문조사가 꼭 있어야만 다른 기능 사용이 가능하다.

+ */ + @GetMapping("/survey") + @UserAuth + public ResponseBooleanDto isSurveyExist(AppAuthentication auth) { + boolean result = surveyService.checkSurvey(auth.getUserId()); + return new ResponseBooleanDto(result); + } +}