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

feat: integrate puting profession-profile apis and change tech_stack … #160

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ CREATE TABLE "member".notification (

CREATE TABLE member.professional_profile (
user_id int8 not null PRIMARY KEY,
introduce TEXT not null ,
tech_stack TEXT not null ,
answer1 TEXT not null ,
answer2 TEXT not null ,
answer3 TEXT not null ,
description TEXT,
introduce varchar(502),
tech_stack jsonb,
answer1 varchar(502),
answer2 varchar(502),
answer3 varchar(502),
description varchar(502),
resume TEXT,
is_visible boolean not null default true
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package Funssion.Inforum.domain.professionalprofile.controller;

import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.professionalprofile.dto.request.CreateProfessionalProfileDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdatePersonalStatementDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdateResumeDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.SaveProfessionalProfileDto;
import Funssion.Inforum.domain.professionalprofile.dto.response.ProfessionalProfileResponseDto;
import Funssion.Inforum.domain.professionalprofile.service.ProfessionalProfileService;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,26 +19,18 @@ public class ProfessionalProfileController {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createProfessionalProfile(
@RequestBody @Validated CreateProfessionalProfileDto createProfessionalProfileDto
@RequestBody @Validated SaveProfessionalProfileDto saveProfessionalProfileDto
) {
Long userId = SecurityContextUtils.getAuthorizedUserId();
professionalProfileService.createProfessionalProfile(userId, createProfessionalProfileDto);
professionalProfileService.createProfessionalProfile(userId, saveProfessionalProfileDto);
}

@PutMapping("/personal-statement")
public void updatePersonalStatement(
@RequestBody @Validated UpdatePersonalStatementDto updatePersonalStatementDto
) {
Long userId = SecurityContextUtils.getAuthorizedUserId();
professionalProfileService.updatePersonalStatement(userId, updatePersonalStatementDto);
}

@PutMapping("/resume")
public void updateResume(
@RequestBody UpdateResumeDto updateResumeDto
) {
@PutMapping
public void updateProfessionalProfile(
@RequestBody @Validated SaveProfessionalProfileDto updatePersonalStatementDto
) {
Long userId = SecurityContextUtils.getAuthorizedUserId();
professionalProfileService.updateResume(userId, updateResumeDto);
professionalProfileService.update(userId, updatePersonalStatementDto);
}

@PostMapping("/visibility")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Funssion.Inforum.domain.professionalprofile.dto.request;

import jakarta.validation.constraints.Size;
import lombok.*;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SaveProfessionalProfileDto {
@Size(max = 500, message = "한 줄 자기소개는 500자를 초과할 수 없습니다")
private String introduce;
@Size(max = 1000)
private String techStack;
@Size(max = 500)
private String description;
@Size(max = 500, message = "질문 1에 대한 답변은 500자를 초과할 수 없습니다")
private String answer1;
@Size(max = 500, message = "질문 2에 대한 답변은 500자를 초과할 수 없습니다")
private String answer2;
@Size(max = 500, message = "질문 3에 대한 답변은 500자를 초과할 수 없습니다")
private String answer3;
@Size(max = 50000)
private String resume;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package Funssion.Inforum.domain.professionalprofile.repository;

import Funssion.Inforum.domain.professionalprofile.domain.ProfessionalProfile;
import Funssion.Inforum.domain.professionalprofile.dto.request.CreateProfessionalProfileDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdatePersonalStatementDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdateResumeDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.SaveProfessionalProfileDto;

public interface ProfessionalProfileRepository {

void create(Long userId, CreateProfessionalProfileDto professionalProfile);
void create(Long userId, SaveProfessionalProfileDto professionalProfile);
ProfessionalProfile findByUserId(Long userId);
void updatePersonalStatement(Long userId, UpdatePersonalStatementDto personalStatement);
void updateResume(Long userId, UpdateResumeDto resume);
void update(Long userId, SaveProfessionalProfileDto professionalProfile);
void updateVisibility(Long userId, Boolean isVisible);
void delete(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
import Funssion.Inforum.common.exception.etc.DeleteFailException;
import Funssion.Inforum.common.exception.etc.UpdateFailException;
import Funssion.Inforum.domain.professionalprofile.domain.ProfessionalProfile;
import Funssion.Inforum.domain.professionalprofile.dto.request.CreateProfessionalProfileDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdatePersonalStatementDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdateResumeDto;
import Funssion.Inforum.domain.tag.TagUtils;
import Funssion.Inforum.domain.professionalprofile.dto.request.SaveProfessionalProfileDto;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.util.ArrayList;

@Repository
Expand All @@ -27,11 +21,14 @@ public ProfessionalProfileRepositoryImpl(DataSource dataSource) {
}

@Override
public void create(Long userId, CreateProfessionalProfileDto professionalProfile) {
public void create(Long userId, SaveProfessionalProfileDto professionalProfile) {
String sql = "INSERT INTO member.professional_profile (user_id, introduce, tech_stack, description, answer1, answer2, answer3, resume) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
"VALUES (?, ?, ?::jsonb, ?, ?, ?, ?, ?);";

template.update(sql, getAllParams(userId, professionalProfile));
ArrayList<Object> paramList = new ArrayList<>();
paramList.add(userId);

template.update(sql, getAllParams(professionalProfile, paramList).toArray());
}

@Override
Expand All @@ -44,23 +41,15 @@ public ProfessionalProfile findByUserId(Long userId) {
}

@Override
public void updatePersonalStatement(Long userId, UpdatePersonalStatementDto personalStatementDto) {
public void update(Long userId, SaveProfessionalProfileDto professionalProfile) {
String sql = "UPDATE member.professional_profile " +
"SET introduce = ?, tech_stack = ?, description = ?, answer1 = ?, answer2 = ?, answer3 = ? " +
"SET introduce = ?, tech_stack = ?::jsonb, description = ?, answer1 = ?, answer2 = ?, answer3 = ?, resume = ? " +
"WHERE user_id = ?";

int updatedRows = template.update(sql,getAllParams(personalStatementDto, userId));
if (updatedRows != 1)
throw new UpdateFailException("professional_profile updated rows not 1 actually " + updatedRows);
}

@Override
public void updateResume(Long userId, UpdateResumeDto resumeDto) {
String sql = "UPDATE member.professional_profile " +
"SET resume = ? " +
"WHERE user_id = ?";
ArrayList<Object> paramList = getAllParams(professionalProfile, new ArrayList<>());
paramList.add(userId);

int updatedRows = template.update(sql, resumeDto.getResume(), userId);
int updatedRows = template.update(sql,paramList.toArray());
if (updatedRows != 1)
throw new UpdateFailException("professional_profile updated rows not 1 actually " + updatedRows);
}
Expand All @@ -87,29 +76,15 @@ public void delete(Long userId) {
throw new DeleteFailException("professional_profile deleted rows not 1 actually " + deletedRows);
}

private Object[] getAllParams(UpdatePersonalStatementDto personalStatementDto ,Long userId) {
ArrayList<Object> paramList = new ArrayList<>();
paramList.add(personalStatementDto.getIntroduce());
paramList.add(personalStatementDto.getTechStack());
paramList.add(personalStatementDto.getDescription());
paramList.add(personalStatementDto.getAnswer1());
paramList.add(personalStatementDto.getAnswer2());
paramList.add(personalStatementDto.getAnswer3());
paramList.add(userId);
return paramList.toArray();
}

private Object[] getAllParams(Long userId, CreateProfessionalProfileDto profile) {
ArrayList<Object> paramList = new ArrayList<>();
paramList.add(userId);
private ArrayList<Object> getAllParams(SaveProfessionalProfileDto profile, ArrayList<Object> paramList) {
paramList.add(profile.getIntroduce());
paramList.add(profile.getTechStack());
paramList.add(profile.getDescription());
paramList.add(profile.getAnswer1());
paramList.add(profile.getAnswer2());
paramList.add(profile.getAnswer3());
paramList.add(profile.getResume());
return paramList.toArray();
return paramList;
}

private RowMapper<ProfessionalProfile> professionalPrifileRowMapper() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,58 @@
package Funssion.Inforum.domain.professionalprofile.service;

import Funssion.Inforum.common.constant.Role;
import Funssion.Inforum.common.exception.forbidden.ForbiddenException;
import Funssion.Inforum.common.exception.notfound.NotFoundException;
import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.professionalprofile.domain.ProfessionalProfile;
import Funssion.Inforum.domain.professionalprofile.dto.request.CreateProfessionalProfileDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdatePersonalStatementDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.UpdateResumeDto;
import Funssion.Inforum.domain.professionalprofile.dto.request.SaveProfessionalProfileDto;
import Funssion.Inforum.domain.professionalprofile.dto.response.ProfessionalProfileResponseDto;
import Funssion.Inforum.domain.professionalprofile.repository.ProfessionalProfileRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@RequiredArgsConstructor
public class ProfessionalProfileService {

private final ProfessionalProfileRepository professionalProfileRepository;

public ProfessionalProfileResponseDto getProfessionalProfile(Long userId) {
Long clientId = SecurityContextUtils.getUserId();
ProfessionalProfile professionalProfile = professionalProfileRepository.findByUserId(userId);
String clientRole = SecurityContextUtils.getAuthority();
log.info("clientRole={}",clientRole);

if (!professionalProfile.getIsVisible() && !clientId.equals(userId))
throw new ForbiddenException("비공개 설정된 프로필은 열람할 수 없습니다.");
validateAccess(userId, clientId, clientRole);

return ProfessionalProfileResponseDto.valueOf(
professionalProfileRepository.findByUserId(userId)
);
}

public void createProfessionalProfile(Long userId, CreateProfessionalProfileDto createProfessionalProfileDto) {
professionalProfileRepository.create(userId, createProfessionalProfileDto);
private void validateAccess(Long userId, Long clientId, String clientRole) {
ProfessionalProfile professionalProfile;
try{
professionalProfile = professionalProfileRepository.findByUserId(userId);
} catch (EmptyResultDataAccessException e) {
throw new NotFoundException("해당 유저의 정보를 찾을 수 없습니다.");
}

if (!professionalProfile.getIsVisible() && !clientId.equals(userId))
throw new ForbiddenException("비공개 설정된 프로필은 열람할 수 없습니다.");

if (!clientId.equals(userId) && !clientRole.equals(Role.EMPLOYER.getRoles()))
throw new ForbiddenException("일반 유저는 접근할 수 없습니다");
}

public void updatePersonalStatement(Long userId, UpdatePersonalStatementDto updatePersonalStatementDto) {
professionalProfileRepository.updatePersonalStatement(userId, updatePersonalStatementDto);
public void createProfessionalProfile(Long userId, SaveProfessionalProfileDto saveProfessionalProfileDto) {
professionalProfileRepository.create(userId, saveProfessionalProfileDto);
}

public void updateResume(Long userId, UpdateResumeDto updateResumeDto) {
professionalProfileRepository.updateResume(userId, updateResumeDto);
public void update(Long userId, SaveProfessionalProfileDto saveProfessionalProfileDto) {
professionalProfileRepository.update(userId, saveProfessionalProfileDto);
}

public void updateVisibility(Long userId, Boolean isVisible) {
Expand Down
Loading