forked from EveryUniv/next-student-council-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from gutanbug/feat/beareats
feat: BearEats 게시판 기능 추가
- Loading branch information
Showing
13 changed files
with
405 additions
and
18 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
src/main/java/com/dku/council/domain/with_dankook/controller/BearEatsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
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.SummarizedBearEatsDto; | ||
import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateBearEatsDto; | ||
import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleBearEatsDto; | ||
import com.dku.council.domain.with_dankook.service.BearEatsService; | ||
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; | ||
|
||
@Tag(name = "BearEats", description = "단국 BearEats 게시판") | ||
@RestController | ||
@RequestMapping("with-dankook/bear-eats") | ||
@RequiredArgsConstructor | ||
public class BearEatsController { | ||
|
||
private final BearEatsService bearEatsService; | ||
|
||
/** | ||
* BearEats 게시글 목록 조회 | ||
* | ||
* @param bodySize 게시글 본문 길이. (글자 단위) 지정하지 않으면 50 글자. | ||
* @param pageable 페이징 size, sort, page | ||
* @return 페이징된 BearEats 게시판 목록 | ||
*/ | ||
@GetMapping | ||
public ResponsePage<SummarizedBearEatsDto> list(@RequestParam(defaultValue = "50") int bodySize, | ||
@ParameterObject Pageable pageable) { | ||
Page<SummarizedBearEatsDto> list = bearEatsService.list(pageable, bodySize); | ||
return new ResponsePage<>(list); | ||
} | ||
|
||
/** | ||
* 내가 쓴 BearEats 게시글 목록 조회 | ||
* | ||
* @param pageable 페이징 size, sort, page | ||
* @return 페이징된 내가 쓴 BearEats 게시판 목록 | ||
*/ | ||
@GetMapping("/my") | ||
@UserAuth | ||
public ResponsePage<SummarizedBearEatsDto> listMyPots(AppAuthentication auth, | ||
@ParameterObject Pageable pageable) { | ||
Page<SummarizedBearEatsDto> list = bearEatsService.listMyPosts(auth.getUserId(), pageable); | ||
return new ResponsePage<>(list); | ||
} | ||
|
||
/** | ||
* BearEats 게시글 상세 조회 | ||
* | ||
* @param id 게시글 id | ||
*/ | ||
@GetMapping("/{id}") | ||
@UserAuth | ||
public ResponseSingleBearEatsDto findOne(AppAuthentication auth, | ||
@PathVariable Long id) { | ||
return bearEatsService.findOne(id, auth.getUserId(), auth.getUserRole()); | ||
} | ||
|
||
/** | ||
* BearEats 게시글 작성 | ||
*/ | ||
@PostMapping | ||
@UserAuth | ||
public ResponseIdDto create(AppAuthentication auth, | ||
@Valid @RequestBody RequestCreateBearEatsDto dto) { | ||
Long id = bearEatsService.create(auth.getUserId(), dto); | ||
return new ResponseIdDto(id); | ||
} | ||
|
||
/** | ||
* BearEats 게시글 신청 | ||
* | ||
* @param id 게시글 id | ||
*/ | ||
@PostMapping("/{id}/enter") | ||
@UserAuth | ||
public void enter(AppAuthentication auth, @PathVariable @Valid Long id) { | ||
bearEatsService.enter(id, auth.getUserId(), auth.getUserRole()); | ||
} | ||
|
||
/** | ||
* BearEats 게시글 삭제 | ||
* | ||
* @param id 게시글 id | ||
*/ | ||
@DeleteMapping("/{id}") | ||
@UserAuth | ||
public void delete(AppAuthentication auth, | ||
@PathVariable Long id) { | ||
bearEatsService.delete(id, auth.getUserId(), auth.isAdmin()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedBearEatsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.dku.council.domain.with_dankook.model.dto.list; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.type.BearEats; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class SummarizedBearEatsDto extends SummarizedWithDankookDto { | ||
|
||
@Schema(description = "식당 이름", example = "피자헛") | ||
private final String restaurant; | ||
|
||
@Schema(description = "배달 주문 장소", example = "피자헛") | ||
private final String deliveryPlace; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm") | ||
@Schema(description = "배달 시간", example = "2021-01-01T12:00") | ||
private final LocalDateTime deliveryTime; | ||
|
||
@Schema(description = "내용", example = "피자헛에서 피자를 시켜먹을 사람을 구합니다.") | ||
private final String content; | ||
|
||
@Schema(description = "모집된 인원", example = "1") | ||
private final int recruitedCount; | ||
|
||
public SummarizedBearEatsDto(SummarizedWithDankookDto dto, BearEats bearEats, int recruitedCount) { | ||
super(dto); | ||
this.restaurant = bearEats.getRestaurant(); | ||
this.deliveryPlace = bearEats.getDeliveryPlace(); | ||
this.deliveryTime = bearEats.getDeliveryTime(); | ||
this.content = bearEats.getContent(); | ||
this.recruitedCount = recruitedCount; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
.../java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateBearEatsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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.type.BearEats; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class RequestCreateBearEatsDto extends RequestCreateWithDankookDto<BearEats>{ | ||
|
||
@NotNull | ||
@Schema(description = "음식점", example = "피자헛") | ||
private String restaurant; | ||
|
||
@NotNull | ||
@Schema(description = "배달 주문 장소", example = "피자헛") | ||
private String deliveryPlace; | ||
|
||
@NotNull | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:MM") | ||
@Schema(description = "배달 시간", example = "2023-12-25 17:30") | ||
private LocalDateTime deliveryTime; | ||
|
||
@NotBlank | ||
@Schema(description = "본문", example = "내용") | ||
private String content; | ||
|
||
public RequestCreateBearEatsDto(@NotNull String restaurant, | ||
@NotNull String deliveryPlace, | ||
@NotNull LocalDateTime deliveryTime, | ||
@NotBlank String content) { | ||
this.restaurant = restaurant; | ||
this.deliveryPlace = deliveryPlace; | ||
this.deliveryTime = deliveryTime; | ||
this.content = content; | ||
} | ||
|
||
@Override | ||
public BearEats toEntity(User user) { | ||
return BearEats.builder() | ||
.user(user) | ||
.restaurant(restaurant) | ||
.deliveryPlace(deliveryPlace) | ||
.deliveryTime(deliveryTime) | ||
.content(content) | ||
.build(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ava/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleBearEatsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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.BearEats; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class ResponseSingleBearEatsDto extends ResponseSingleWithDankookDto { | ||
|
||
@Schema(description = "식당 이름", example = "피자헛") | ||
private final String restaurant; | ||
|
||
@Schema(description = "배달 주문 장소", example = "피자헛") | ||
private final String deliveryPlace; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm") | ||
@Schema(description = "배달 시간", example = "2021-01-01 12:00") | ||
private final String deliveryTime; | ||
|
||
@Schema(description = "내용", example = "피자헛에서 피자를 시켜먹을 사람을 구합니다.") | ||
private final String content; | ||
|
||
@Schema(description = "모집된 인원", example = "1") | ||
private final int recruitedCount; | ||
|
||
@Schema(description = "모집된 사용자들") | ||
private final List<RecruitedUsersDto> recruitedUsers; | ||
|
||
public ResponseSingleBearEatsDto(ResponseSingleWithDankookDto dto, BearEats bearEats, int recruitedCount) { | ||
super(dto); | ||
this.restaurant = bearEats.getRestaurant(); | ||
this.deliveryPlace = bearEats.getDeliveryPlace(); | ||
this.deliveryTime = bearEats.getDeliveryTime().toString(); | ||
this.content = bearEats.getContent(); | ||
this.recruitedCount = recruitedCount; | ||
this.recruitedUsers = bearEats.getUsers().stream() | ||
.map(RecruitedUsersDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/dku/council/domain/with_dankook/repository/BearEatsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.dku.council.domain.with_dankook.repository; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.type.BearEats; | ||
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 BearEatsRepository extends WithDankookRepository<BearEats>{ | ||
|
||
@Query("select b from BearEats b where b.masterUser.id = :userId and " + | ||
"(b.withDankookStatus='ACTIVE' or b.withDankookStatus='CLOSED') ") | ||
Page<BearEats> findAllBearEatsByUserId(@Param("userId") Long userId, Pageable pageable); | ||
} |
10 changes: 6 additions & 4 deletions
10
src/main/java/com/dku/council/domain/with_dankook/repository/StudyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package com.dku.council.domain.with_dankook.repository; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.type.Study; | ||
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 java.util.List; | ||
|
||
public interface StudyRepository extends WithDankookRepository<Study>{ | ||
@Query("select s from Study s " + | ||
"join fetch s.tag " + | ||
"where s.tag.name = :name ") | ||
List<Study> findAllByStudyTagName(@Param("name") String name); | ||
|
||
@Query("select s from Study s where s.masterUser.id = :userId and " + | ||
"(s.withDankookStatus='ACTIVE' or s.withDankookStatus='CLOSED') ") | ||
Page<Study> findAllStudyByUserId(@Param("userId") Long userId, Pageable pageable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.