Skip to content

Commit

Permalink
[feature/Inhabas#228] 공모전 게시판 API 구현
Browse files Browse the repository at this point in the history
[feature/Inhabas#228] 공모전 게시판 API 구현
  • Loading branch information
skytin1004 authored Mar 2, 2024
2 parents 0f662bc + 0b305dc commit 9412373
Show file tree
Hide file tree
Showing 43 changed files with 2,432 additions and 950 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public GroupedOpenApi getBoardApi() {
.build();
}

@Bean
public GroupedOpenApi getContestApi() {

return GroupedOpenApi.builder()
.group("공모전 게시판 관련")
.pathsToMatch("/contest/**", "/**/**/**/comment/**", "/**/**/**/comments")
.build();
}

@Bean
@Profile("local")
public OpenAPI localOpenAPI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.inhabas.api.web.converter.ContestOrderByConverter;
import com.inhabas.api.web.converter.ContestTypeConverter;
import com.inhabas.api.web.converter.MenuIdConverter;
import com.inhabas.api.web.converter.NormalBoardTypeConverter;
import io.swagger.v3.core.jackson.ModelResolver;

@Configuration
public class WebConfig {
public class WebConfig implements WebMvcConfigurer {

// 커스텀 컨버터를 Spring 변환 서비스에 등록
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new ContestOrderByConverter.StringToOrderByConverter());
registry.addConverter(new ContestOrderByConverter.OrderByToStringConverter());
registry.addConverter(new ContestTypeConverter.StringToContestTypeConverter());
registry.addConverter(new ContestTypeConverter.ContestTypeToStringConverter());
registry.addConverter(new NormalBoardTypeConverter.NormalTypeToStringConverter());
registry.addConverter(new NormalBoardTypeConverter.StringToNormalTypeConverter());
registry.addConverter(new MenuIdConverter.StringToMenuIdConverter());
registry.addConverter(new MenuIdConverter.MenuIdToStringConverter());
}

@Bean
public ModelResolver modelResolver(ObjectMapper objectMapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class WebSecurityConfig {
};
private static final String[] AUTH_WHITELIST_NORMAL_BOARD = {"/board/count"};

private static final String[] AUTH_WHITELIST_CONTEST_BOARD = {"/contest/count"};

@Order(1)
@EnableGlobalMethodSecurity(prePostEnabled = true, jsr250Enabled = true)
@EnableWebSecurity
Expand All @@ -87,6 +89,7 @@ public void configure(WebSecurity web) throws Exception {
.antMatchers(HttpMethod.GET, AUTH_WHITELIST_SIGNUP)
.antMatchers(HttpMethod.GET, AUTH_WHITELIST_CLUB)
.antMatchers(HttpMethod.GET, AUTH_WHITELIST_NORMAL_BOARD)
.antMatchers(HttpMethod.GET, AUTH_WHITELIST_CONTEST_BOARD)
.antMatchers(AUTH_WHITELIST_SWAGGER)
.antMatchers(AUTH_WHITELIST_STATIC)
.antMatchers(AUTH_WHITELIST_PATH);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,88 @@
package com.inhabas.api.domain.contest.domain;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.inhabas.api.domain.board.domain.BaseBoard;
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.contest.domain.valueObject.Association;
import com.inhabas.api.domain.contest.domain.valueObject.Topic;
import com.inhabas.api.domain.normalBoard.domain.NormalBoard;
import com.inhabas.api.domain.file.domain.BoardFile;
import com.inhabas.api.domain.menu.domain.Menu;

@Entity
@Table(name = "contest_board")
@Table(name = "CONTEST_BOARD")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ContestBoard extends NormalBoard {
@EntityListeners(AuditingEntityListener.class)
@DiscriminatorValue("CONTEST")
public class ContestBoard extends BaseBoard {

@ManyToOne
@JoinColumn(name = "CONTEST_FIELD_ID", foreignKey = @ForeignKey(name = "FK_CONTEST_FIELD_OF_ID"))
private ContestField contestField;

@Embedded private Topic topic;

@Embedded private Association association;

@Column private LocalDate start;
@Embedded private Content content;

@Column(name = "DATE_CONTEST_START", nullable = false)
private LocalDate dateContestStart;

@Column(name = "DATE_CONTEST_END", nullable = false)
private LocalDate dateContestEnd;

@Column private LocalDate deadline;
@OneToMany(mappedBy = "parentBoard", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> comments = new ArrayList<>();

/* constructor */
@Builder
public ContestBoard(
Menu menu,
ContestField contestField,
String title,
String content,
String association,
String topic,
LocalDate dateContestStart,
LocalDate dateContestEnd) {

super(title, menu);
this.contestField = contestField;
this.title = new Title(title);
this.content = new Content(content);
this.association = new Association(association);
this.topic = new Topic(topic);
this.dateContestStart = dateContestStart;
this.dateContestEnd = dateContestEnd;
}

/* Getter */
/* getter */
public String getAssociation() {
return association.getValue();
}
Expand All @@ -40,32 +91,46 @@ public String getTopic() {
return topic.getValue();
}

/* Constructor */
public String getContent() {
return content.getValue();
}

@Builder
public ContestBoard(
public List<BoardFile> getFiles() {
return Collections.unmodifiableList(files);
}

/* relation method */

// 첨부파일 수정
public void updateFiles(List<BoardFile> files) {

if (this.files != null) {
this.files.clear();
} else {
this.files = new ArrayList<>();
}

for (BoardFile file : files) {
addFile(file);
}
}

// 공모전 정보 수정
public void updateContest(
ContestField contestField,
String title,
String contents,
String content,
String association,
String topic,
LocalDate start,
LocalDate deadline) {
LocalDate dateContestStart,
LocalDate dateContestEnd) {

this.contestField = contestField;
this.title = new Title(title);
// this.content = new Content(contents);
this.content = new Content(content);
this.association = new Association(association);
this.topic = new Topic(topic);
this.start = start;
this.deadline = deadline;
this.dateContestStart = dateContestStart;
this.dateContestEnd = dateContestEnd;
}

// public void modify(String title, String contents, String association, String topic,
// LocalDate start, LocalDate deadline, StudentId loginMember) {
//
// super.modify(title, contents, loginMember);
// this.association = new Association(association);
// this.topic = new Topic(topic);
// this.start = start;
// this.deadline = deadline;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.inhabas.api.domain.contest.domain;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.inhabas.api.domain.BaseEntity;
import com.inhabas.api.domain.contest.domain.valueObject.ContestFieldName;

@Entity
@Table(name = "CONTEST_FIELD")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class ContestField extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Long id;

@Embedded private ContestFieldName name;

@Builder
public ContestField(String name) {
this.name = new ContestFieldName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import javax.persistence.Embeddable;
import javax.persistence.Transient;

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

@Embeddable
public class Association {

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

@Transient private final int MAX_LENGTH = 100;
Expand All @@ -18,7 +20,7 @@ public Association() {}

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

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

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;

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

@Embeddable
public class ContestFieldName {

@Column(name = "NAME", length = 15, nullable = false)
private String value;

@Transient private final int MAX_LENGTH = 15;

public ContestFieldName() {}

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

private boolean validate(Object value) {
if (Objects.isNull(value)) return false;
if (!(value instanceof String)) return false;

String o = (String) value;
if (o.isBlank()) return false;
return o.length() < MAX_LENGTH;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.inhabas.api.domain.contest.domain.valueObject;

public enum ContestType {
CONTEST("contest", 18),
ACTIVITY("activity", 19);

private final String boardType;
private final int menuId;

ContestType(String boardType, int menuId) {
this.boardType = boardType;
this.menuId = menuId;
}

public String getBoardType() {
return boardType;
}

public int getMenuId() {
return menuId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.inhabas.api.domain.contest.domain.valueObject;

import com.inhabas.api.domain.contest.domain.QContestBoard;
import com.querydsl.core.types.OrderSpecifier;

public enum OrderBy {
DATE_CONTEST_END {
public OrderSpecifier<?> getOrderBy(QContestBoard contestBoard) {
return contestBoard.dateContestEnd.desc();
}
},

DATE_CREATED {
public OrderSpecifier<?> getOrderBy(QContestBoard contestBoard) {
return contestBoard.dateCreated.desc();
}
};

public abstract OrderSpecifier<?> getOrderBy(QContestBoard contestBoard);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import javax.persistence.Embeddable;
import javax.persistence.Transient;

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

@Embeddable
public class Topic {
@Column(name = "topic", length = 500, nullable = false)
@Column(name = "TOPIC", length = 100, nullable = false)
private String value;

@Transient private final int MAX_LENGTH = 500;
@Transient private final int MAX_LENGTH = 100;

public Topic() {}

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

private boolean validate(Object value) {
Expand Down
Loading

0 comments on commit 9412373

Please sign in to comment.