-
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.
[RID-425][#150][feat]: create fronoffice table
- Loading branch information
1 parent
38ba84b
commit ac47eb3
Showing
17 changed files
with
208 additions
and
29 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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/backend/curi/common/interceptor/FrontofficeAuthInterceptor.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,42 @@ | ||
package com.backend.curi.common.interceptor; | ||
|
||
import com.backend.curi.exception.CuriException; | ||
import com.backend.curi.exception.ErrorType; | ||
import com.backend.curi.frontoffice.service.FrontofficeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.UUID; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class FrontofficeAuthInterceptor implements HandlerInterceptor { | ||
private final FrontofficeService frontofficeService; | ||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
Long workspaceId = Extractor.extractLongFromUrl(request, "workspaces"); | ||
Long launchedmoduleId = Extractor.extractLongFromUrl(request, "modules"); | ||
UUID frontofficeId = Extractor.extractUUIDFromUrl(request, "frontoffices"); | ||
UUID accessToken = getAccessToken(request); | ||
|
||
frontofficeService.checkAuth(frontofficeId, accessToken); | ||
|
||
return true; | ||
} | ||
|
||
private UUID getAccessToken(HttpServletRequest request){ | ||
String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); | ||
if (authorization == null || !authorization.startsWith("Bearer ")) { | ||
throw new CuriException(HttpStatus.BAD_REQUEST, ErrorType.FRONTOFFICE_UNAUTHORIZED); | ||
} | ||
|
||
String accessToken = authorization.split(" ")[1]; | ||
|
||
return UUID.fromString(accessToken); | ||
} | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/backend/curi/frontoffice/controller/FrontofficeController.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,30 @@ | ||
package com.backend.curi.frontoffice.controller; | ||
|
||
import com.backend.curi.frontoffice.controller.dto.FrontofficeResponse; | ||
import com.backend.curi.frontoffice.service.FrontofficeService; | ||
import com.backend.curi.launched.controller.dto.LaunchedSequenceResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/frontoffices") | ||
@RequiredArgsConstructor | ||
public class FrontofficeController { | ||
|
||
private final FrontofficeService frontofficeService; | ||
|
||
@GetMapping("/{frontofficeId}") | ||
public ResponseEntity<FrontofficeResponse> getLaunchedsequence(@PathVariable UUID frontofficeId){ | ||
FrontofficeResponse frontofficeResponse = frontofficeService.getFrontoffice(frontofficeId); | ||
return ResponseEntity.ok(frontofficeResponse); | ||
} | ||
|
||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/backend/curi/frontoffice/controller/dto/FrontofficeResponse.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,24 @@ | ||
package com.backend.curi.frontoffice.controller.dto; | ||
|
||
import com.backend.curi.frontoffice.repository.entity.Frontoffice; | ||
import com.backend.curi.launched.controller.dto.LaunchedSequenceResponse; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.UUID; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class FrontofficeResponse { | ||
private UUID id; | ||
private LaunchedSequenceResponse launchedSequenceResponse; | ||
|
||
public static FrontofficeResponse of (Frontoffice frontoffice){ | ||
return new FrontofficeResponse(frontoffice.getId(), LaunchedSequenceResponse.of(frontoffice.getLaunchedSequence())); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/backend/curi/frontoffice/repository/FrontofficeRepository.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,9 @@ | ||
package com.backend.curi.frontoffice.repository; | ||
|
||
import com.backend.curi.frontoffice.repository.entity.Frontoffice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface FrontofficeRepository extends JpaRepository<Frontoffice, UUID> { | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/backend/curi/frontoffice/repository/entity/Frontoffice.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,28 @@ | ||
package com.backend.curi.frontoffice.repository.entity; | ||
|
||
import com.backend.curi.launched.repository.entity.LaunchedSequence; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import javax.persistence.*; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class Frontoffice { | ||
@Id | ||
@GeneratedValue(generator = "uuid2") | ||
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator") | ||
private UUID id; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
private LaunchedSequence launchedSequence; | ||
|
||
private UUID accessToken; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/backend/curi/frontoffice/service/FrontofficeService.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,32 @@ | ||
package com.backend.curi.frontoffice.service; | ||
|
||
import com.backend.curi.exception.CuriException; | ||
import com.backend.curi.exception.ErrorType; | ||
import com.backend.curi.frontoffice.controller.dto.FrontofficeResponse; | ||
import com.backend.curi.frontoffice.repository.FrontofficeRepository; | ||
import com.backend.curi.frontoffice.repository.entity.Frontoffice; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
|
||
public class FrontofficeService { | ||
|
||
private final FrontofficeRepository frontofficeRepository; | ||
|
||
public FrontofficeResponse getFrontoffice(UUID frontofficeId) { | ||
Frontoffice frontoffice = frontofficeRepository.findById(frontofficeId).orElseThrow(() -> new CuriException(HttpStatus.NOT_FOUND, ErrorType.FRONTOFFICE_NOT_EXISTS)); | ||
return FrontofficeResponse.of(frontoffice); | ||
|
||
} | ||
|
||
public void checkAuth(UUID frontofficeId, UUID accessToken) { | ||
Frontoffice frontoffice = frontofficeRepository.findById(frontofficeId).orElseThrow(() -> new CuriException(HttpStatus.NOT_FOUND, ErrorType.FRONTOFFICE_NOT_EXISTS)); | ||
if (!frontoffice.getAccessToken().equals(accessToken)) throw new CuriException(HttpStatus.UNAUTHORIZED, ErrorType.FRONTOFFICE_UNAUTHORIZED); | ||
|
||
} | ||
} |
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