-
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.
Browse files
Browse the repository at this point in the history
* feat: complete the workspace when it exceeds goal score * feat: add api of opening task box in workspace + drawing task in service * feat: change api of seeing password of workspace to seeing introduction of workspace * feat: add api of editing description of workspace
- Loading branch information
Showing
18 changed files
with
457 additions
and
115 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
src/main/java/gymmi/exception/ServerLogicFaultException.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 gymmi.exception; | ||
|
||
public class ServerLogicFaultException extends GymmiException { | ||
|
||
public static final String ERROR_CODE = "SERVER_LOGIC_FAULT"; | ||
public static final String ERROR_DESCRIPTION = "서버 내 로직에서 결함이 생긴 경우"; | ||
|
||
public ServerLogicFaultException(String message) { | ||
super(message, ERROR_CODE, ERROR_DESCRIPTION); | ||
} | ||
} |
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,17 +1,21 @@ | ||
package gymmi.repository; | ||
|
||
import gymmi.entity.Task; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface TaskRepository extends JpaRepository<Task, Long> { | ||
|
||
@Query("select t from Task t where t.user.id = :userId and t.workspace.id = :workspaceId") | ||
@Query("select t from Task t where t.register.id = :userId and t.workspace.id = :workspaceId") | ||
Optional<Task> findByUserIdAndWorkspaceId(Long userId, Long workspaceId); | ||
|
||
@Query("select t from Task t where t.workspace.id = :workspaceId") | ||
List<Task> getAllByWorkspaceId(Long workspaceId); | ||
|
||
@Modifying(clearAutomatically = true) | ||
@Query("delete from Task t where t.user.id = :userId and t.workspace.id = :workspaceId") | ||
@Query("delete from Task t where t.register.id = :userId and t.workspace.id = :workspaceId") | ||
void deleteByUserIdAndWorkspaceId(Long userId, Long workspaceId); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/gymmi/request/EditingDescriptionOfWorkspaceRequest.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,15 @@ | ||
package gymmi.request; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class EditingDescriptionOfWorkspaceRequest { | ||
|
||
private String description; | ||
|
||
public EditingDescriptionOfWorkspaceRequest(String description) { | ||
this.description = description; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gymmi.response; | ||
|
||
import gymmi.entity.Task; | ||
import gymmi.exception.ServerLogicFaultException; | ||
import java.util.List; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class OpeningTasksBoxResponse { | ||
|
||
private final TaskDTO pickedTask; | ||
private final List<TaskDTO> tasks; | ||
|
||
public OpeningTasksBoxResponse(List<Task> tasks) { | ||
this.pickedTask = getPickedTask(tasks); | ||
this.tasks = getTask(tasks); | ||
} | ||
|
||
private List<TaskDTO> getTask(List<Task> tasks) { | ||
return tasks.stream() | ||
.map(t -> new TaskDTO(t.getId(), t.getName(), t.getRegister().getNickname())) | ||
.toList(); | ||
} | ||
|
||
private TaskDTO getPickedTask(List<Task> tasks) { | ||
return tasks.stream() | ||
.filter(t -> t.isPicked()) | ||
.findFirst() | ||
.map(t -> new TaskDTO(t.getId(), t.getName(), t.getRegister().getNickname())) | ||
.orElseThrow(() -> new ServerLogicFaultException("picked task is not exist: " + this.getClass())); | ||
} | ||
|
||
} |
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,17 @@ | ||
package gymmi.response; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class TaskDTO { | ||
|
||
private final Long id; | ||
private final String task; | ||
private final String nickname; | ||
|
||
public TaskDTO(Long id, String task, String nickname) { | ||
this.id = id; | ||
this.task = task; | ||
this.nickname = nickname; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/gymmi/response/WorkspaceIntroductionResponse.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,18 @@ | ||
package gymmi.response; | ||
|
||
import gymmi.entity.Workspace; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class WorkspaceIntroductionResponse { | ||
|
||
private final String password; | ||
private final String description; | ||
private final String tag; | ||
|
||
public WorkspaceIntroductionResponse(Workspace workspace) { | ||
this.password = workspace.getPassword(); | ||
this.description = workspace.getDescription(); | ||
this.tag = workspace.getTag(); | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/gymmi/response/WorkspacePasswordResponse.java
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
package gymmi.service; | ||
|
||
import gymmi.entity.Task; | ||
import gymmi.entity.User; | ||
import gymmi.entity.Worker; | ||
import gymmi.exception.ServerLogicFaultException; | ||
import java.security.SecureRandom; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TaskDraw { | ||
|
||
// 기여퍼센트 + 2 * 등수(reversed) | ||
private final List<Task> tasks; | ||
|
||
public TaskDraw(List<Task> tasks) { | ||
this.tasks = new ArrayList<>(tasks); | ||
} | ||
|
||
private Task findBy(User user) { | ||
return tasks.stream() | ||
.filter(t -> t.isRegisteredBy(user)) | ||
.findFirst() | ||
.orElseThrow(() -> new ServerLogicFaultException("task is not exist: " + this.getClass())); | ||
} | ||
|
||
private Task findBy(Long id) { | ||
return tasks.stream() | ||
.filter(t -> t.getId().equals(id)) | ||
.findFirst() | ||
.orElseThrow(() -> new ServerLogicFaultException("task is not exist: " + this.getClass())); | ||
} | ||
|
||
public Task pickOneAmong(List<Worker> workers, List<Integer> ranks) { | ||
List<Long> box = new ArrayList<>(); | ||
for (int i = 0; i < workers.size(); i++) { | ||
int score = (int) Math.round(workers.get(i).getContributedPercent()) + 2 * (ranks.size() - ranks.get(i)); | ||
for (int j = 0; j < score; j++) { | ||
box.add(findBy(workers.get(i).getUser()).getId()); | ||
} | ||
} | ||
SecureRandom random = new SecureRandom(); | ||
Long taskId = box.get(random.nextInt(0, box.size())); | ||
return findBy(taskId); | ||
} | ||
} |
Oops, something went wrong.