-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...ava/com/bbteam/budgetbuddies/domain/searchkeyword/controller/SearchKeywordController.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,48 @@ | ||
package com.bbteam.budgetbuddies.domain.searchkeyword.controller; | ||
|
||
import com.bbteam.budgetbuddies.apiPayload.ApiResponse; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.SearchKeyword; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.service.SearchKeywordService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/search-keyword") | ||
public class SearchKeywordController { | ||
|
||
private final SearchKeywordService searchKeywordService; | ||
|
||
@PostMapping("") | ||
public ApiResponse<SearchKeyword> saveKeyword(String keyword) { | ||
|
||
return ApiResponse.onSuccess(searchKeywordService.saveKeyword(keyword)); | ||
} | ||
|
||
@GetMapping("") | ||
public ApiResponse<SearchKeyword> findOne(Long searchKeywordId) { | ||
return ApiResponse.onSuccess(searchKeywordService.findOne(searchKeywordId)); | ||
} | ||
|
||
@GetMapping("/all") | ||
public ApiResponse<Page<SearchKeyword>> findAll(Pageable pageable) { | ||
return ApiResponse.onSuccess(searchKeywordService.findAll(pageable)); | ||
} | ||
|
||
@PutMapping("") | ||
public ApiResponse<SearchKeyword> modifyOne(Long searchKeywordId, String newKeyword) { | ||
return ApiResponse.onSuccess((searchKeywordService.modifyOne(searchKeywordId, newKeyword))); | ||
} | ||
|
||
@DeleteMapping("") | ||
public ApiResponse<String> deleteOne(Long searchKeywordId) { | ||
searchKeywordService.deleteOne(searchKeywordId); | ||
return ApiResponse.onSuccess("OK"); | ||
} | ||
|
||
|
||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/bbteam/budgetbuddies/domain/searchkeyword/domain/SearchKeyword.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,23 @@ | ||
package com.bbteam.budgetbuddies.domain.searchkeyword.domain; | ||
|
||
import com.bbteam.budgetbuddies.common.BaseEntity; | ||
import jakarta.persistence.Entity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class SearchKeyword extends BaseEntity { | ||
|
||
private String keyword; | ||
|
||
public void changeKeyword(String newKeyword) { | ||
this.keyword = newKeyword; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ava/com/bbteam/budgetbuddies/domain/searchkeyword/repository/SearchKeywordRepository.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,7 @@ | ||
package com.bbteam.budgetbuddies.domain.searchkeyword.repository; | ||
|
||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.SearchKeyword; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SearchKeywordRepository extends JpaRepository<SearchKeyword, Long> { | ||
} |
44 changes: 44 additions & 0 deletions
44
...main/java/com/bbteam/budgetbuddies/domain/searchkeyword/service/SearchKeywordService.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,44 @@ | ||
package com.bbteam.budgetbuddies.domain.searchkeyword.service; | ||
|
||
import com.bbteam.budgetbuddies.apiPayload.code.status.ErrorStatus; | ||
import com.bbteam.budgetbuddies.apiPayload.exception.GeneralException; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.SearchKeyword; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.repository.SearchKeywordRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class SearchKeywordService { | ||
|
||
private final SearchKeywordRepository searchKeywordRepository; | ||
|
||
public SearchKeyword saveKeyword(String keyword) { | ||
SearchKeyword searchKeyword = SearchKeyword.builder().keyword(keyword).build(); | ||
searchKeywordRepository.save(searchKeyword); | ||
return searchKeyword; | ||
} | ||
|
||
public SearchKeyword findOne(Long searchKeywordId) { | ||
return searchKeywordRepository.findById(searchKeywordId).orElseThrow(() -> new GeneralException(ErrorStatus._SEARCH_KEYWORD_NOT_FOUND)); | ||
} | ||
|
||
public Page<SearchKeyword> findAll(Pageable pageable) { | ||
return searchKeywordRepository.findAll(pageable); | ||
} | ||
|
||
public SearchKeyword modifyOne(Long searchKeywordId, String keyword) { | ||
SearchKeyword searchKeyword = searchKeywordRepository.findById(searchKeywordId).orElseThrow(() -> new GeneralException(ErrorStatus._SEARCH_KEYWORD_NOT_FOUND)); | ||
searchKeyword.changeKeyword(keyword); | ||
return searchKeyword; | ||
} | ||
|
||
public void deleteOne(Long searchKeywordId) { | ||
SearchKeyword searchKeyword = searchKeywordRepository.findById(searchKeywordId).orElseThrow(() -> new GeneralException(ErrorStatus._SEARCH_KEYWORD_NOT_FOUND)); | ||
searchKeywordRepository.delete(searchKeyword); | ||
} | ||
} |