Skip to content

Commit

Permalink
Feat: 아코폴리오 CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
saokiritoni committed Nov 26, 2024
1 parent e17f03c commit 1d7414d
Show file tree
Hide file tree
Showing 23 changed files with 498 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/main/java/dongguk/osori/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@Configuration
@EnableRedisRepositories
Expand All @@ -35,12 +34,13 @@ public RedisConnectionFactory redisConnectionFactory() {
}

@Bean
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory());

return redisTemplate;
}

}
2 changes: 1 addition & 1 deletion src/main/java/dongguk/osori/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public PasswordEncoder passwordEncoder() {
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("http://localhost:3000")); // 정확한 오리진 설정
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // 허용할 HTTP 메서드
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")); // 허용할 HTTP 메서드
configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type")); // 허용할 HTTP 헤더
configuration.setAllowCredentials(true); // 자격 증명 허용

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import dongguk.osori.domain.follow.FollowRepository;
import dongguk.osori.domain.follow.dto.FollowDto;
import dongguk.osori.domain.follow.entity.Follow;
import dongguk.osori.domain.user.UserRepository;
import dongguk.osori.domain.user.repository.UserRepository;
import dongguk.osori.domain.user.entity.User;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import dongguk.osori.domain.goal.repository.GoalCommentRepository;
import dongguk.osori.domain.goal.repository.GoalRepository;
import dongguk.osori.domain.user.entity.User;
import dongguk.osori.domain.user.UserRepository;
import dongguk.osori.domain.user.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dongguk.osori.domain.goal.service;

import dongguk.osori.domain.goal.dto.*;
import dongguk.osori.domain.goal.entity.GoalComment;
import dongguk.osori.domain.goal.repository.GoalCommentRepository;
import dongguk.osori.domain.goal.repository.GoalRepository;
import dongguk.osori.domain.goal.entity.Goal;
import dongguk.osori.domain.user.entity.User;
import dongguk.osori.domain.user.UserRepository;
import dongguk.osori.domain.user.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dongguk.osori.domain.portfolio.controller;

