Skip to content

Commit

Permalink
[feature/InhaBas#204] ClubHistory controller 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
whitem4rk committed Dec 31, 2023
1 parent e39b4d6 commit 0ee8625
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.inhabas.api.domain.club.repository;

import com.inhabas.api.domain.club.domain.entity.ClubHistory;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ClubHistoryRepository extends JpaRepository<ClubHistory, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.inhabas.api.domain.club.usecase;

import com.inhabas.api.domain.club.dto.ClubHistoryDto;
import com.inhabas.api.domain.club.dto.SaveClubHistoryDto;

import java.util.List;

public interface ClubHistoryService {

Long writeClubHistory(SaveClubHistoryDto saveClubHistoryDto);

ClubHistoryDto findClubHistory(Long clubHistoryId);

List<ClubHistoryDto> getClubHistories();

void updateClubHistory(Long clubHistoryId, SaveClubHistoryDto saveClubHistoryDto);

void deleteClubHistories(Long clubHistoryId);

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.inhabas.api.domain.club.usecase;

import com.inhabas.api.domain.club.dto.ClubHistoryDto;
import com.inhabas.api.domain.club.dto.SaveClubHistoryDto;
import com.inhabas.api.domain.club.repository.ClubHistoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ClubHistoryServiceImpl implements ClubHistoryService {

private final ClubHistoryRepository clubHistoryRepository;


@Override
public Long writeClubHistory(SaveClubHistoryDto saveClubHistoryDto) {
return null;
}

@Override
public ClubHistoryDto findClubHistory(Long clubHistoryId) {
return null;
}

@Override
public List<ClubHistoryDto> getClubHistories() {
return null;
}

@Override
public void updateClubHistory(Long clubHistoryId, SaveClubHistoryDto saveClubHistoryDto) {

}

@Override
public void deleteClubHistories(Long clubHistoryId) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.inhabas.api.web;

import com.inhabas.api.auth.domain.error.ErrorResponse;
import com.inhabas.api.domain.club.dto.ClubHistoryDto;
import com.inhabas.api.domain.club.dto.SaveClubHistoryDto;
import com.inhabas.api.domain.club.usecase.ClubHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import javax.validation.Valid;
import java.net.URI;
import java.util.List;

@Tag(name = "동아리 소개", description = "동아리 소개 관련 조회, 수정")
@RestController
@RequiredArgsConstructor
public class ClubHistoryController {

private final ClubHistoryService clubHistoryService;

@Operation(summary = "동아리 연혁 조회",
description = "동아리 연혁 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", content = { @Content(
schema = @Schema(implementation = ClubHistoryDto.class,
type = "array")) }),
})
@GetMapping("/club/histories")
public ResponseEntity<List<ClubHistoryDto>> getClubHistories() {

List<ClubHistoryDto> clubHistoryDtoList = clubHistoryService.getClubHistories();
return ResponseEntity.ok(clubHistoryDtoList);

}

@Operation(summary = "동아리 연혁 단일 조회",
description = "동아리 연혁 단일 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", content = { @Content(
schema = @Schema(implementation = ClubHistoryDto.class))
}),
})
@GetMapping("/club/history/{clubHistoryId}")
public ResponseEntity<ClubHistoryDto> findClubHistory(@PathVariable Long clubHistoryId) {

ClubHistoryDto clubHistoryDto = clubHistoryService.findClubHistory(clubHistoryId);
return ResponseEntity.ok(clubHistoryDto);

}

@Operation(summary = "동아리 연혁 생성",
description = "동아리 연혁 생성")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "'Location' 헤더에 생성된 리소스의 URI가 포함됩니다."),
@ApiResponse(responseCode = "400 ", description = "입력값이 없거나, 타입이 유효하지 않습니다.", content = @Content(
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(
value = "{\"status\": 400, \"code\": \"G003\", \"message\": \"입력값이 없거나, 타입이 유효하지 않습니다.\"}"
)
))
})
@PostMapping("/club/history")
public ResponseEntity<ClubHistoryDto> writeClubHistories(@Valid SaveClubHistoryDto saveClubHistoryDto) {

Long newClubHistoryId = clubHistoryService.writeClubHistory(saveClubHistoryDto);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/club/history/{clubHistoryId}")
.buildAndExpand(newClubHistoryId)
.toUri();
return ResponseEntity.created(location).build();

}

@Operation(summary = "동아리 연혁 수정",
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(
value = "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}"
)
))
})
@PutMapping("/club/history/{clubHistoryId}")
public ResponseEntity<Void> updateClubHistory(@PathVariable Long clubHistoryId, @Valid SaveClubHistoryDto saveClubHistoryDto) {

clubHistoryService.updateClubHistory(clubHistoryId, saveClubHistoryDto);
return ResponseEntity.noContent().build();

}

@Operation(summary = "동아리 연혁 삭제",
description = "동아리 연혁 삭제")
@ApiResponses(value = {
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "404", description = "데이터가 존재하지 않습니다.", content = @Content(
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(
value = "{\"status\": 404, \"code\": \"G004\", \"message\": \"데이터가 존재하지 않습니다.\"}"
)
))
})
@DeleteMapping ("/club/{clubHistoryId}")
public ResponseEntity<Void> deleteClubHistory(@PathVariable Long clubHistoryId) {

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

}

}

0 comments on commit 0ee8625

Please sign in to comment.