-
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.
* refactor: add field to response * feat: add api to seeing workout confirmation list * feat: add api to seeing workout confirmation detail * feat: add api to tackling to workout confirmation * feat: add api of voting to tackle * fix: add exception handler * fix: add @validated * refactor: rename diction * feat: add ddl.sql * feat: add api of seeing objection * fix: calculate vote result when objection is closed * refactor: add field to response dto
- Loading branch information
Showing
33 changed files
with
1,143 additions
and
260 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
57 changes: 57 additions & 0 deletions
57
src/main/java/gymmi/workspace/domain/ObjectionManager.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,57 @@ | ||
package gymmi.workspace.domain; | ||
|
||
import gymmi.exceptionhandler.exception.AlreadyExistException; | ||
import gymmi.exceptionhandler.exception.InvalidStateException; | ||
import gymmi.exceptionhandler.message.ErrorCode; | ||
import gymmi.workspace.domain.entity.Objection; | ||
import gymmi.workspace.domain.entity.Vote; | ||
import gymmi.workspace.domain.entity.Worker; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ObjectionManager { | ||
private final Objection objection; | ||
private boolean isApproved; | ||
|
||
public ObjectionManager(Objection objection) { | ||
this.objection = objection; | ||
this.isApproved = false; | ||
} | ||
|
||
public Vote createVote(Worker worker, boolean isApproved) { | ||
if (!objection.isInProgress()) { | ||
throw new InvalidStateException(ErrorCode.ALREADY_CLOSED_OBJECTION); | ||
} | ||
if (objection.hasVoteBy(worker)) { | ||
throw new AlreadyExistException(ErrorCode.ALREADY_VOTED); | ||
} | ||
return new Vote(worker, objection, isApproved); | ||
} | ||
|
||
public boolean closeIfOnMajorityOrDone(int workerCount) { | ||
int majority = getMajority(workerCount); | ||
if (objection.getApprovalCount() >= majority) { | ||
objection.close(); | ||
isApproved = true; | ||
return true; | ||
} | ||
if (objection.getRejectionCount() >= majority) { | ||
objection.close(); | ||
return true; | ||
} | ||
if (objection.getVoteCount() >= workerCount) { | ||
objection.close(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
private int getMajority(int workerCount) { | ||
if (workerCount % 2 == 0) { | ||
return (workerCount / 2) + 1; | ||
} | ||
return (int) Math.round(workerCount / 2.0); | ||
} | ||
|
||
} |
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
Oops, something went wrong.