Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/#204] [동아리 소개] API 구현 #206

Merged
merged 10 commits into from
Jan 5, 2024
45 changes: 23 additions & 22 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
name: Gradle Build

on:
pull_request:
branches: [dev, master, feature/*, refactor/* ]
pull_request_target:
types: [ opened, reopened, synchronize ]


jobs:
build:
runs-on: ubuntu-latest
environment: build_gradle

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021
with:
arguments: build
env:
IBAS_DEV_JWT_SECRET_KEY: ${{ secrets.IBAS_DEV_JWT_SECRET_KEY }}
IBAS_DEV_KAKAO_CLIENT_ID: ${{ secrets.IBAS_DEV_KAKAO_CLIENT_ID }}
IBAS_DEV_KAKAO_CLIENT_SECRET: ${{ secrets.IBAS_DEV_KAKAO_CLIENT_SECRET }}
IBAS_DEV_NAVER_CLIENT_ID: ${{ secrets.IBAS_DEV_NAVER_CLIENT_ID }}
IBAS_DEV_NAVER_CLIENT_SECRET: ${{ secrets.IBAS_DEV_NAVER_CLIENT_SECRET }}
IBAS_DEV_GOOGLE_CLIENT_ID: ${{ secrets.IBAS_DEV_GOOGLE_CLIENT_ID }}
IBAS_DEV_GOOGLE_CLIENT_SECRET: ${{ secrets.IBAS_DEV_GOOGLE_CLIENT_SECRET }}
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew clean build
env:
IBAS_DEV_JWT_SECRET_KEY: ${{ secrets.IBAS_DEV_JWT_SECRET_KEY }}
IBAS_DEV_KAKAO_CLIENT_ID: ${{ secrets.IBAS_DEV_KAKAO_CLIENT_ID }}
IBAS_DEV_KAKAO_CLIENT_SECRET: ${{ secrets.IBAS_DEV_KAKAO_CLIENT_SECRET }}
IBAS_DEV_NAVER_CLIENT_ID: ${{ secrets.IBAS_DEV_NAVER_CLIENT_ID }}
IBAS_DEV_NAVER_CLIENT_SECRET: ${{ secrets.IBAS_DEV_NAVER_CLIENT_SECRET }}
IBAS_DEV_GOOGLE_CLIENT_ID: ${{ secrets.IBAS_DEV_GOOGLE_CLIENT_ID }}
IBAS_DEV_GOOGLE_CLIENT_SECRET: ${{ secrets.IBAS_DEV_GOOGLE_CLIENT_SECRET }}
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 @@ -2,7 +2,7 @@

import com.inhabas.api.domain.board.BaseBoard;
import com.inhabas.api.domain.board.BoardCannotModifiableException;
import com.inhabas.api.domain.board.domain.valueObject.Contents;
import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import com.inhabas.api.domain.comment.domain.Comment;
import com.inhabas.api.domain.file.BoardFile;
Expand Down Expand Up @@ -39,7 +39,7 @@
public class NormalBoard extends BaseBoard {

@Embedded
protected Contents contents;
protected Content content;

@OneToMany(mappedBy = "parentBoard", cascade = CascadeType.ALL, orphanRemoval = true)
protected List<Comment> comments = new ArrayList<>();
Expand All @@ -52,14 +52,14 @@ public class NormalBoard extends BaseBoard {

public NormalBoard(String title, String contents) {
this.title = new Title(title);
this.contents = new Contents(contents);
this.content = new Content(contents);
}


/* getter */

public String getContents() {
return contents.getValue();
public String getContent() {
return content.getValue();
}

public Set<BoardFile> getFiles() {
Expand Down Expand Up @@ -92,7 +92,7 @@ public void modify(String title, String contents, StudentId loginMember) {
}

this.title = new Title(title);
this.contents = new Contents(contents);
this.content = new Content(contents);
}

public boolean cannotModifiableBy(StudentId loginMember) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package com.inhabas.api.domain.board.domain.valueObject;

import com.inhabas.api.auth.domain.error.businessException.InvalidInputException;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
import java.util.Objects;

@Embeddable
public class Contents {
public class Content {

@Column(name = "contents", columnDefinition = "MEDIUMTEXT", nullable = false)
@Column(name = "CONTENT", columnDefinition = "MEDIUMTEXT", nullable = false)
private String value;

@Transient
private final int MAX_SIZE = 2 << 24 - 1; //16MB

public Contents() {}
public Content() {}

public Contents(String value) {
public Content(String value) {
if (validate(value))
this.value = value;
else
throw new IllegalArgumentException();
throw new InvalidInputException();
}

private boolean validate(Object value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.inhabas.api.domain.board.domain.valueObject;

import com.inhabas.api.auth.domain.error.businessException.InvalidInputException;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
Expand All @@ -8,7 +10,7 @@
@Embeddable
public class Title {

@Column(name = "title", length = 100, nullable = false)
@Column(name = "TITLE", length = 100, nullable = false)
private String value;

@Transient
Expand All @@ -20,7 +22,7 @@ public Title(String value) {
if (validate(value))
this.value = value;
else
throw new IllegalArgumentException();
throw new InvalidInputException();
}

private boolean validate(Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Page<BoardDto> findAllByMenuId(MenuId menuId, Pageable pageable) {
List<BoardDto> results = queryFactory.select(Projections.constructor(BoardDto.class,
normalBoard.id,
normalBoard.title.value,
Expressions.asString("").as("contents"),
Expressions.asString("").as("content"),
member.name.value,
normalBoard.menuId,
normalBoard.dateCreated,
Expand Down Expand Up @@ -60,7 +60,7 @@ public Optional<BoardDto> findDtoById(Integer id) {
BoardDto target = queryFactory.select(Projections.constructor(BoardDto.class,
Expressions.asNumber(id).as("id"),
normalBoard.title.value,
normalBoard.contents.value,
normalBoard.content.value,
member.name.value,
normalBoard.menuId,
normalBoard.dateCreated,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.inhabas.api.domain.club.domain.entity;

import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.domain.board.domain.valueObject.Content;
import com.inhabas.api.domain.board.domain.valueObject.Title;
import com.inhabas.api.domain.club.dto.SaveClubHistoryDto;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Table(name = "CLUB_HISTORY")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class ClubHistory {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "USER_ID", foreignKey = @ForeignKey(name = "FK_MEMBER_OF_CLUB_HISTORY"))
private Member member;

@Embedded
private Title title;

@Embedded
private Content content;

@Column(name = "DATE_HISTORY", nullable = false, columnDefinition = "DATETIME(0)")
private LocalDateTime dateHistory;

@CreatedDate
@Column(name = "DATE_CREATED", nullable = false, updatable = false, insertable = false, columnDefinition = "DATETIME(0) DEFAULT CURRENT_TIMESTAMP")
private LocalDateTime dateCreated;

@Builder
public ClubHistory(Member member, Title title, Content content, LocalDateTime dateHistory) {
this.member = member;
this.title = title;
this.content = content;
this.dateHistory = dateHistory;
}

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

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

import com.fasterxml.jackson.annotation.JsonFormat;
import com.inhabas.api.domain.club.domain.entity.ClubHistory;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class ClubHistoryDto {

@NotNull
@Positive
private Long id;

@NotNull
private String title;

@NotNull
private String content;

@NotNull
@Positive
private Long writerId;

@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 ClubHistoryDto(Long id, String title, String content, Long writerId, LocalDateTime dateHistory) {
this.id = id;
this.title = title;
this.content = content;
this.writerId = writerId;
this.dateHistory = dateHistory;
}

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

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class SaveClubHistoryDto {

private String title;

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(String title, String content, LocalDateTime dateHistory) {
this.title = title;
this.content = content;
this.dateHistory = dateHistory;
}

}
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> {
}
Loading