Skip to content

Commit

Permalink
[feature/InhaBas#204] ClubHistory 전체적인 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
whitem4rk committed Jan 3, 2024
1 parent 9cfc981 commit e428b63
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public GroupedOpenApi getMemberApi() {

}

@Bean
public GroupedOpenApi getIBASApi() {

return GroupedOpenApi
.builder()
.group("IBAS 관련")
.pathsToMatch("/club/**")
.build();

}

@Bean
@Profile("local")
public OpenAPI localOpenAPI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class WebSecurityConfig {
private static final String[] AUTH_WHITELIST_PATH = {"/menu/**", "/menus", "/member/chief", "/error"};
private static final String[] AUTH_WHITELIST_SIGNUP = {"/signUp/schedule", "/signUp/questionnaires",
"/signUp/majorInfo"};

private static final String[] AUTH_WHITELIST_CLUB = {"/club/histories", "/club/history/**"};

@Order(1)
@EnableGlobalMethodSecurity(prePostEnabled = true, jsr250Enabled = true)
Expand All @@ -71,6 +71,7 @@ public void configure(AuthenticationManagerBuilder auth) throws Exception {
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(HttpMethod.GET, AUTH_WHITELIST_SIGNUP)
.antMatchers(HttpMethod.GET, AUTH_WHITELIST_CLUB)
.antMatchers(AUTH_WHITELIST_SWAGGER)
.antMatchers(AUTH_WHITELIST_STATIC)
.antMatchers(AUTH_WHITELIST_PATH);
Expand Down Expand Up @@ -122,6 +123,9 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/signUp/check").hasRole(ANONYMOUS.toString())
.antMatchers("/signUp/**").hasRole(SIGNING_UP.toString())

// 동아리 연혁 수정
.antMatchers("/club/history/**").hasRole(EXECUTIVES.toString())

// 그 외
.anyRequest().hasRole(ANONYMOUS.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public ClubHistory(Member member, Title title, Content content, LocalDateTime da

public void updateClubHistory(Member member, SaveClubHistoryDto saveClubHistoryDto) {
this.member = member;
this.title = saveClubHistoryDto.getTitle();
this.content = saveClubHistoryDto.getContent();
this.title = new Title(saveClubHistoryDto.getTitle());
this.content = new Content(saveClubHistoryDto.getContent());
this.dateHistory = saveClubHistoryDto.getDateHistory();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.inhabas.api.domain.club.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import com.inhabas.api.domain.club.domain.entity.ClubHistory;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand All @@ -21,9 +19,11 @@ public class ClubHistoryDto {
@Positive
private Long id;

private Title title;
@NotNull
private String title;

private Content content;
@NotNull
private String content;

@NotNull
@Positive
Expand All @@ -35,7 +35,7 @@ public class ClubHistoryDto {
private LocalDateTime dateHistory;

@Builder
public ClubHistoryDto(Long id, Title title, Content content, Long writerId, LocalDateTime dateHistory) {
public ClubHistoryDto(Long id, String title, String content, Long writerId, LocalDateTime dateHistory) {
this.id = id;
this.title = title;
this.content = content;
Expand All @@ -45,8 +45,8 @@ public ClubHistoryDto(Long id, Title title, Content content, Long writerId, Loca

public ClubHistoryDto(ClubHistory clubHistory) {
this.id = clubHistory.getId();
this.title = clubHistory.getTitle();
this.content = clubHistory.getContent();
this.title = clubHistory.getTitle().getValue();
this.content = clubHistory.getContent().getValue();
this.writerId = clubHistory.getMember().getId();
this.dateHistory = clubHistory.getDateHistory();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.inhabas.api.domain.club.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -15,17 +13,17 @@
@NoArgsConstructor
public class SaveClubHistoryDto {

private Title title;
private String title;

private Content content;
private String content;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2023-11-01T00:00:00")
private LocalDateTime dateHistory;

@Builder
public SaveClubHistoryDto(Title title, Content content, LocalDateTime dateHistory) {
public SaveClubHistoryDto(String title, String content, LocalDateTime dateHistory) {
this.title = title;
this.content = content;
this.dateHistory = dateHistory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ClubHistoryService {

void updateClubHistory(Long memberId, Long clubHistoryId, SaveClubHistoryDto saveClubHistoryDto);

void deleteClubHistories(Long clubHistoryId);
void deleteClubHistory(Long clubHistoryId);

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.exception.MemberNotFoundException;
import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository;
import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import com.inhabas.api.domain.club.domain.entity.ClubHistory;
import com.inhabas.api.domain.club.dto.ClubHistoryDto;
import com.inhabas.api.domain.club.dto.SaveClubHistoryDto;
Expand Down Expand Up @@ -31,8 +33,8 @@ public Long writeClubHistory(Long memberId, SaveClubHistoryDto saveClubHistoryDt
Member writer = memberRepository.findById(memberId).orElseThrow(MemberNotFoundException::new);
ClubHistory clubHistory = ClubHistory.builder()
.member(writer)
.title(saveClubHistoryDto.getTitle())
.content(saveClubHistoryDto.getContent())
.title(new Title(saveClubHistoryDto.getTitle()))
.content(new Content(saveClubHistoryDto.getContent()))
.dateHistory(saveClubHistoryDto.getDateHistory())
.build();

Expand Down Expand Up @@ -77,7 +79,7 @@ public void updateClubHistory(Long memberId, Long clubHistoryId, SaveClubHistory

@Override
@Transactional
public void deleteClubHistories(Long clubHistoryId) {
public void deleteClubHistory(Long clubHistoryId) {

ClubHistory clubHistory = clubHistoryRepository.findById(clubHistoryId).orElseThrow(NotFoundException::new);
clubHistoryRepository.delete(clubHistory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public ResponseEntity<List<ClubHistoryDto>> getClubHistories() {
value = "{\"status\": 400, \"code\": \"G003\", \"message\": \"입력값이 없거나, 타입이 유효하지 않습니다.\"}"
)
)),
@ApiResponse(responseCode = "404", description = "데이터가 존재하지 않습니다.", content = @Content(
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(
value = "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}"
)
))
})
@GetMapping("/club/history/{clubHistoryId}")
public ResponseEntity<ClubHistoryDto> findClubHistory(@PathVariable Long clubHistoryId) {
Expand All @@ -76,7 +82,7 @@ public ResponseEntity<ClubHistoryDto> findClubHistory(@PathVariable Long clubHis
))
})
@PostMapping("/club/history")
public ResponseEntity<ClubHistoryDto> writeClubHistories(@Authenticated Long memberId, @Valid SaveClubHistoryDto saveClubHistoryDto) {
public ResponseEntity<ClubHistoryDto> writeClubHistory(@Authenticated Long memberId, @Valid @RequestBody SaveClubHistoryDto saveClubHistoryDto) {

Long newClubHistoryId = clubHistoryService.writeClubHistory(memberId, saveClubHistoryDto);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
Expand All @@ -103,10 +109,11 @@ public ResponseEntity<ClubHistoryDto> writeClubHistories(@Authenticated Long mem
value = "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}"
)
))

})
@PutMapping("/club/history/{clubHistoryId}")
public ResponseEntity<Void> updateClubHistory(@PathVariable Long clubHistoryId, @Authenticated Long memberId,
@Valid SaveClubHistoryDto saveClubHistoryDto) {
@Valid @RequestBody SaveClubHistoryDto saveClubHistoryDto) {

clubHistoryService.updateClubHistory(memberId, clubHistoryId, saveClubHistoryDto);
return ResponseEntity.noContent().build();
Expand All @@ -117,6 +124,12 @@ public ResponseEntity<Void> updateClubHistory(@PathVariable Long clubHistoryId,
description = "동아리 연혁 삭제")
@ApiResponses(value = {
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400 ", description = "입력값이 없거나, 타입이 유효하지 않습니다.", content = @Content(
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(
value = "{\"status\": 400, \"code\": \"G003\", \"message\": \"입력값이 없거나, 타입이 유효하지 않습니다.\"}"
)
)),
@ApiResponse(responseCode = "404", description = "데이터가 존재하지 않습니다.", content = @Content(
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(
Expand All @@ -127,7 +140,7 @@ public ResponseEntity<Void> updateClubHistory(@PathVariable Long clubHistoryId,
@DeleteMapping ("/club/history/{clubHistoryId}")
public ResponseEntity<Void> deleteClubHistory(@PathVariable Long clubHistoryId) {

clubHistoryService.deleteClubHistories(clubHistoryId);
clubHistoryService.deleteClubHistory(clubHistoryId);
return ResponseEntity.noContent().build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void updateClubHistory() {
.dateHistory(LocalDateTime.now())
.build();
SaveClubHistoryDto saveClubHistoryDto = SaveClubHistoryDto.builder()
.title(new Title("title"))
.content(new Content("content"))
.title("title")
.content("content")
.dateHistory(LocalDateTime.now())
.build();

Expand All @@ -35,7 +35,8 @@ void updateClubHistory() {

//then
assertThat(clubHistory)
.extracting(ClubHistory::getTitle, ClubHistory::getContent)
.extracting(ClubHistory -> clubHistory.getTitle().getValue(),
ClubHistory -> clubHistory.getContent().getValue())
.containsExactly(saveClubHistoryDto.getTitle(), saveClubHistoryDto.getContent());

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.inhabas.api.domain.club.dto;

import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -37,8 +35,8 @@ void Positive_Test() {
//given
ClubHistoryDto clubHistoryDto = ClubHistoryDto.builder()
.id(-1L)
.title(new Title("goodTitle"))
.content(new Content("goodContent"))
.title("goodTitle")
.content("goodContent")
.writerId(-1L)
.dateHistory(LocalDateTime.now())
.build();
Expand All @@ -57,8 +55,8 @@ void NotNull_Test() {
//given
ClubHistoryDto clubHistoryDto = ClubHistoryDto.builder()
.id(null)
.title(new Title("goodTitle"))
.content(new Content("goodContent"))
.title("goodTitle")
.content("goodContent")
.writerId(null)
.dateHistory(null)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.inhabas.api.domain.club.dto;

import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -36,8 +34,8 @@ public static void close() {
void NotNull_Test() {
//given
SaveClubHistoryDto saveClubHistoryDto = SaveClubHistoryDto.builder()
.title(new Title("goodTitle"))
.content(new Content("goodContent"))
.title("goodTitle")
.content("goodContent")
.dateHistory(null)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void writeClubHistory_Success() {
Long memberId = 1L;
Member member = MemberTest.chiefMember(); // 필요한 속성으로 Member 객체 초기화
SaveClubHistoryDto saveClubHistoryDto = new SaveClubHistoryDto(
new Title("title"), new Content("content"), LocalDateTime.now());
"title", "content", LocalDateTime.now());

given(memberRepository.findById(memberId)).willReturn(Optional.of(member));
given(clubHistoryRepository.save(any(ClubHistory.class))).willAnswer(invocation -> {
Expand All @@ -71,7 +71,7 @@ void writeClubHistory_Success() {
void writeClubHistory_Member_Not_Found() {
//given
SaveClubHistoryDto saveClubHistoryDto = new SaveClubHistoryDto(
new Title("title"), new Content("content"), LocalDateTime.now());
"title", "content", LocalDateTime.now());
given(memberRepository.findById(any())).willReturn(Optional.empty());

// then
Expand Down Expand Up @@ -135,7 +135,7 @@ void getClubHistories_Success() {
assertThat(clubHistoryDtoList)
.hasSize(1)
.extracting("title", "content")
.contains(tuple(clubHistory.getTitle(), clubHistory.getContent()));
.contains(tuple(clubHistory.getTitle().getValue(), clubHistory.getContent().getValue()));

}

Expand All @@ -152,7 +152,7 @@ void updateClubHistory_Success() {
.dateHistory(LocalDateTime.now())
.build();
SaveClubHistoryDto saveClubHistoryDto = new SaveClubHistoryDto(
new Title("title"), new Content("content"), LocalDateTime.now());
"title", "content", LocalDateTime.now());
given(clubHistoryRepository.findById(any())).willReturn(Optional.ofNullable(clubHistory));
given(memberRepository.findById(any())).willReturn(Optional.of(member));

Expand All @@ -179,7 +179,7 @@ void deleteClubHistories_Success() {
given(clubHistoryRepository.findById(any())).willReturn(Optional.ofNullable(clubHistory));

//when
clubHistoryService.deleteClubHistories(any());
clubHistoryService.deleteClubHistory(any());

//then
then(clubHistoryRepository).should().findById(any());
Expand Down
Loading

0 comments on commit e428b63

Please sign in to comment.