import dongguk.osori.domain.portfolio.dto.PortfolioBaseDto;
import dongguk.osori.domain.portfolio.dto.PortfolioDetailDto;
import dongguk.osori.domain.portfolio.dto.PortfolioRequestDto;
import dongguk.osori.domain.portfolio.service.PortfolioService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/portfolios")
@RequiredArgsConstructor
public class PortfolioController {

private final PortfolioService portfolioService;
private final HttpSession httpSession;

@PostMapping
public ResponseEntity<PortfolioDetailDto> createPortfolio(@RequestBody PortfolioRequestDto requestDto) {
Long userId = (Long) httpSession.getAttribute("userId");
return ResponseEntity.ok(portfolioService.createPortfolio(userId, requestDto));
}

@GetMapping
public ResponseEntity<List<PortfolioBaseDto>> getPortfolioList() {
Long userId = (Long) httpSession.getAttribute("userId");
return ResponseEntity.ok(portfolioService.getPortfolioList(userId));
}

@GetMapping("/{portfolioId}")
public ResponseEntity<PortfolioDetailDto> getPortfolioDetail(@PathVariable("portfolioId") Long portfolioId) {
Long userId = (Long) httpSession.getAttribute("userId");
return ResponseEntity.ok(portfolioService.getPortfolioDetail(userId, portfolioId));
}


@PutMapping("/{portfolioId}")
public ResponseEntity<PortfolioDetailDto> updatePortfolio(
@PathVariable("portfolioId") Long portfolioId,
@RequestBody PortfolioRequestDto requestDto
) {
Long userId = (Long) httpSession.getAttribute("userId");
return ResponseEntity.ok(portfolioService.updatePortfolio(userId, portfolioId, requestDto));
}


@DeleteMapping("/{portfolioId}")
public ResponseEntity<Void> deletePortfolio(@PathVariable("portfolioId") Long portfolioId) {
Long userId = (Long) httpSession.getAttribute("userId");
portfolioService.deletePortfolio(userId, portfolioId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dongguk.osori.domain.portfolio.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ExperienceDto {
private String situation;
private String task;
private String action;
private String result;
}
14 changes: 14 additions & 0 deletions src/main/java/dongguk/osori/domain/portfolio/dto/PmiDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dongguk.osori.domain.portfolio.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PmiDto {
private String plus;
private String minus;
private String interesting;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dongguk.osori.domain.portfolio.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
/*
목록 조회 dto
*/
public class PortfolioBaseDto {
private Long portfolioId;
private String name;
private LocalDate startDate;
private List<String> tags;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dongguk.osori.domain.portfolio.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PortfolioDetailDto {
private PortfolioBaseDto baseInfo;
private ExperienceDto experience;
private PmiDto pmi;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dongguk.osori.domain.portfolio.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PortfolioRequestDto {
private String name;
private LocalDate startDate;
private List<String> tags;
private ExperienceDto experience;
private PmiDto pmi;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dongguk.osori.domain.portfolio.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@Entity
public class Experience {

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

private String situation;
private String task;
private String action;
private String result;



public Experience(String situation, String task, String action, String result) {
this.situation = situation;
this.task = task;
this.action = action;
this.result = result;
}

public void setPortfolio(Portfolio portfolio) {
this.portfolio = portfolio;
}

public void update(String situation, String task, String action, String result) {
this.situation = situation;
this.task = task;
this.action = action;
this.result = result;
}

@OneToOne
@JoinColumn(name = "portfolio_id", nullable = false)
private Portfolio portfolio;
}
39 changes: 39 additions & 0 deletions src/main/java/dongguk/osori/domain/portfolio/entity/Pmi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dongguk.osori.domain.portfolio.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@Entity
public class Pmi {

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

private String plus;
private String minus;
private String interesting;

public Pmi(String plus, String minus, String interesting) {
this.plus = plus;
this.minus = minus;
this.interesting = interesting;
}

public void setPortfolio(Portfolio portfolio) {
this.portfolio = portfolio;
}

public void update(String plus, String minus, String interesting) {
this.plus = plus;
this.minus = minus;
this.interesting = interesting;
}

@OneToOne
@JoinColumn(name = "portfolio_id", nullable = false)
private Portfolio portfolio;
}
67 changes: 67 additions & 0 deletions src/main/java/dongguk/osori/domain/portfolio/entity/Portfolio.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package dongguk.osori.domain.portfolio.entity;

import dongguk.osori.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;

@Getter
@NoArgsConstructor
@Entity
public class Portfolio {

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

private String name;
private LocalDate startDate;

@ElementCollection
@CollectionTable(name = "portfolio_tags", joinColumns = @JoinColumn(name = "portfolio_id"))
@Column(name = "tag")
private Set<String> tags = new HashSet<>();

public Portfolio(String name, LocalDate startDate, Set<String> tags, Experience experience, Pmi pmi, User user) {
this.name = name;
this.startDate = startDate;
this.tags = tags;
this.user = user;
setExperience(experience);
setPmi(pmi);
}

public void update(String name, LocalDate startDate, Set<String> tags) {
this.name = name;
this.startDate = startDate;
this.tags = tags;
}

public void setExperience(Experience experience) {
this.experience = experience;
if (experience != null) {
experience.setPortfolio(this);
}
}

public void setPmi(Pmi pmi) {
this.pmi = pmi;
if (pmi != null) {
pmi.setPortfolio(this);
}
}

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "portfolio")
private Experience experience;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "portfolio")
private Pmi pmi;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
}
8 changes: 8 additions & 0 deletions src/main/java/dongguk/osori/domain/portfolio/entity/Tag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dongguk.osori.domain.portfolio.entity;

public enum Tag {
전공, 교양, 교내동아리, 교외동아리, 학회, 봉사활동, 인턴, 아르바이트,
대외활동, 서포터즈, 기자단, 강연행사, 스터디, 부트캠프, 프로젝트, 연구,
학생회, 기타

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dongguk.osori.domain.portfolio.repository;

import dongguk.osori.domain.portfolio.entity.Experience;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ExperienceRepository extends JpaRepository<Experience, Long> {
}
Loading

0 comments on commit 1d7414d

Please sign in to comment.