-
Notifications
You must be signed in to change notification settings - Fork 3
[feat] 홍보게시판 API 구현 #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[feat] 홍보게시판 API 구현 #1125
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/moadong/club/controller/PromotionArticleController.java
This file contains hidden or 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,44 @@ | ||
| package moadong.club.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import moadong.club.payload.request.PromotionArticleCreateRequest; | ||
| import moadong.club.payload.response.PromotionArticleResponse; | ||
| import moadong.club.service.PromotionArticleService; | ||
| import moadong.global.payload.Response; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/promotion") | ||
| @RequiredArgsConstructor | ||
| @Tag(name = "Promotion", description = "홍보게시판 API") | ||
| public class PromotionArticleController { | ||
|
|
||
| private final PromotionArticleService promotionArticleService; | ||
|
|
||
| @GetMapping | ||
| @Operation(summary = "홍보 게시글 목록 조회", description = "전체 홍보 게시글 목록을 조회합니다.") | ||
| public ResponseEntity<?> getPromotionArticles() { | ||
| PromotionArticleResponse response = promotionArticleService.getPromotionArticles(); | ||
| return Response.ok(response); | ||
| } | ||
|
|
||
| @PostMapping | ||
| @Operation(summary = "홍보 게시글 생성", description = "새로운 홍보 게시글을 생성합니다.") | ||
| @PreAuthorize("isAuthenticated()") | ||
| @SecurityRequirement(name = "BearerAuth") | ||
| public ResponseEntity<?> createPromotionArticle( | ||
| @RequestBody @Validated PromotionArticleCreateRequest request) { | ||
| promotionArticleService.createPromotionArticle(request); | ||
| return Response.ok("홍보 게시글이 생성되었습니다."); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/moadong/club/entity/PromotionArticle.java
This file contains hidden or 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,41 @@ | ||
| package moadong.club.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.springframework.data.annotation.Id; | ||
| import org.springframework.data.mongodb.core.mapping.Document; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| @Document("promotion_articles") | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class PromotionArticle { | ||
|
|
||
| @Id | ||
| private String id; | ||
|
|
||
| private String clubId; | ||
|
|
||
| private String clubName; | ||
|
|
||
| private String title; | ||
|
|
||
| private String location; | ||
|
|
||
| private Instant eventStartDate; | ||
|
|
||
| private Instant eventEndDate; | ||
|
|
||
| private String description; | ||
|
|
||
| private List<String> images; | ||
|
|
||
| @Builder.Default | ||
| private Instant createdAt = Instant.now(); | ||
| } |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/moadong/club/payload/dto/PromotionArticleDto.java
This file contains hidden or 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,16 @@ | ||
| package moadong.club.payload.dto; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| public record PromotionArticleDto( | ||
| String clubName, | ||
| String clubId, | ||
| String title, | ||
| String location, | ||
| Instant eventStartDate, | ||
| Instant eventEndDate, | ||
| String description, | ||
| List<String> images | ||
| ) { | ||
| } |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/moadong/club/payload/request/PromotionArticleCreateRequest.java
This file contains hidden or 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,19 @@ | ||
| package moadong.club.payload.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotEmpty; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| public record PromotionArticleCreateRequest( | ||
| @NotBlank String clubId, | ||
| @NotBlank String title, | ||
| String location, | ||
| @NotNull Instant eventStartDate, | ||
| @NotNull Instant eventEndDate, | ||
| @NotBlank String description, | ||
| @NotEmpty List<String> images | ||
| ) { | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/moadong/club/payload/response/PromotionArticleResponse.java
This file contains hidden or 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,10 @@ | ||
| package moadong.club.payload.response; | ||
|
|
||
| import moadong.club.payload.dto.PromotionArticleDto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record PromotionArticleResponse( | ||
| List<PromotionArticleDto> articles | ||
| ) { | ||
| } |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/moadong/club/repository/PromotionArticleRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package moadong.club.repository; | ||
|
|
||
| import moadong.club.entity.PromotionArticle; | ||
| import moadong.club.payload.dto.PromotionArticleDto; | ||
| import org.springframework.data.mongodb.repository.MongoRepository; | ||
| import org.springframework.data.mongodb.repository.Query; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface PromotionArticleRepository extends MongoRepository<PromotionArticle, String> { | ||
|
|
||
| @Query(value = "{}", sort = "{ 'createdAt': -1 }") | ||
| List<PromotionArticleDto> findAllProjectedBy(); | ||
|
|
||
| List<PromotionArticle> findByClubIdOrderByCreatedAtDesc(String clubId); | ||
lepitaaar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
51 changes: 51 additions & 0 deletions
51
backend/src/main/java/moadong/club/service/PromotionArticleService.java
This file contains hidden or 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,51 @@ | ||
| package moadong.club.service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import moadong.club.entity.Club; | ||
| import moadong.club.entity.PromotionArticle; | ||
| import moadong.club.payload.dto.PromotionArticleDto; | ||
| import moadong.club.payload.request.PromotionArticleCreateRequest; | ||
| import moadong.club.payload.response.PromotionArticleResponse; | ||
| import moadong.club.repository.ClubRepository; | ||
| import moadong.club.repository.PromotionArticleRepository; | ||
| import moadong.global.exception.ErrorCode; | ||
| import moadong.global.exception.RestApiException; | ||
| import moadong.global.util.ObjectIdConverter; | ||
| import org.bson.types.ObjectId; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PromotionArticleService { | ||
|
|
||
| private final PromotionArticleRepository promotionArticleRepository; | ||
| private final ClubRepository clubRepository; | ||
|
|
||
| public PromotionArticleResponse getPromotionArticles() { | ||
| List<PromotionArticleDto> articles = promotionArticleRepository.findAllProjectedBy(); | ||
| return new PromotionArticleResponse(articles); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void createPromotionArticle(PromotionArticleCreateRequest request) { | ||
| ObjectId clubObjectId = ObjectIdConverter.convertString(request.clubId()); | ||
| Club club = clubRepository.findClubById(clubObjectId) | ||
| .orElseThrow(() -> new RestApiException(ErrorCode.CLUB_NOT_FOUND)); | ||
lepitaaar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| PromotionArticle article = PromotionArticle.builder() | ||
| .clubId(request.clubId()) | ||
| .clubName(club.getName()) | ||
| .title(request.title()) | ||
| .location(request.location()) | ||
| .eventStartDate(request.eventStartDate()) | ||
| .eventEndDate(request.eventEndDate()) | ||
| .description(request.description()) | ||
| .images(request.images()) | ||
| .build(); | ||
|
|
||
| promotionArticleRepository.save(article); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.