-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 소식지 서비스 구현 #353
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
Gyuhyeok99
merged 23 commits into
solid-connection:develop
from
Gyuhyeok99:feat/300-news-api-v2
Jul 2, 2025
Merged
feat: 소식지 서비스 구현 #353
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
583f7e7
feat: News에 siteUserId FK 추가
Gyuhyeok99 aef7987
refactor: 권한 검사 로직을 역할 기반으로 유연하게 개선
Gyuhyeok99 5563ef9
feat: 소식지 생성 api 추가
Gyuhyeok99 e002fcc
test: 소식지 생성 테스트 추가
Gyuhyeok99 a968baf
feat: 소식지 수정 api 추가
Gyuhyeok99 9b246fb
feat: 소식지 삭제 api 추가
Gyuhyeok99 1e8461f
feat: 특정 유저의 소식지 목록 조회 api 추가
Gyuhyeok99 4eaf083
style: news_id에서 news-id로 변경
Gyuhyeok99 37a0bb9
style: 테스트 클래스에서 불필요한 public 제거
Gyuhyeok99 627c691
refactor: @JsonProperty 제거
Gyuhyeok99 7d92804
refactor: defaultThumbnailUrl application-varaible.yml에서 가져오도록 변경
Gyuhyeok99 df0253a
refactor: RequireRoleAccess 어노테이션 roles 기본값 제거
Gyuhyeok99 954ef78
refactor: 권한 체크 로직 contains로 단순화하여 final 제거
Gyuhyeok99 8214db7
test: 권한별 나열식 테스트 제거, 요구 역할 유무에 따른 핵심 시나리오 중심으로 개선
Gyuhyeok99 18a9121
refactor: 소식지 수정 PATCH -> PUT으로 변경
Gyuhyeok99 389f3ee
test: 테스트 메서드명을 멘토 → 사용자로 일반화
Gyuhyeok99 36be2ab
style: NewsRepository 메서드 선언 개행 및 파라미터 타입 Long → long 변경
Gyuhyeok99 b275ede
refactor: 단일/목록 응답 클래스 네이밍 통일
Gyuhyeok99 a425050
chore: 서브모듈 커밋 반영
Gyuhyeok99 cb77894
refactor: siteUserId 타입을 Long에서 long으로 통일
Gyuhyeok99 cef3ff5
test: assertAll로 테스트 그룹화
Gyuhyeok99 a170b6b
refactor: private 메서드 위치를 호출부 아래로 이동
Gyuhyeok99 5eb35a7
chore: 서브모듈 커밋 반영
Gyuhyeok99 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
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
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/solidconnection/news/config/NewsProperties.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,9 @@ | ||
| package com.example.solidconnection.news.config; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| @ConfigurationProperties(prefix = "news") | ||
| public record NewsProperties( | ||
| String defaultThumbnailUrl | ||
| ) { | ||
| } |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/example/solidconnection/news/controller/NewsController.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,80 @@ | ||
| package com.example.solidconnection.news.controller; | ||
|
|
||
| import com.example.solidconnection.common.resolver.AuthorizedUser; | ||
| import com.example.solidconnection.news.dto.NewsCommandResponse; | ||
| import com.example.solidconnection.news.dto.NewsCreateRequest; | ||
| import com.example.solidconnection.news.dto.NewsListResponse; | ||
| import com.example.solidconnection.news.dto.NewsUpdateRequest; | ||
| import com.example.solidconnection.news.service.NewsCommandService; | ||
| import com.example.solidconnection.news.service.NewsQueryService; | ||
| import com.example.solidconnection.security.annotation.RequireRoleAccess; | ||
| import com.example.solidconnection.siteuser.domain.Role; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RequestPart; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/news") | ||
| public class NewsController { | ||
|
|
||
| private final NewsQueryService newsQueryService; | ||
| private final NewsCommandService newsCommandService; | ||
|
|
||
| // todo: 추후 Slice 적용 | ||
| @GetMapping | ||
| public ResponseEntity<NewsListResponse> findNewsBySiteUserId( | ||
| @RequestParam(value = "site-user-id") Long siteUserId | ||
| ) { | ||
| NewsListResponse newsListResponse = newsQueryService.findNewsBySiteUserId(siteUserId); | ||
| return ResponseEntity.ok(newsListResponse); | ||
| } | ||
|
|
||
| @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) | ||
| @PostMapping | ||
| public ResponseEntity<NewsCommandResponse> createNews( | ||
| @AuthorizedUser SiteUser siteUser, | ||
| @Valid @RequestPart("newsCreateRequest") NewsCreateRequest newsCreateRequest, | ||
| @RequestParam(value = "file", required = false) MultipartFile imageFile | ||
| ) { | ||
| NewsCommandResponse newsCommandResponse = newsCommandService.createNews(siteUser.getId(), newsCreateRequest, imageFile); | ||
| return ResponseEntity.ok(newsCommandResponse); | ||
| } | ||
|
|
||
| @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) | ||
| @PutMapping("/{news-id}") | ||
| public ResponseEntity<NewsCommandResponse> updateNews( | ||
| @AuthorizedUser SiteUser siteUser, | ||
| @PathVariable("news-id") Long newsId, | ||
| @Valid @RequestPart(value = "newsUpdateRequest") NewsUpdateRequest newsUpdateRequest, | ||
| @RequestParam(value = "file", required = false) MultipartFile imageFile | ||
| ) { | ||
| NewsCommandResponse newsCommandResponse = newsCommandService.updateNews( | ||
| siteUser.getId(), | ||
| newsId, | ||
| newsUpdateRequest, | ||
| imageFile); | ||
| return ResponseEntity.ok(newsCommandResponse); | ||
| } | ||
|
|
||
| @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) | ||
| @DeleteMapping("/{news-id}") | ||
| public ResponseEntity<NewsCommandResponse> deleteNewsById( | ||
| @AuthorizedUser SiteUser siteUser, | ||
| @PathVariable("news-id") Long newsId | ||
| ) { | ||
| NewsCommandResponse newsCommandResponse = newsCommandService.deleteNewsById(siteUser, newsId); | ||
| return ResponseEntity.ok(newsCommandResponse); | ||
| } | ||
| } |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/solidconnection/news/dto/NewsCommandResponse.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,13 @@ | ||
| package com.example.solidconnection.news.dto; | ||
|
|
||
| import com.example.solidconnection.news.domain.News; | ||
|
|
||
| public record NewsCommandResponse( | ||
| long id | ||
| ) { | ||
| public static NewsCommandResponse from(News news) { | ||
| return new NewsCommandResponse( | ||
| news.getId() | ||
| ); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/example/solidconnection/news/dto/NewsCreateRequest.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,31 @@ | ||
| package com.example.solidconnection.news.dto; | ||
|
|
||
| import com.example.solidconnection.news.domain.News; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
| import org.hibernate.validator.constraints.URL; | ||
|
|
||
| public record NewsCreateRequest( | ||
| @NotBlank(message = "소식지 제목을 입력해주세요.") | ||
| @Size(max = 20, message = "소식지 제목은 20자 이하여야 합니다.") | ||
| String title, | ||
|
|
||
| @NotBlank(message = "소식지 내용을 입력해주세요.") | ||
| @Size(max = 30, message = "소식지 내용은 30자 이하여야 합니다.") | ||
| String description, | ||
|
|
||
| @NotBlank(message = "소식지 URL을 입력해주세요.") | ||
| @Size(max = 500, message = "소식지 URL은 500자 이하여야 합니다.") | ||
| @URL(message = "올바른 URL 형식이 아닙니다.") | ||
| String url | ||
| ) { | ||
| public News toEntity(String thumbnailUrl, long siteUserId) { | ||
| return new News( | ||
| title, | ||
| description, | ||
| thumbnailUrl, | ||
| url, | ||
| siteUserId | ||
| ); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/solidconnection/news/dto/NewsListResponse.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,11 @@ | ||
| package com.example.solidconnection.news.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record NewsListResponse( | ||
| List<NewsResponse> newsResponseList | ||
| ) { | ||
| public static NewsListResponse from(List<NewsResponse> newsResponseList) { | ||
| return new NewsListResponse(newsResponseList); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/solidconnection/news/dto/NewsResponse.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,25 @@ | ||
| package com.example.solidconnection.news.dto; | ||
|
|
||
| import com.example.solidconnection.news.domain.News; | ||
|
|
||
| import java.time.ZonedDateTime; | ||
|
|
||
| public record NewsResponse( | ||
| long id, | ||
| String title, | ||
| String description, | ||
| String thumbnailUrl, | ||
| String url, | ||
| ZonedDateTime updatedAt | ||
| ) { | ||
| public static NewsResponse from(News news) { | ||
| return new NewsResponse( | ||
| news.getId(), | ||
| news.getTitle(), | ||
| news.getDescription(), | ||
| news.getThumbnailUrl(), | ||
| news.getUrl(), | ||
| news.getUpdatedAt() | ||
| ); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/solidconnection/news/dto/NewsUpdateRequest.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,23 @@ | ||
| package com.example.solidconnection.news.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
| import org.hibernate.validator.constraints.URL; | ||
|
|
||
| public record NewsUpdateRequest( | ||
| @NotBlank(message = "소식지 제목을 입력해주세요.") | ||
| @Size(max = 20, message = "소식지 제목은 20자 이하여야 합니다.") | ||
| String title, | ||
|
|
||
| @NotBlank(message = "소식지 내용을 입력해주세요.") | ||
| @Size(max = 30, message = "소식지 내용은 30자 이하여야 합니다.") | ||
| String description, | ||
|
|
||
| @NotBlank(message = "소식지 URL을 입력해주세요.") | ||
| @Size(max = 500, message = "소식지 URL은 500자 이하여야 합니다.") | ||
| @URL(message = "올바른 URL 형식이 아닙니다.") | ||
| String url, | ||
|
|
||
| Boolean resetToDefaultImage | ||
| ) { | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/solidconnection/news/repository/NewsRepository.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,11 @@ | ||
| package com.example.solidconnection.news.repository; | ||
|
|
||
| import com.example.solidconnection.news.domain.News; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface NewsRepository extends JpaRepository<News, Long> { | ||
|
|
||
| List<News> findAllBySiteUserIdOrderByUpdatedAtDesc(long siteUserId); | ||
| } |
Oops, something went wrong.
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.