Skip to content

Commit

Permalink
feature/#159 동아리 entity 설계 및 crud api 구현 (#160)
Browse files Browse the repository at this point in the history
* feat: club entity 생성

* feat: 동아리 생성 api 구현

* feat: 동아리 조회 api 구현

* feat: 동아리 수정 api 구현

* feat: 동아리 삭제 api 구현

* feat: 동아리 더미 데이터 추가

* feat: test code

* refactor: test 에러 주석처리

* refactor: 더미 데이터 수정

* refactor: createClub 메소드 이름 수정

* refactor: db 디렉터리 삭제

* refactor: 코멘트 반영
  • Loading branch information
minjo-on authored Jan 3, 2025
1 parent 4b42492 commit 97e8181
Show file tree
Hide file tree
Showing 30 changed files with 817 additions and 506 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kgu.developers.admin.club.application;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import kgu.developers.admin.club.presentation.request.ClubRequest;
import kgu.developers.admin.club.presentation.response.ClubPersistResponse;
import kgu.developers.domain.club.application.command.ClubCommandService;
import kgu.developers.domain.club.application.query.ClubQueryService;
import kgu.developers.domain.club.domain.Club;
import lombok.RequiredArgsConstructor;

@Component
@Transactional
@RequiredArgsConstructor
public class ClubAdminFacade {
private final ClubCommandService clubCommandService;
private final ClubQueryService clubQueryService;

public ClubPersistResponse createClub(ClubRequest request) {
Long id = clubCommandService.createClub(request.name(), request.description(), request.site());
return ClubPersistResponse.of(id);
}

public void updateClub(Long id, ClubRequest request) {
Club club = clubQueryService.getById(id);
clubCommandService.updateClub(club, request.name(), request.description(), request.site());
}

public void deleteClub(Long id) {
clubCommandService.deleteClubById(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package kgu.developers.admin.club.presentation;

import static org.springframework.http.HttpStatus.CREATED;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
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;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Positive;
import kgu.developers.admin.club.application.ClubAdminFacade;
import kgu.developers.admin.club.presentation.request.ClubRequest;
import kgu.developers.admin.club.presentation.response.ClubPersistResponse;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/clubs")
@Tag(name = "Club", description = "동아리 관리자 API")
public class ClubAdminController {
private final ClubAdminFacade clubAdminFacade;

@Operation(summary = "동아리 생성 API", description = """
- Description : 이 API는 동아리를 생성합니다.
- Assignee : 박민준
""")
@ApiResponse(responseCode = "201", content = @Content(schema = @Schema(implementation = ClubPersistResponse.class)))
@PostMapping
public ResponseEntity<ClubPersistResponse> createClub(
@Valid @RequestBody ClubRequest request
) {
ClubPersistResponse response = clubAdminFacade.createClub(request);
return ResponseEntity.status(CREATED).body(response);
}

@Operation(summary = "동아리 수정 API", description = """
- Description : 이 API는 동아리 정보를 수정합니다.
- Assignee : 박민준
""")
@ApiResponse(responseCode = "204")
@PatchMapping("/{id}")
public ResponseEntity<Void> updateClub(
@Parameter(description = "수정할 동아리 id", example = "1", required = true) @PathVariable @Positive Long id,
@Valid @RequestBody ClubRequest request
) {
clubAdminFacade.updateClub(id, request);
return ResponseEntity.noContent().build();
}

@Operation(summary = "동아리 삭제 API", description = """
- Description : 이 API는 해당 동아리를 삭제합니다.
- Assignee : 박민준
""")
@ApiResponse(responseCode = "204")
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteClub(
@Parameter(description = "삭제할 동아리의 id", example = "1", required = true) @PathVariable @Positive Long id
) {
clubAdminFacade.deleteClub(id);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kgu.developers.admin.club.presentation.request;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

public record ClubRequest(
@Schema(description = "동아리 이름", example = "C-Lab", requiredMode = REQUIRED)
@NotBlank
@Size(max = 15)
String name,

@Schema(description = "동아리 설명", example = "경기대학교 AI컴퓨터공학부 개발동아리입니다.", requiredMode = REQUIRED)
@NotBlank
@Size(max = 50)
String description,

@Schema(description = "동아리 홈페이지", example = "https://www.clab.page/", requiredMode = NOT_REQUIRED)
@Pattern(regexp = "^(http|https)://.*$", message = "URL은 http:// 또는 https://으로 시작해야 합니다.")
String site
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kgu.developers.admin.club.presentation.response;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
public record ClubPersistResponse(
@Schema(description = "동아리 id", example = "1", requiredMode = REQUIRED)
Long id
) {
public static ClubPersistResponse of(Long id) {
return ClubPersistResponse.builder()
.id(id)
.build();
}
}
60 changes: 0 additions & 60 deletions aics-admin/src/main/resources/db/data.sql

This file was deleted.

128 changes: 0 additions & 128 deletions aics-admin/src/main/resources/db/schema.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kgu.developers.api.club.application;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import kgu.developers.api.club.presentation.response.ClubListResponse;
import kgu.developers.domain.club.application.query.ClubQueryService;
import kgu.developers.domain.club.domain.Club;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ClubFacade {
private final ClubQueryService clubQueryService;

public ClubListResponse getClubs() {
List<Club> clubs = clubQueryService.getClubs();
return ClubListResponse.from(clubs);
}
}
Loading

0 comments on commit 97e8181

Please sign in to comment.