-
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 branch 'main' of https://github.com/TAVE-WEBSITE/TAVE-WEBSITE-BE …
…into feat/#25/정규-세션-비지니스-로직-개발
- Loading branch information
Showing
87 changed files
with
2,691 additions
and
116 deletions.
There are no files selected for viewing
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
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
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
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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/tave/tavewebsite/domain/history/controller/ManagerHistoryController.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,50 @@ | ||
package com.tave.tavewebsite.domain.history.controller; | ||
|
||
import com.tave.tavewebsite.domain.history.dto.request.HistoryRequestDto; | ||
import com.tave.tavewebsite.domain.history.dto.response.HistoryResponseDto; | ||
import com.tave.tavewebsite.domain.history.service.HistoryService; | ||
import com.tave.tavewebsite.global.success.SuccessResponse; | ||
import jakarta.validation.Valid; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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("/v1/manager/history") | ||
@RequiredArgsConstructor | ||
public class ManagerHistoryController { | ||
|
||
private final HistoryService historyService; | ||
|
||
@GetMapping | ||
public SuccessResponse<List<HistoryResponseDto>> getAllHistory() { | ||
List<HistoryResponseDto> allOrderByGenerationDesc = historyService.findAllOrderByGenerationDesc(); | ||
return new SuccessResponse<>(allOrderByGenerationDesc); | ||
} | ||
|
||
@PostMapping | ||
public SuccessResponse postHistory(@RequestBody @Valid HistoryRequestDto historyRequestDto) { | ||
historyService.save(historyRequestDto); | ||
return SuccessResponse.ok(); | ||
} | ||
|
||
@PatchMapping("/{historyId}") | ||
public SuccessResponse updateHistory(@PathVariable("historyId") Long id, | ||
@RequestBody @Valid HistoryRequestDto historyRequestDto) { | ||
historyService.patch(id, historyRequestDto); | ||
return SuccessResponse.ok(); | ||
} | ||
|
||
@DeleteMapping("/{historyId}") | ||
public SuccessResponse deleteHistory(@PathVariable("historyId") Long id) { | ||
historyService.delete(id); | ||
return SuccessResponse.ok(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/tave/tavewebsite/domain/history/controller/NormalHistoryController.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,24 @@ | ||
package com.tave.tavewebsite.domain.history.controller; | ||
|
||
import com.tave.tavewebsite.domain.history.dto.response.HistoryResponseDto; | ||
import com.tave.tavewebsite.domain.history.service.HistoryService; | ||
import com.tave.tavewebsite.global.success.SuccessResponse; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/normal/history") | ||
public class NormalHistoryController { | ||
|
||
private final HistoryService historyService; | ||
|
||
@GetMapping | ||
public SuccessResponse<List<HistoryResponseDto>> getPublicHistory() { | ||
List<HistoryResponseDto> publicOrderByGenerationDesc = historyService.findPublicOrderByGenerationDesc(); | ||
return new SuccessResponse<>(publicOrderByGenerationDesc); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/tave/tavewebsite/domain/history/dto/request/HistoryRequestDto.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,22 @@ | ||
package com.tave.tavewebsite.domain.history.dto.request; | ||
|
||
import com.tave.tavewebsite.domain.history.entity.History; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record HistoryRequestDto( | ||
@NotNull(message = "필수로 입력하셔야합니다.") @Size(min = 1, max = 5, message = "1~5 글자 사이로 입력해주세요.") | ||
String generation, | ||
@NotNull(message = "필수로 입력하셔야합니다.") @Size(min = 1, max = 500, message = "최대 500 글자까지 입력 가능합니다.") | ||
String description, | ||
@NotNull(message = "필수로 입력하셔야합니다.") | ||
Boolean isPublic | ||
) { | ||
public History toHistory() { | ||
return History.builder() | ||
.generation(this.generation) | ||
.description(this.description) | ||
.isPublic(this.isPublic) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/tave/tavewebsite/domain/history/dto/response/HistoryResponseDto.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,15 @@ | ||
package com.tave.tavewebsite.domain.history.dto.response; | ||
|
||
import com.tave.tavewebsite.domain.history.entity.History; | ||
|
||
public record HistoryResponseDto( | ||
Long id, | ||
String generation, | ||
String description, | ||
Boolean isPublic | ||
) { | ||
public static HistoryResponseDto of(History history) { | ||
return new HistoryResponseDto(history.getId(), history.getGeneration(), history.getDescription(), | ||
history.isPublic()); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/tave/tavewebsite/domain/history/exception/HistoryErrorException.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,13 @@ | ||
package com.tave.tavewebsite.domain.history.exception; | ||
|
||
import com.tave.tavewebsite.global.exception.BaseErrorException; | ||
|
||
public abstract class HistoryErrorException { | ||
|
||
public static class HistoryNotFoundException extends BaseErrorException { | ||
public HistoryNotFoundException() { | ||
super(HistoryErrorMessage.NOT_FOUND_HISTORY.getCode(), HistoryErrorMessage.NOT_FOUND_HISTORY.getMessage()); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/tave/tavewebsite/domain/history/exception/HistoryErrorMessage.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,15 @@ | ||
package com.tave.tavewebsite.domain.history.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum HistoryErrorMessage { | ||
|
||
NOT_FOUND_HISTORY(400, "History를 찾을 수 없습니다."); | ||
|
||
final int code; | ||
final String message; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/tave/tavewebsite/domain/history/repository/HistoryRepository.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,13 @@ | ||
package com.tave.tavewebsite.domain.history.repository; | ||
|
||
import com.tave.tavewebsite.domain.history.entity.History; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface HistoryRepository extends JpaRepository<History, Long> { | ||
List<History> findByIsPublicOrderByGenerationDesc(Boolean isPublic); | ||
|
||
List<History> findAllByOrderByGenerationDesc(); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/tave/tavewebsite/domain/history/service/HistoryService.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,58 @@ | ||
package com.tave.tavewebsite.domain.history.service; | ||
|
||
import com.tave.tavewebsite.domain.history.dto.request.HistoryRequestDto; | ||
import com.tave.tavewebsite.domain.history.dto.response.HistoryResponseDto; | ||
import com.tave.tavewebsite.domain.history.entity.History; | ||
import com.tave.tavewebsite.domain.history.exception.HistoryErrorException.HistoryNotFoundException; | ||
import com.tave.tavewebsite.domain.history.repository.HistoryRepository; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HistoryService { | ||
|
||
private final HistoryRepository historyRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public List<HistoryResponseDto> findPublicOrderByGenerationDesc() { | ||
List<History> isPublicOrderByGenerationDesc = historyRepository.findByIsPublicOrderByGenerationDesc(true); | ||
List<HistoryResponseDto> historyResponseDtos = new ArrayList<>(); | ||
for (History history : isPublicOrderByGenerationDesc) { | ||
historyResponseDtos.add(HistoryResponseDto.of(history)); | ||
} | ||
return historyResponseDtos; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<HistoryResponseDto> findAllOrderByGenerationDesc() { | ||
List<History> orderByGenerationDesc = historyRepository.findAllByOrderByGenerationDesc(); | ||
List<HistoryResponseDto> historyResponseDtos = new ArrayList<>(); | ||
for (History history : orderByGenerationDesc) { | ||
historyResponseDtos.add(HistoryResponseDto.of(history)); | ||
} | ||
return historyResponseDtos; | ||
} | ||
|
||
public void save(HistoryRequestDto dto) { | ||
historyRepository.save(dto.toHistory()); | ||
} | ||
|
||
@Transactional | ||
public void patch(Long id, HistoryRequestDto dto) { | ||
History history = validate(id); | ||
history.patchHistory(dto); | ||
} | ||
|
||
public void delete(Long id) { | ||
validate(id); | ||
historyRepository.deleteById(id); | ||
} | ||
|
||
private History validate(Long id) { | ||
return historyRepository.findById(id).orElseThrow(HistoryNotFoundException::new); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/tave/tavewebsite/domain/member/controller/AdminController.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,31 @@ | ||
package com.tave.tavewebsite.domain.member.controller; | ||
|
||
import com.tave.tavewebsite.domain.member.dto.response.AuthorizedManagerResponseDto; | ||
import com.tave.tavewebsite.domain.member.dto.response.UnauthorizedManagerResponseDto; | ||
import com.tave.tavewebsite.domain.member.service.AdminService; | ||
import com.tave.tavewebsite.global.success.SuccessResponse; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/admin") | ||
@RequiredArgsConstructor | ||
public class AdminController { | ||
|
||
private final AdminService adminService; | ||
|
||
@GetMapping("/unauthorized") | ||
public SuccessResponse<List<UnauthorizedManagerResponseDto>> getUnauthorizedManager() { | ||
List<UnauthorizedManagerResponseDto> response = adminService.getUnauthorizedManager(); | ||
return new SuccessResponse<>(response); | ||
} | ||
|
||
@GetMapping("/authorized") | ||
public SuccessResponse<List<AuthorizedManagerResponseDto>> getAuthorizedAdmins() { | ||
List<AuthorizedManagerResponseDto> response = adminService.getAuthorizedAdmins(); | ||
return new SuccessResponse<>(response); | ||
} | ||
} |
Oops, something went wrong.