Skip to content
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

[BE] dev 서버에 배포한다. #669

Merged
merged 30 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b4e1e0d
feat(RoomService): 방 삭제 구현
shin-jisong Sep 23, 2024
b649c0a
feat(ChecklistQuestionService): 질문 삭제 구현
shin-jisong Sep 23, 2024
dd03406
feat(ChecklistQuestionRepository): long을 Long으로 변경
shin-jisong Sep 23, 2024
e4a46ee
feat(ChecklistOptionSevice): 옵션 삭제 구현
shin-jisong Sep 23, 2024
1f80ee2
feat(ChecklistMaintenanceService): 관리비 포함 항목 삭제 구현
shin-jisong Sep 23, 2024
f98f34c
feat(ChecklistManageService): 체크리스트 삭제 구현
shin-jisong Sep 23, 2024
50dc5a7
feat(ChecklistService): 체크리스트 삭제 구현
shin-jisong Sep 23, 2024
4621174
feat(ChecklistController): 체크리스트 삭제 manageService 사용하도록 구현
shin-jisong Sep 23, 2024
0458acd
style: 코드 재정렬
shin-jisong Sep 23, 2024
f6e2e3b
Merge remote-tracking branch 'refs/remotes/origin/dev-be' into refact…
shin-jisong Sep 24, 2024
7d4ff37
[BE] 로그인하지 않은 사용자도 특정 페이지에 접근할 수 있도록 권한을 허용한다. (#625)
JINU-CHANG Sep 24, 2024
edbd1cb
refactor: 체크리스트 조회시 좋아요 여부 전달하도록 수정
JINU-CHANG Sep 24, 2024
82a2f82
style: 공백 제거
shin-jisong Sep 25, 2024
672f628
feat: long을 Long으로 변경
shin-jisong Sep 25, 2024
d5d3f18
style: 사용 안 하는 메서드 삭제
shin-jisong Sep 25, 2024
243ca13
Merge branch 'dev-be' into refactor/632-delete-checklist
shin-jisong Sep 25, 2024
2bd460c
fix: 빌드 오류 해결
shin-jisong Sep 25, 2024
e7ab611
[BE] 체크리스트 수정 API를 리팩토링한다. (#631)
shin-jisong Sep 25, 2024
aa195fb
Merge remote-tracking branch 'origin/dev' into dev-be
JINU-CHANG Sep 25, 2024
3583ebb
fix: dev 브랜치와 머지 충돌 해결
JINU-CHANG Sep 25, 2024
67d985a
remove: 아티클 카드뷰 기능 제거
tsulocalize Sep 25, 2024
b619dca
refactor: 아티클 목록 api 엔드포인트 수정
tsulocalize Sep 25, 2024
036667a
refactor: 아티클 리스트뷰 명칭 수정
tsulocalize Sep 25, 2024
e8e40f3
Merge remote-tracking branch 'refs/remotes/origin/dev-be' into refact…
shin-jisong Sep 25, 2024
2525129
fix: 머지 충돌 해결
shin-jisong Sep 25, 2024
03c4196
[BE] 아티클 응답을 수정한다. (#666)
shin-jisong Sep 25, 2024
6cd37e4
[BE] 체크리스트 삭제 API를 리팩토링한다. (#640)
shin-jisong Sep 25, 2024
2a1ee26
[BE] 체크리스트 조회시 좋아요 여부를 전달하도록 수정한다. (#653)
shin-jisong Sep 25, 2024
b1554d1
[BE] 지하철 데이터를 업데이트한다 (#662)
tsulocalize Sep 25, 2024
4c1b105
dev 충돌 해결
tsulocalize Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.bang_ggood.article.dto.request.ArticleCreateRequest;
import com.bang_ggood.article.dto.response.ArticleResponse;
import com.bang_ggood.article.dto.response.ArticlesListViewResponse;
import com.bang_ggood.article.dto.response.ArticlesCardViewResponse;
import com.bang_ggood.article.dto.response.ArticlesResponses;
import com.bang_ggood.article.service.ArticleService;
import com.bang_ggood.auth.config.AuthRequiredPrincipal;
import com.bang_ggood.user.domain.User;
Expand Down Expand Up @@ -38,14 +37,9 @@ public ResponseEntity<ArticleResponse> readArticle(@PathVariable("id") Long id)
return ResponseEntity.ok(articleService.readArticle(id));
}

@GetMapping("/articles/card")
public ResponseEntity<ArticlesCardViewResponse> readArticlesCardView() {
return ResponseEntity.ok(articleService.readArticlesCardView());
}

@GetMapping("/articles/list")
public ResponseEntity<ArticlesListViewResponse> readArticlesListView() {
return ResponseEntity.ok(articleService.readArticlesListView());
@GetMapping("/articles")
public ResponseEntity<ArticlesResponses> readArticles() {
return ResponseEntity.ok(articleService.readArticles());
}

@DeleteMapping("/articles/{id}")
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.LocalDateTime;

public record ArticleResponse(Long articleId, String title, String content, String keyword, String summary,
LocalDateTime createdAt) {
String thumbnail, LocalDateTime createdAt) {

public static ArticleResponse from(Article article) {
return new ArticleResponse(
Expand All @@ -13,6 +13,7 @@ public static ArticleResponse from(Article article) {
article.getContent(),
article.getKeyword(),
article.getSummary(),
article.getThumbnail(),
article.getCreatedAt()
);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bang_ggood.article.dto.response;

import com.bang_ggood.article.domain.Article;
import java.time.LocalDateTime;

public record ArticlesResponse(Long articleId, String title, String keyword, String summary,
LocalDateTime createdAt) {

public static ArticlesResponse from(Article article) {
return new ArticlesResponse(
article.getId(),
article.getTitle(),
article.getKeyword(),
article.getSummary(),
article.getCreatedAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bang_ggood.article.dto.response;

import java.util.List;

public record ArticlesResponses(List<ArticlesResponse> articles) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ default Article getById(Long id) {
"ORDER BY a.createdAt DESC ")
List<Article> findLatestArticles();

@Query("SELECT a FROM Article a " +
"WHERE a.deleted = false " +
"ORDER BY a.createdAt DESC " +
"LIMIT :count")
List<Article> findLatestArticles(@Param("count") int count);

@Modifying(flushAutomatically = true, clearAutomatically = true)
@Query("UPDATE Article a " +
"SET a.deleted = true " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.bang_ggood.article.domain.Article;
import com.bang_ggood.article.dto.request.ArticleCreateRequest;
import com.bang_ggood.article.dto.response.ArticleListViewResponse;
import com.bang_ggood.article.dto.response.ArticleCardViewResponse;
import com.bang_ggood.article.dto.response.ArticlesResponse;
import com.bang_ggood.article.dto.response.ArticleResponse;
import com.bang_ggood.article.dto.response.ArticlesListViewResponse;
import com.bang_ggood.article.dto.response.ArticlesCardViewResponse;
import com.bang_ggood.article.dto.response.ArticlesResponses;
import com.bang_ggood.article.repository.ArticleRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -15,7 +13,6 @@
@Service
public class ArticleService {

private static final int MAX_ARTICLE_CARDS = 3;
private final ArticleRepository articleRepository;

public ArticleService(ArticleRepository articleRepository) {
Expand All @@ -36,19 +33,11 @@ public ArticleResponse readArticle(Long id) {
}

@Transactional(readOnly = true)
public ArticlesListViewResponse readArticlesListView() {
List<ArticleListViewResponse> articles = articleRepository.findLatestArticles().stream()
.map(ArticleListViewResponse::from)
public ArticlesResponses readArticles() {
List<ArticlesResponse> articles = articleRepository.findLatestArticles().stream()
.map(ArticlesResponse::from)
.toList();
return new ArticlesListViewResponse(articles);
}

@Transactional(readOnly = true)
public ArticlesCardViewResponse readArticlesCardView() {
List<ArticleCardViewResponse> articles = articleRepository.findLatestArticles(MAX_ARTICLE_CARDS).stream()
.map(ArticleCardViewResponse::from)
.toList();
return new ArticlesCardViewResponse(articles);
return new ArticlesResponses(articles);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ResponseEntity<Void> updateChecklistById(

@DeleteMapping("/checklists/{id}")
public ResponseEntity<Void> deleteChecklistById(@AuthRequiredPrincipal User user, @PathVariable("id") long id) {
checklistService.deleteChecklistById(user, id);
checklistManageService.deleteChecklistById(user, id);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.bang_ggood.checklist.dto.response.ChecklistsPreviewResponse;
import com.bang_ggood.checklist.dto.response.SelectedChecklistResponse;
import com.bang_ggood.like.service.ChecklistLikeService;
import com.bang_ggood.checklist.dto.response.SelectedChecklistResponse;
import com.bang_ggood.maintenance.domain.ChecklistMaintenance;
import com.bang_ggood.maintenance.domain.MaintenanceItem;
import com.bang_ggood.maintenance.service.ChecklistMaintenanceService;
Expand Down Expand Up @@ -96,7 +97,7 @@ public SelectedChecklistResponse readChecklist(User user, Long checklistId) {
List<SelectedOptionResponse> options = readChecklistOptions(checklist);
List<SelectedCategoryQuestionsResponse> questions = readChecklistQuestions(checklist);
SelectedRoomResponse room = SelectedRoomResponse.of(checklist, maintenances);
boolean isLiked = false; // TODO 좋아요 이후 리팩토링 필요
boolean isLiked = checklistLikeService.isLikedChecklist(checklist);

return SelectedChecklistResponse.of(room, options, questions, isLiked);
}
Expand Down Expand Up @@ -147,6 +148,16 @@ private List<ChecklistPreviewResponse> mapToChecklistPreviewResponses(List<Check
.toList();
}

@Transactional
public void deleteChecklistById(User user, Long id) {
Checklist checklist = checklistService.readChecklist(user, id);
checklistQuestionService.deleteAllByChecklistId(checklist.getId());
checklistOptionService.deleteAllByChecklistId(checklist.getId());
checklistMaintenanceService.deleteAllByChecklistId(checklist.getId());
checklistService.deleteById(id);
roomService.deleteById(checklist.getRoom().getId());
}

@Transactional(readOnly = true)
public ChecklistsPreviewResponse readAllChecklistsPreview(User user) {
List<Checklist> checklists = checklistService.readAllChecklistsOrderByLatest(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,7 @@ public void updateChecklist(Checklist checklist, Checklist updateChecklist) {
}

@Transactional
public void deleteChecklistById(User user, long id) {
Checklist checklist = checklistRepository.getById(id);
validateChecklistOwnership(user, checklist);
checklistQuestionRepository.deleteAllByChecklistId(checklist.getId());
checklistOptionRepository.deleteAllByChecklistId(checklist.getId());
checklistMaintenanceRepository.deleteAllByChecklistId(checklist.getId());
public void deleteById(Long id) {
checklistRepository.deleteById(id);
roomRepository.deleteById(checklist.getRoom().getId());
}

@Transactional
public void deleteChecklistLikeByChecklistId(User user, long checklistId) {
Checklist checklist = checklistRepository.getById(checklistId);
validateChecklistOwnership(user, checklist);
ChecklistLike checklistLike = checklistLikeRepository.getByChecklistId(checklistId);

checklistLikeRepository.deleteById(checklistLike.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public List<ChecklistMaintenance> readChecklistMaintenances(Checklist checklist)
return checklistMaintenanceRepository.findAllByChecklistId(checklist.getId());
}

@Transactional
public void deleteAllByChecklistId(Long id) {
checklistMaintenanceRepository.deleteAllByChecklistId(id);
}

@Transactional
public void updateMaintenances(Long checklistId, List<ChecklistMaintenance> checklistMaintenances) {
validateMaintenancesDuplicate(checklistMaintenances);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public List<ChecklistOption> readChecklistOptions(Checklist checklist) {
return checklistOptionRepository.findAllByChecklistId(checklist.getId());
}

@Transactional
public void deleteAllByChecklistId(Long id) {
checklistOptionRepository.deleteAllByChecklistId(id);
}

@Transactional
public void updateOptions(Long checklistId, List<ChecklistOption> checklistOptions) {
validateOptionDuplicate(checklistOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ChecklistQuestionRepository extends JpaRepository<ChecklistQues
@Query("SELECT cq FROM ChecklistQuestion cq "
+ "WHERE cq.checklist.id = :checklistId "
+ "AND cq.deleted = false")
List<ChecklistQuestion> findAllByChecklistId(@Param("checklistId") long checklistId);
List<ChecklistQuestion> findAllByChecklistId(@Param("checklistId") Long checklistId);

@Modifying(flushAutomatically = true, clearAutomatically = true)
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

@Service
public class ChecklistQuestionService {
Expand Down Expand Up @@ -83,6 +82,11 @@ public List<ChecklistQuestion> readChecklistQuestions(Checklist checklist) {
return checklistQuestionRepository.findAllByChecklistId(checklist.getId());
}

@Transactional
public void deleteAllByChecklistId(Long id) {
checklistQuestionRepository.deleteAllByChecklistId(id);
}

@Transactional
public void updateQuestions(List<ChecklistQuestion> questions, List<ChecklistQuestion> updateQuestions) {
validateQuestionDuplicate(updateQuestions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public Room createRoom(Room room) {
return roomRepository.save(room);
}

@Transactional
public void deleteById(Long id) {
roomRepository.deleteById(id);
}

@Transactional
public void updateRoom(Room room, Room updateRoom) {
room.change(updateRoom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvValidationException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class SubwayReader {

public static final String SUBWAY_DATA_PATH = "seoul_stations_240819.csv";
private static final String SUBWAY_DATA_PATH = "classpath*:seoul_stations*.csv";

public static List<SubwayStation> readSubwayStationData() {
List<SubwayStation> stations = new ArrayList<>();
ClassPathResource resource = new ClassPathResource(SUBWAY_DATA_PATH);
try (CSVReader csvReader = new CSVReaderBuilder(
new InputStreamReader(resource.getInputStream(), Charset.forName("EUC-KR"))).build()) {
new InputStreamReader(getSubwayStationResource().getInputStream(), Charset.forName("EUC-KR"))).build()) {
String[] line = csvReader.readNext(); // drop first row
while ((line = csvReader.readNext()) != null) {
SubwayStation station = new SubwayStation(
Expand All @@ -35,4 +38,14 @@ public static List<SubwayStation> readSubwayStationData() {
throw new RuntimeException("지하철 데이터 파일을 읽어오는데 실패했습니다.");
}
}

private static Resource getSubwayStationResource() throws IOException {
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = patternResolver.getResources(SUBWAY_DATA_PATH);

return Arrays.stream(resources)
.filter(resource -> resource.getFilename() != null)
.max(Comparator.comparing(Resource::getFilename))
.orElseThrow(() -> new RuntimeException(SUBWAY_DATA_PATH + "를 읽어오는데 실패했습니다."));
}
}
Loading
Loading