Skip to content

Commit

Permalink
refactor: add reason to day-off (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenk authored Aug 18, 2024
1 parent abb392e commit ec87c78
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import app.teamwize.api.dayoff.exception.DayOffNotFoundException;
import app.teamwize.api.dayoff.exception.DayOffUpdateStatusFailedException;
import app.teamwize.api.dayoff.service.DayOffService;
import app.teamwize.api.user.exception.UserNotFoundException;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
Expand All @@ -29,7 +30,7 @@ public class DayOffController {


@PostMapping
public DayOffResponse create(@RequestBody DayOffCreateRequest request) {
public DayOffResponse create(@RequestBody DayOffCreateRequest request) throws UserNotFoundException {
var dayOff = dayOffService.createDayOff(securityService.getUserOrganizationId(), securityService.getUserId(), request);
return dayOffMapper.toDayOffResponse(dayOff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class DayOff extends BaseAuditEntity {
@ManyToOne(fetch = FetchType.LAZY)
private User user;

private String reason;

@ManyToOne(fetch = FetchType.LAZY)
private Organization organization;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public record DayOffCreateRequest(
DayOffType type,
String reason,
LocalDateTime start,
LocalDateTime end
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public record DayOffResponse(
LocalDateTime endAt,
DayOffStatus status,
DayOffType type,
String reason,
UserCompactResponse user) {
}
10 changes: 7 additions & 3 deletions src/main/java/app/teamwize/api/dayoff/service/DayOffService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import app.teamwize.api.dayoff.exception.DayOffUpdateStatusFailedException;
import app.teamwize.api.dayoff.repository.DayOffRepository;
import app.teamwize.api.organization.domain.entity.Organization;
import app.teamwize.api.user.domain.entity.User;
import app.teamwize.api.user.exception.UserNotFoundException;
import app.teamwize.api.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -25,13 +26,16 @@
public class DayOffService {

private final DayOffRepository dayOffRepository;
private final UserService userService;

@Transactional
public DayOff createDayOff(Long organizationId, Long userId, DayOffCreateRequest request) {
public DayOff createDayOff(Long organizationId, Long userId, DayOffCreateRequest request) throws UserNotFoundException {
var user = userService.getUser(organizationId,userId);
var dayOff = new DayOff()
.setReason(request.reason())
.setStartAt(request.start())
.setEndAt(request.end())
.setUser(new User(userId))
.setUser(user)
.setOrganization(new Organization(organizationId))
.setStatus(DayOffStatus.PENDING)
.setType(request.type());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public record UserCompactResponse(
String lastName,
@Nullable
String phone,
@Nullable
String countryCode,
@Nullable
String timezone,
@Nonnull
TeamCompactResponse team) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

<changeSet id="20240818-0933-add-reason-to-days-off-table" author="M.Karimi">
<addColumn tableName="days_off">
<column name="reason" type="VARCHAR" />
</addColumn>
</changeSet>

</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ databaseChangeLog:
relativeToChangelogFile: true
- include:
file: 20240815-2230-add-timezone-country-code-to-user-table.xml
relativeToChangelogFile: true
- include:
file: 20240818-0933-add-reason-to-days-off-table.xml
relativeToChangelogFile: true

0 comments on commit ec87c78

Please sign in to comment.