-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from BaeJunH0/dev
[2025.01.01] dev 진행 내역 main에 머지
- Loading branch information
Showing
23 changed files
with
509 additions
and
24 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...in/java/com/sparksInTheStep/webBoard/global/errorHandling/errorCode/ProjectErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.sparksInTheStep.webBoard.global.errorHandling.errorCode; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum ProjectErrorCode implements ErrorCode{ | ||
NOT_FOUND(HttpStatus.NOT_FOUND, "Pr000", "No such project"), | ||
NOT_TEAM_LEADER(HttpStatus.FORBIDDEN, "Pr001", "Project can be deleted by only team leader"), | ||
ALREADY_EXIST_NAME(HttpStatus.FORBIDDEN, "Pr002", "Project's name is already using"), | ||
ALREADY_JOINED_PROJECT(HttpStatus.FORBIDDEN, "Pr003", "Login user already in this project"); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorCode; | ||
private final String message; | ||
|
||
@Override | ||
public HttpStatus httpStatus() { | ||
return this.httpStatus; | ||
} | ||
|
||
@Override | ||
public String code() { | ||
return this.errorCode; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return this.message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
src/main/java/com/sparksInTheStep/webBoard/member/presentation/MemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
package com.sparksInTheStep.webBoard.member.presentation; | ||
|
||
import com.sparksInTheStep.webBoard.global.annotation.AuthorizedUser; | ||
import com.sparksInTheStep.webBoard.member.application.MemberService; | ||
import com.sparksInTheStep.webBoard.member.application.dto.MemberInfo; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.util.List; | ||
|
||
@RequestMapping("/members") | ||
@RequiredArgsConstructor | ||
public class MemberController implements MemberApiSpec { | ||
private final MemberService memberService; | ||
|
||
@GetMapping("/my/nickname") | ||
public ResponseEntity<?> getNickname( | ||
@AuthorizedUser MemberInfo.Default memberInfo | ||
) { | ||
return new ResponseEntity<>(memberInfo.nickname(), HttpStatus.OK); | ||
} | ||
|
||
@PatchMapping("/my/employed") | ||
public ResponseEntity<?> updateEmployed( | ||
@AuthorizedUser MemberInfo.Default memberInfo | ||
) { | ||
memberService.updateEmployed(memberInfo.nickname()); | ||
|
||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
} |
6 changes: 2 additions & 4 deletions
6
src/main/java/com/sparksInTheStep/webBoard/member/presentation/dto/MemberRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package com.sparksInTheStep.webBoard.member.presentation.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record MemberRequest( | ||
String nickname, | ||
|
||
String password | ||
String password, | ||
Boolean employed | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/java/com/sparksInTheStep/webBoard/post/domain/PostType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.sparksInTheStep.webBoard.post.domain; | ||
|
||
public enum PostType{ | ||
INFORMATION, | ||
FREE, | ||
QUESTION | ||
TIP, | ||
PROJECT, | ||
RESUME; | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/com/sparksInTheStep/webBoard/project/application/ProjectService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.sparksInTheStep.webBoard.project.application; | ||
|
||
import com.sparksInTheStep.webBoard.global.errorHandling.CustomException; | ||
import com.sparksInTheStep.webBoard.global.errorHandling.errorCode.ProjectErrorCode; | ||
import com.sparksInTheStep.webBoard.project.doamin.JoinedProject; | ||
import com.sparksInTheStep.webBoard.project.persistent.JoinedProjectRepository; | ||
import com.sparksInTheStep.webBoard.member.domain.Member; | ||
import com.sparksInTheStep.webBoard.member.persistent.MemberRepository; | ||
import com.sparksInTheStep.webBoard.project.application.dto.ProjectCommand; | ||
import com.sparksInTheStep.webBoard.project.application.dto.ProjectInfo; | ||
import com.sparksInTheStep.webBoard.project.doamin.Project; | ||
import com.sparksInTheStep.webBoard.project.persistent.ProjectRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ProjectService { | ||
private final ProjectRepository projectRepository; | ||
private final MemberRepository memberRepository; | ||
private final JoinedProjectRepository joinedProjectRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public Page<ProjectInfo> getAllProjects(Pageable pageable){ | ||
return projectRepository.findAll(pageable).map(ProjectInfo::of); | ||
} | ||
@Transactional(readOnly = true) | ||
public ProjectInfo getProject(Long id){ | ||
Project project = projectRepository.findById(id).orElseThrow( | ||
() -> CustomException.of(ProjectErrorCode.NOT_FOUND) | ||
); | ||
return ProjectInfo.of(project); | ||
} | ||
@Transactional(readOnly = true) | ||
public Page<ProjectInfo> getMyProjects(Pageable pageable, String nickname) { | ||
Member member = memberRepository.findByNickname(nickname); | ||
Page<JoinedProject> joinedProjects = joinedProjectRepository.findJoinedProjectsByMember(pageable, member); | ||
return joinedProjects.map(JoinedProject::getProject).map(ProjectInfo::of); | ||
} | ||
@Transactional | ||
public void makeProject(ProjectCommand projectCommand){ | ||
if(projectRepository.existsByName(projectCommand.name())) { | ||
throw CustomException.of(ProjectErrorCode.ALREADY_EXIST_NAME); | ||
} | ||
Project project = Project.of(projectCommand); | ||
projectRepository.save(project); | ||
} | ||
@Transactional | ||
public void joinProject(Long id, String nickname) { | ||
Project project = projectRepository.findById(id).orElseThrow( | ||
() -> CustomException.of(ProjectErrorCode.NOT_FOUND) | ||
); | ||
Member member = memberRepository.findByNickname(nickname); | ||
|
||
if(joinedProjectRepository.existsByMemberAndProject(member, project)){ | ||
throw CustomException.of(ProjectErrorCode.ALREADY_JOINED_PROJECT); | ||
} | ||
JoinedProject joinedProject = JoinedProject.from(member, project); | ||
joinedProjectRepository.save(joinedProject); | ||
} | ||
@Transactional | ||
public void updateProject(Long id, ProjectCommand projectCommand){ | ||
Project project = projectRepository.findById(id).orElseThrow( | ||
() -> CustomException.of(ProjectErrorCode.NOT_FOUND) | ||
); | ||
if(projectRepository.existsByName(projectCommand.name())) { | ||
throw CustomException.of(ProjectErrorCode.ALREADY_EXIST_NAME); | ||
} | ||
if(!project.getName().equals(projectCommand.nickname())) { | ||
throw CustomException.of(ProjectErrorCode.NOT_TEAM_LEADER); | ||
} | ||
|
||
project.update(projectCommand.name(), projectCommand.info(), projectCommand.gitLink()); | ||
} | ||
|
||
@Transactional | ||
public void deleteProject(Long id, String nickname){ | ||
Project project = projectRepository.findById(id).orElseThrow( | ||
() -> CustomException.of(ProjectErrorCode.NOT_FOUND) | ||
); | ||
if(!project.getName().equals(nickname)) { | ||
throw CustomException.of(ProjectErrorCode.NOT_TEAM_LEADER); | ||
} | ||
|
||
projectRepository.delete(project); | ||
} | ||
|
||
@Transactional | ||
public void withdrawProject(Long id, String nickname) { | ||
Project project = projectRepository.findById(id).orElseThrow( | ||
() -> CustomException.of(ProjectErrorCode.NOT_FOUND) | ||
); | ||
Member member = memberRepository.findByNickname(nickname); | ||
|
||
if(!joinedProjectRepository.existsByMemberAndProject(member, project)){ | ||
throw CustomException.of(ProjectErrorCode.NOT_FOUND); | ||
} | ||
|
||
joinedProjectRepository.deleteByMemberAndProject(member, project); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/sparksInTheStep/webBoard/project/application/dto/ProjectCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.sparksInTheStep.webBoard.project.application.dto; | ||
|
||
import com.sparksInTheStep.webBoard.project.presentation.dto.ProjectRequest; | ||
|
||
public record ProjectCommand(String name, String info, String gitLink, String nickname) { | ||
public static ProjectCommand from(ProjectRequest projectRequest, String nickname) { | ||
return new ProjectCommand( | ||
projectRequest.name(), projectRequest.info(), projectRequest.gitLink(), nickname | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/sparksInTheStep/webBoard/project/application/dto/ProjectInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.sparksInTheStep.webBoard.project.application.dto; | ||
|
||
import com.sparksInTheStep.webBoard.project.doamin.Project; | ||
|
||
public record ProjectInfo(String name, String info, String gitLink, String leaderName) { | ||
public static ProjectInfo of(Project project){ | ||
return new ProjectInfo( | ||
project.getName(), project.getInfo(), project.getGitLink(), project.getLeaderName() | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/sparksInTheStep/webBoard/project/doamin/JoinedProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.sparksInTheStep.webBoard.project.doamin; | ||
|
||
import com.sparksInTheStep.webBoard.member.domain.Member; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Getter | ||
public class JoinedProject { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@ManyToOne | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
@ManyToOne | ||
@JoinColumn(name = "project_id") | ||
private Project project; | ||
|
||
private JoinedProject(Member member, Project project) { | ||
this.member = member; | ||
this.project = project; | ||
} | ||
|
||
public static JoinedProject from( | ||
Member member, Project project | ||
){ | ||
return new JoinedProject(member, project); | ||
} | ||
} |
Oops, something went wrong.