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
7 changes: 3 additions & 4 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ jobs:
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
run: ./gradlew clean build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses: gradle/gradle-build-action@

대신에 run: ./gradlew clean build를 사용한 이유를 알고 싶습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

환경 변수 때문인가요? 특정 버전의 gradle을 사용하기 위해서 이렇게 코드를 수정한 것인지 궁금합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.yml에 변수 env를 넘겨줘야하는데 gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021 쓰는 방식은 변수를 넘겨주는건 enterprise 버전에서만 적용된다고 그래서 저렇게 수정했어.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle/gradle-build-action의 사용은 종속성 캐싱 등의 기능을 통해 빌드 시간을 단축시킬 수 있습니다. 특히, 대규모 프로젝트나 복잡한 빌드 과정이 있는 경우에 유용합니다.
직접 ./gradlew 사용은 추가 설정 없이 기본적인 Gradle 실행을 제공합니다. 간단한 프로젝트나 특별한 빌드 최적화가 필요 없는 경우에 적합할 수 있습니다.

확실히 전자의 방식이 성능면에선 우수하네

env:
IBAS_DEV_JWT_SECRET_KEY: ${{ secrets.IBAS_DEV_JWT_SECRET_KEY }}
IBAS_DEV_KAKAO_CLIENT_ID: ${{ secrets.IBAS_DEV_KAKAO_CLIENT_ID }}
Expand Down
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> {
}
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(Long memberId, SaveClubHistoryDto saveClubHistoryDto);

ClubHistoryDto findClubHistory(Long clubHistoryId);

List<ClubHistoryDto> getClubHistories();

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

void deleteClubHistory(Long clubHistoryId);

}

Loading
Loading